Exemple de script Visual Basic

Remplacez l'adresse IP colorée en rouge par l'adresse de la machine cible des requêtes ICMP :

Function Ping( myHostName )
' This function returns True if the specified host could be pinged. ' myHostName can be a computer name or IP address. ' The Win32_PingStatus class used in this function requires Windows XP or later. ' This function is based on the TestPing function in a sample script by Don Jones ' http://www.scriptinganswers.com/vault/computer%20management/default.asp#activedirectoryquickworkstationinventorytxt ' Standard housekeeping Dim colPingResults, objPingResult, strQuery ' Define the WMI query strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & myHostName & "'" ' Run the WMI query Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery ) ' Translate the query results to either True or False For Each objPingResult In colPingResults If Not IsObject( objPingResult ) Then Ping = False ElseIf objPingResult.StatusCode = 0 Then Ping = True Else Ping = False End If Next Set colPingResults = Nothing End Function If Ping("192.168.56.10") Then Wscript.echo "yes" Wscript.quit(1) Else Wscript.echo "no" wscript.quit(0) End If