views:

30

answers:

3

Hey,

I have the eventual goal of determining that a particular database on a particular server with particular credentials is running, but I would settle, at this point, for the ability to check and see if a server is actually up on the network. Does anyone have a way of doing this? I seem to be drawing a blank.

Michael

A: 

try this

Dim target
Dim result

target= "172.19.130.96"

Set shell = WScript.CreateObject("WScript.Shell")

Set shellexec = shell.Exec("ping " & target) 

result = LCase(shellexec.StdOut.ReadAll)

If InStr(result , "reply from") Then
  WScript.Echo "Server alive"  
Else
  WScript.Echo "Not Alive"
End If

There maybe better ways especialy given you end goal but this should work and at least point you in the correct direction.

Gratzy
You, sir, are fantastic. Thanks for the quick response.
Michael Beck
A: 

Here's an alternative solution that uses the Win32_PingStatus WMI class (note: this class is only available on Windows XP and later):

strServer = "stackoverflow.com"

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strServer & "'")

If oPing.StatusCode = 0 Then 
   WScript.Echo "Server is available."
Else
   WScript.Echo "Server is not available."
End If

More ping script samples here: Why Doesn't My Ping Script Run on Windows 2000 Computers?

Helen
A: 

For checking whether your database server is up, you can use tools like nmap. Then you can call it in your vbscript using exec() as per normal.

ghostdog74