// Yazılım

Sending a Ping with VBS and Acting Based on the Response

code

The necessary code to ping a machine with Visual Basic Script and, based on the response received, perform an action accordingly if the device can be reached..

 

strHost="www.google.com"

if Ping(strHost) = True then
    'Wscript.Echo "Host " & strHost & " contacted"
	MsgBox("Baglanti VAR")
Else
    'Wscript.Echo "Host " & strHost & " could not be contacted"
	MsgBox("HATA")
end if

Function Ping(strHost)

    dim objPing, objRetStatus

    set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = '" & strHost & "'")

    for each objRetStatus in objPing
        if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
        Ping = False
            'WScript.Echo "Status code is " & objRetStatus.StatusCode
        else
            Ping = True
            'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
            'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
            'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
        end if
    next
End Function

 

// JOIN THE CONVERSATION

Share your experience

Bir sorunun, farklı bir çözümün veya eklemek istediğin bir notun var mı? Giriş yapmadan da yazabilirsin.

// KEEP READING

One more note.

All posts ↗︎