# Solved: Have list of computers need VBScript to only run on the onese currently online.



## StumpedTechy (Jul 7, 2004)

Anyway to use VBScript to determine if a PC is online and only run the rest of the script against those that are online. I have a code that works fine when ran against alot of turned on computers but gives me an error once it trys and connects to the first unreachable PC and it actually stops the processing for the rest of the list.

I.E. If I have a list of 4 computers and the second one is turned off the 3rd and 4th don't get the script ran against it. The error is created in a create object sting that can't create the object because the PC is turned off.


----------



## cristobal03 (Aug 5, 2005)

How are you identifying the computers? I imagine you have a list of computer names. You could try to ping each one before executing the remainder of the process. But this sounds familiar...have you tried something like that before?

chris.


----------



## StumpedTechy (Jul 7, 2004)

Nope but I just passed along some code that did the trick nicely.


```
Function IsAlive(strHost)
'---------- Test to see if host or url alive through ping -----------------
' Returns True if Host responds to ping
' 
' Though there are other ways to ping a computer, Win2K,
' XP and different versions of PING return different error
' codes. So the only reliable way to see if the ping
' was sucessful is to read the output of the ping
' command and look for "TTL="
' 
' strHost is a hostname or IP 
    Const OpenAsASCII = 0 
     Const FailIfNotExist = 0 
     Const ForReading =  1 
     Dim objShell, objFSO, sTempFile, fFile 
    Set objShell = CreateObject("WScript.Shell") 
     Set objFSO = CreateObject("Scripting.FileSystemObject") 
    sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName 
    objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & ">" & sTempFile, 0 , True 
    Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII) 
    Select Case InStr(fFile.ReadAll, "TTL=") 
         Case 0
            IsAlive = False 
         Case Else
            IsAlive = True 
    End Select 
    ffile.close 
     objFSO.DeleteFile(sTempFile)
    Set objFSO = Nothing
    Set objShell = Nothing
End Function
```


----------

