0

Put a TIdIcmpClient component on your form and set its properties like in this screenshot:

TIdIcmpClient properties

Then execute a Ping:

IdIcmpClient1.Ping;

This will get you an error message at runtime:

enter image description here

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.

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • Not possible until Indy team will publish Windows specific code. – Free Consulting Feb 28 '15 at 14:45
  • Is it possible with something different than Indy? – user1580348 Feb 28 '15 at 14:46
  • Is it possible to use the Windows ping.exe without showing the console window? – user1580348 Feb 28 '15 at 15:01
  • See http://stackoverflow.com/a/7691109/80901 for an answer of Remy Lebeau (Indy team) – mjn Feb 28 '15 at 15:05
  • Do you know in which unit or wrapper `IcmpSendEcho` is implemented? – user1580348 Feb 28 '15 at 15:37
  • Found a nice piece of code with `IcmpSendEcho` which seems to work perfectly without Administrator mode: http://www.delphipraxis.net/1251781-post4.html – user1580348 Feb 28 '15 at 16:47
  • @mjn Somebody might not know that `TIdIcmpClient` uses Raw Sockets, so he might find an answer here...? – user1580348 Feb 28 '15 at 16:58
  • That linked code is not so nice. You can translate it better for XE7 where you have all the needed data types available ([`except these two`](http://stackoverflow.com/q/17084031/960757), which are translated quite *extraordinarily* in that code, but well, it might work, since [`by my tests`](http://stackoverflow.com/questions/17084031/how-to-define-uchar-pointer-32-and-void-pointer-32-types-in-delphi#comment25601761_17084181) from the past, those members seems to not be of type `POINTER_32` in real). – TLama Feb 28 '15 at 20:12
  • @user1580348: as stated, `TIdIcmpClient` requires admin rights. This is because it uses a RAW socket to implement its ICMP. There are TODO items to change that requirement (native ICMP APIs on Windows, ICMP over UDP for OSX/iOS, etc), but it is not going to happen anytime soon. Maybe in Indy 11. – Remy Lebeau Feb 28 '15 at 20:56

0 Answers0