2/28/2008

vbscript to check if a computer is available

  1. Option Explicit  
  2. dim objPing  
  3. dim objStatus  
  4. dim strComputer  
  5.   
  6. strComputer="." 'IP Address or Name  
  7. Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._  
  8. ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")  
  9.   
  10. For Each objStatus in objPing  
  11.  If  IsNull(objStatus.ReplySize) Then  
  12.   WScript.Echo "computer is offline"  
  13.   '...  
  14.  Else  
  15.   WScript.Echo "computer is online"  
  16.   '...  
  17.  End If  
  18. Next  
  19.   
  20. Set objPing=Nothing  
  21. Set objStatus=Nothing  

No comments: