Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for pingu.vbs

(view source code of pingu.vbs as plain text)

  1. On Error Resume Next
  2.  
  3. If WScript.Arguments.Count <> 1 Then Syntax( )
  4.  
  5. Dim pcEngine
  6. CheckEngine( )
  7.  
  8. Dim WshShell, objExec, input
  9. Set WshShell = CreateObject( "WScript.Shell" )
  10.  
  11. Do While True
  12. 	Set objExec  = WshShell.Exec( "ping.exe -n 4 -w 15000 " & WScript.Arguments(0) )
  13. 	input        = ""
  14.  
  15. 	Do While True
  16. 		If Not objExec.StdOut.AtEndOfStream Then
  17. 			input = input & objExec.StdOut.Read(1)
  18. 			If InStr( input, "TTL=" ) <> 0 Then Exit Do
  19. 		End If
  20. 		WScript.Sleep 100
  21. 	Loop
  22. 	If InStr( input, "TTL=" ) <> 0 Then Exit Do
  23. Loop
  24.  
  25. MsgBox "[" & Now & "]" & vbCrLf & vbCrLf & WScript.Arguments(0) & " is now on-line"
  26.  
  27. Do While objExec.Status <> 1
  28.      WScript.Sleep 100
  29. Loop
  30.  
  31.  
  32. Sub CheckEngine
  33. 	pcEngine = LCase( Mid( WScript.FullName, InStrRev( WScript.FullName, "\" ) + 1 ) )
  34. 	If Not pcEngine = "cscript.exe" Then
  35. 		Set WshShell = CreateObject( "WScript.Shell" )
  36. 		WshShell.Run "CSCRIPT.EXE //NoLogo " & Chr(34) _
  37. 		           & WScript.ScriptFullName & Chr(34)  _
  38. 		           & " " & WScript.Arguments(0)
  39. 		WScript.Quit(1)
  40. 	End If
  41. End Sub
  42.  
  43.  
  44. Sub Syntax
  45. 	strMsg = vbCrLf _
  46. 	       & "PingU.vbs,  Version 1.00"                     & vbCrLf _
  47. 	       & "Notify when a computer gets on-line" & vbCrLf & vbCrLf _
  48. 	       & "Usage:  [ CSCRIPT ]  PINGU.VBS  <hostname>"   & vbCrLf _
  49. 	       & "   or:  [ CSCRIPT ]  PINGU.VBS  <ip address>" & vbCrLf & vbCrLf _
  50. 	       & "Written by Rob van der Woude"                 & vbCrLf _
  51. 	       & "http://www.robvanderwoude.com"                & vbCrLf & vbCrLf _
  52. 	       & "CheckEngine subroutine by James Lim"          & vbCrLf _
  53. 	       & "http://www.windowsitpro.com/Article/ArticleID/48568/48568.html"
  54. 	WScript.Echo strMsg
  55. 	WScript.Quit(2)
  56. End Sub
  57.  

page last modified: 2024-04-16; loaded in 0.0076 seconds