Feb 25th, 2012, 11:57 AM
VB6 - Clean Ping in VB6 Code
Here is version 2 of my PingIPv4.bas module. Version 1 was a little too feature-poor for publication.
There is a Ping() function that you pass an IP address string value to. There are optional arguments to set a non-default timeout in milliseconds or a string to be echoed as part of a larger payload. By default the timeout is 1000 and the data string is "".
In case you need name resolution you can call the helper function Resolve(). You pass a string containing either an IP address or network name (DNS, Hosts file, WINS, etc. host names) and it returns the IP adress string in the second argument. Then this "converted" string can be used with Ping() calls.
You can use this as-is, delete parts you don't need, expand upon it further, etc. (see the comments). You could also convert it to a Class which makes the code dynamic (i.e. if you only need to ping on occasion your program won't carry the baggage of a static module for its entire lifetime).
Tested on Windows 95 OSR2, Windows XP SP3, Windows Vista SP2, and Windows 7 SP1.
Atached here as part of a working demo Project.
While there is another example posted here somewhere it is pretty old and crusty. It also appears to have been hastily created from some really, really raggedy VB4 code he found somewhere.
Jul 30th, 2012, 10:05 AM
Re: VB6 - Clean Ping in VB6 Code
Here is a version 3 that takes care of wrapping the previous logic as a Class. It also exposes a RoundTripTime property instead of the entire ICMP_ECHO_REPLY structure (that is seldom needed anyway).
Remember, this is done with simple API calls. Thus you have none of the issues of the slow, clunky, heavyweight, and erratically available WMI Service - which was designed to support occasional admin scripting and not application logic. This works even where WMI doesn't exist at all, as well as where the Service has been disabled for security reasons.
Tags for this Thread
Click Here to Expand Forum to Full Width
Survey posted by VBForums.