Richard
Wed Jan 25 13:05:48 CST 2006
Jason wrote:
>I want to create a script that with help a person determine if a pc is
>online or not based upon the PC name entered.
>
> My first thought was just.....
>
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Dim PcnameVariable
> PcnameVariable = Trim(InputBox("Enter a pc name ","Enter a PC name"))
>
> Wshshell.run "ping "&PcnameVariable ,0, false 'surpress the ping output
> window
>
> Then use a MsgBox to indicate if that PC in on-line or not. No need for
> the user to see anything else
>
> Any Ideas, or is there a easier way?
Hi,
I use the following function, based on work by other MVP's:
=======================
strComputer = "RemoteMachineNetBIOSName"
' Ping computer to see if online.
If (IsConnectible(strComputer, 1, 750) = True) Then
' Computer is online.
Else
' Computer is not online.
End If
Function IsConnectible(strHost, intPings, intTO)
' Returns True if strHost can be pinged.
Dim objFile, strResults
If intPings = "" Then intPings = 2
If intTO = "" Then intTO = 750
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
objShell.Run "%comspec% /c ping -n " & intPings & " -w " & intTO _
& " " & strHost & ">" & strTempFile, 0, True
Set objFile = objFSO.OpenTextFile(strTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
strResults = objFile.ReadAll
objFile.Close
Select Case InStr(strResults, "TTL=")
Case 0
IsConnectible = False
Case Else
IsConnectible = True
End Select
End Function
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net