Professional Documents
Culture Documents
Making A PING With Delphi and The WMI - The Road To Delphi
Making A PING With Delphi and The WMI - The Road To Delphi
Making A PING With Delphi and The WMI - The Road To Delphi
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 1/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
BLOG STATS
Now check this sample console application.
1,871,417 hits
1 program WMIPing;
2
3 {$APPTYPE CONSOLE} SEARCH
4
5 uses
6 SysUtils,
7 ActiveX, SEARCH
8 ComObj,
9 Variants;
10
11 function GetStatusCodeStr(statusCode:integer) : str
12 begin
FOLLOW B LOG VIA
13 case statusCode of EMAIL
14 0 : Result:='Success';
15 11001 : Result:='Buffer Too Small'; Enter your email address
16 11002 : Result:='Destination Net Unreachable'; to follow this blog and
17 11003 : Result:='Destination Host Unreachable'; receive notifications of
18 11004 : Result:='Destination Protocol Unreachab new posts by email.
19 11005 : Result:='Destination Port Unreachable'; Join 1,331 other followers
20 11006 : Result:='No Resources'; Enter your email address
21 11007 : Result:='Bad Option';
Follow
22 11008 : Result:='Hardware Error';
23 11009 : Result:='Packet Too Big';
24 11010 : Result:='Request Timed Out';
25 11011 : Result:='Bad Request';
26 11012 : Result:='Bad Route'; FOLLOW M E ON
27 11013 : Result:='TimeToLive Expired Transit'; TWIT TER
28 11014 : Result:='TimeToLive Expired Reassembly'
29 11015 : Result:='Parameter Problem'; My Tweets
30 11016 : Result:='Source Quench';
31 11017 : Result:='Option Too Big';
32 11018 : Result:='Bad Destination';
33 11032 : Result:='Negotiating IPSEC';
34 11050 : Result:='General Failure'
35 else
36 result:='Unknow';
37 end;
38 end;
39
40
41 //The form of the Address parameter can be either t TRANSLATE
42 procedure Ping(const Address:string;Retries,Buffer
43 var Translate this blog into
44 FSWbemLocator : OLEVariant; different languages...
45 FWMIService : OLEVariant;
46 FWbemObjectSet: OLEVariant;
47 FWbemObject : OLEVariant; اﻟﻌرﺑﯾﺔ
48 oEnum : IEnumvariant; Български
49 iValue : LongWord; 中文(简体)
50 i : Integer; 中文(繁體)
51
52 PacketsReceived : Integer; Hrvatski
53 Minimum : Integer; Česky
54 Maximum : Integer; Dansk
55 Average : Integer; Nederlands
56 begin;
57 PacketsReceived:=0; Suomi
58 Minimum :=0; Français
59 Maximum :=0; Deutsch
60 Average :=0; Ελληνική
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 2/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
61 Writeln(''); िह ी
62 Writeln(Format('Pinging %s with %d bytes of data: Italiano
63 FSWbemLocator := CreateOleObject('WbemScripting.S
日本語
64 FWMIService := FSWbemLocator.ConnectServer('loc
65 //FWMIService := FSWbemLocator.ConnectServer('1 한국어
66 for i := 0 to Retries-1 do Norsk
67 begin Polski
68 FWbemObjectSet:= FWMIService.ExecQuery(Format('
Português
69 oEnum := IUnknown(FWbemObjectSet._NewEn
70 if oEnum.Next(1, FWbemObject, iValue) = 0 then Română
71 begin Русский
72 if FWbemObject.StatusCode=0 then Español
73 begin
Svenska
74 if FWbemObject.ResponseTime>0 then
75 Writeln(Format('Reply from %s: bytes=%s t
76 else
77 Writeln(Format('Reply from %s: bytes=%s t
78
79 Inc(PacketsReceived);
80
81 if FWbemObject.ResponseTime>Maximum then
82 Maximum:=FWbemObject.ResponseTime;
83
84 if Minimum=0 then
85 Minimum:=Maximum;
86 BLOGROLL
87 if FWbemObject.ResponseTime<Minimum then
88 Minimum:=FWbemObject.ResponseTime; Andy’s Blog and Tools
89
Delphi – Neftali
90 Average:=Average+FWbemObject.ResponseTime;
91 end Delphi Haven – Chris
92 else Rolliston Blog
93 if not VarIsNull(FWbemObject.StatusCode) then
94 Writeln(Format('Reply from %s: %s',[FWbemOb Delphi sorcery – Stefan
95 else Glienke's Blog
96 Writeln(Format('Reply from %s: %s',[Address Delphifeeds.com
97 end;
98 FWbemObject:=Unassigned; Felix J COLIBRI
99 FWbemObjectSet:=Unassigned; Hallvard's Blog
100 //Sleep(500);
101 end; Hey, Scripting Guy! Blog
102 JEDI Windows API
103 Writeln('');
104 Writeln(Format('Ping statistics for %s:',[Address Peter Johnson's
105 Writeln(Format(' Packets: Sent = %d, Received DelphiDabbler.com
106 if PacketsReceived>0 then Reinvent The Wheel
107 begin
108 Writeln('Approximate round trip times in milli-s RemObject Blog
109 Writeln(Format(' Minimum = %dms, Maximum = %d Rudy's Delphi Corner
110 end;
111 end; Scott Hanselman Blog
112 Sip from the Firehose
113
114 begin The Art of Delphi
115 try Programming
116 CoInitialize(nil); The Delphi Geek
117 try
118 //Ping('192.168.52.130',4,32); The Old New Thing
119 Ping('theroadtodelphi.wordpress.com',4,32); The Oracle at Delphi
120 finally
121 CoUninitialize; The TIndex
122 end; YAPB – Alex Ciobanu Blog
123 except
124 on E:Exception do
125 Writeln(E.Classname, ':', E.Message);
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 3/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
CATEGOR IES
.Net (13)
ADO (2)
ADSI (1)
Applications (16)
Bing API (3)
C# (2)
C++ Builder (1)
Cpp (1)
Email Print Facebook Reddit Pocket Twitter
Delphi (207)
Thanks.
DELPHIFEEDS
Thanks.
An error has occurred; the
Reply feed is probably down. Try
again later.
Rodrigo
February 2, 2011 at 2:37 pm
STACKOVERFLOW
WanC , which browser are you using? the code looks good DELPHI QUESTION S
in Firefox and IE Explorer.
Delphi : How to use
Reply system.RegularExpressions
in my case? October 17,
2019 rooky06
How to avoid that
Radu
TStrings.SaveToFile creates
February 2, 2011 at 9:07 am
a final empty line? October
17, 2019 Fabrizio
Hi Rodrigo,
Real-Time Collaboration
As usual exceptional examples with very useful information! [on hold] October 16, 2019
On this example I could suggest you to change Soufiane Bra
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 5/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
machine name when you use the ConnectServer function. How to Parse JSON in
about the commented line is just for illustrate which you Delphi [duplicate] October
16, 2019 Ant
can make a ping from a remote machine using the WMI.
Reply
Domingo
February 2, 2011 at 10:03 am
Gracias
Reply
Rodrigo
February 2, 2011 at 2:41 pm
Reply
Rafael Colucci
April 5, 2011 at 12:39 pm
Reply
Rodrigo
April 5, 2011 at 12:56 pm
Reply
Rafael Colucci
April 5, 2011 at 1:10 pm
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 7/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
Rodrigo
April 5, 2011 at 1:15 pm
EMB
August 29, 2011 at 3:01 pm
EMB
Reply
Rodrigo
August 29, 2011 at 3:48 pm
Reply
EMB
August 30, 2011 at 10:40 am
Thanks! (:
the problem with IcmpSendEcho is that we should
not statically link to the library. Instead, call
LoadLibrary and then GetProccess, and if fails, try
again.
Sometimes, I just wanna a simpler code that work in
all target windows…
Reply
Pingback: WMI Tasks using Delphi – Networking « The Road to Delphi – a Blog
about programming
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 8/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
Abraão
August 9, 2012 at 8:31 am
Reply
Rodrigo
February 7, 2013 at 12:22 am
Reply
Massimo Voto
June 23, 2013 at 2:50 am
Hi Rodrigo
Thank for good example. The ICMP of Indy on W7 64 not work,
and your example work for all target windows.
Reply
víctor
November 7, 2013 at 3:46 pm
Reply
asqar
February 3, 2014 at 12:11 pm
Reply
Rodrigo
February 3, 2014 at 12:25 pm
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 9/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
Reply
asqar
February 3, 2014 at 1:08 pm
Reply
Jorge Abel
April 30, 2014 at 11:13 am
Reply
Rodrigo
April 30, 2014 at 4:09 pm
Reply
Olav
September 30, 2014 at 2:28 pm
Reply
Rodrigo
October 2, 2014 at 10:40 am
Reply
Sean Roulo
November 1, 2014 at 7:43 pm
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 10/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
Reply
Rob
January 28, 2015 at 3:55 am
Reply
dagobert
March 20, 2016 at 10:36 am
Reply
Rodrigo
March 20, 2016 at 11:23 pm
Reply
Arthur Guimarães
June 22, 2016 at 10:36 am
Reply
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 11/12
17/10/2019 Making a PING with Delphi and the WMI | The Road to Delphi
Rodrigo
June 22, 2016 at 5:09 pm
NO, I don’t made that test before, but you can try
yourself.
Reply
Volker Giese
October 24, 2016 at 10:59 am
Hi Rodrigo,
Reply
Rodrigo
October 24, 2016 at 11:07 am
Reply
Leave a Reply
Enter your comment here...
Blog at WordPress.com.
Top
https://theroadtodelphi.com/2011/02/02/making-a-ping-with-delphi-and-the-wmi/ 12/12