PDA

View Full Version : [BATCH / VBSCRIPT / JScript] Ping e spegnegnere il pc


bedo2991
16-05-2009, 14:40
Mi serve uno script fatto in un qualunque linguaggio che esegua un ping ad un indirizzo. Se il pc risponde non fa nulla, altrimenti spegne un certo computer col comando "shutdown -s -f -t 0 -m \\DC1"
Non riesco a gestire questa storia del ping... Qualcuno mi aiuta?

BATCH:

ping -n 1 192.168.1.3 | find "durata" > nul
if errorlevel 1 echo %errorlevel% && shutdown -s -t 60 -f


VBSCRIPT

Dim i
i=2
ECHstrMachines = "PC-Inesistente;192.168.1.110"
aMachines = split(strMachines, ";")
For Each machine in aMachines
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& machine & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
WScript.Echo("Computer " & machine & " is not reachable")
i=i-1
End If
Next
Next
WScript.Echo i
If i <= 0 Then
Dim objShell
Dim strShutdown
strShutdown = "shutdown -s -t 60 -f"
set objShell = CreateObject("WScript.Shell")
objShell.Run strShutdown
End If
Wscript.Quit