Faça sua buscar ...
sábado, 7 de maio de 2016
Verificar se está conectado à Internet
A função abaixo retorna true se estiver conectado e false
caso contrário.
function RemoteConnection: boolean;
const
Key = '\System\CurrentControlSet\Services\RemoteAccess';
Value = 'Remote Connection';
var
Reg: TRegistry;
Buffer: DWord;
begin
Result := false;
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey(Key, false) then
begin
Reg.ReadBinaryData(Value, Buffer, SizeOf(Buffer));
Result := Buffer = 1;
end;
finally
Reg.CloseKey;
Reg.Free;
end;
end;
Exemplo de uso
Para testar a função coloquei um Timer e um Label no
formulário. No evento OnTimer do Timer escrevi o
código abaixo.
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if RemoteConnection() then
Label1.Caption := 'Conectado'
else
Label1.Caption := 'Desconectado';
end;
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário