Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Command Prompt Question 1

Status
Not open for further replies.

nafogel

Technical User
May 12, 2010
1
US
Hi all,

I am working on web app that pings remote servers to see if they are alive (has to be client-side script as app is being used as desktop "widgit" to monitor remote servers). I got the script to work but everytime it pings the distant end an annoying dos window pops up for a second. Is there anyway to hide the window when it runs the command? See source code below:

----
Dim results

On Error Resume Next

Set shell = CreateObject("WScript.Shell")


Set exec = shell.Exec("ping -n 1 -w 100 " & Target)
results = LCase(exec.StdOut.ReadAll)

Ping = (InStr(results, "reply from") > 0)
End Function
If Ping("192.168.2.1") Then

'script to visually show ping status (not relevant)

End If
----

I don't have too much familiarity with VBscript (prefer javascript), but this is the only way I know how to ping via client-side scripting. Any help? Thanks
 
its your Shell.Exec, you could try and use something like cmd /??? and some parameter to start the shell minimized but im not sure it supports it.
i am sure ther eis a simple solution to this....WshShell.Run can use , 1, True where the 1 can be changed to how you want the new process disaplyed, but then you can read standard output from the ping.
How about the Win32_Ping class from WMI, that will accomplish the same thing but wont result in the dos window?

from MS scripting guys site?

On Error Resume Next
strComputer = "sea-wks-1"
strPingStatus = PingStatus(strComputer)
If strPingStatus = "Success" Then
Wscript.Echo "Success pinging " & strComputer
Else
Wscript.Echo "Failure pinging " & strComputer & ": " & strPingStatus
End If

'******************************************************************************

Function PingStatus(strComputer)

On Error Resume Next
strWorkstation = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
For Each objPing in colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Success"
Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
Case 11004 PingStatus = _
"Status code 11004 - Destination Protocol Unreachable"
Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
Case 11006 PingStatus = "Status code 11006 - No Resources"
Case 11007 PingStatus = "Status code 11007 - Bad Option"
Case 11008 PingStatus = "Status code 11008 - Hardware Error"
Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
Case 11011 PingStatus = "Status code 11011 - Bad Request"
Case 11012 PingStatus = "Status code 11012 - Bad Route"
Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
Case 11014 PingStatus = _
"Status code 11014 - TimeToLive Expired Reassembly"
Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
Case 11016 PingStatus = "Status code 11016 - Source Quench"
Case 11017 PingStatus = "Status code 11017 - Option Too Big"
Case 11018 PingStatus = "Status code 11018 - Bad Destination"
Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
Case 11050 PingStatus = "Status code 11050 - General Failure"
Case Else PingStatus = "Status code " & objPing.StatusCode & _
" - Unable to determine cause of failure."
End Select
Next

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top