How to Ping a Server From VB6

Updated July 19, 2017

You can use the Windows ICMP link library to ping an address in Visual Basic 6 (VB6). The DLL is included with the Windows operating system to handle networking requests for TCP/IP, which is the protocol used in internal networks and on the Internet. You must include the DLL in your VB6 code, ping the server and assign the results to a string.

Right-click the SLN file that contains your VB6 and click "Open With." Double-click the "Visual Basic" program displayed in the list of programs.

Right-click the form you want to use to ping the server. Copy and paste the following DLL link to the top of your VB6 file:

Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long

Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long

These two DLLs provide the functions to ping and communicate over the TCP/IP protocol.

Ping the server. The following code pins the server:

Public Function ping("server", Reply As ICMP_ECHO_REPLY) As Long

Replace "server" with the name or IP address of the server. The replay is stored in the "echo reply" variable.

Print out the results from the ping. The following code sends the result to a string and displays the result in a message box:

Dim ping As String

ping = Reply.Status

MsgBox ping

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Jim Campbell has been a computer engineer for over five years. He excels in hardware repair, computer programming and troubleshooting, and software design. He is currently attending Florida Atlantic University, pursuing a master's degree in computer and electrical engineering and fine-tuning his technical writing abilities.