Put a TIdIcmpClient component on your form and set its properties like in this screenshot:
Then execute a Ping:
IdIcmpClient1.Ping;
This will get you an error message at runtime:
However, if I run the program As Administrator, no error message is displayed and the IdIcmpClient1Reply
event is triggered.
WHY?
Also, when I create the component at runtime...:
function TForm1.MyPing(const AHost: string): Boolean;
var
MyIdIcmpClient: TIdIcmpClient;
begin
Result := False;
MyIdIcmpClient := TIdIcmpClient.Create(Self);
try
MyIdIcmpClient.ReceiveTimeout := 2000;
MyIdIcmpClient.Host := AHost;
MyIdIcmpClient.PacketSize := 32;
MyIdIcmpClient.Protocol := 1;
MyIdIcmpClient.IPVersion := Id_IPv4;
MyIdIcmpClient.OnReply := IdIcmpClient1Reply;
try
MyIdIcmpClient.Ping;
except
Result := False;
EXIT;
end;
Result := MyIdIcmpClient.ReplyStatus.ReplyStatusType = rsEcho
finally
MyIdIcmpClient.Free;
end;
end;
...
// Usage:
MyPing('microsoft.com');
... the Socket Error #10013 is thrown with the Ping, and again the program triggers the IdIcmpClient1Reply
event only when run As Administrator.
⇨ So how can I execute the Ping without having to run the program as Administrator?
All this is done with Delphi XE7.