Solved

VBSCRIPT - computer exists?

Posted on 2006-06-30
7
874 Views
Last Modified: 2008-01-09
Hi

Anyone know how to check if a computer on my domain is up or down?

I tried doing this but it says success when the drive p: doesnt exist!

dim WSHNetwork, WSHShell
Dim FileSysObj

set WSHShell=Wscript.CreateObject("Wscript.Shell")
Set WSHNetwork=Wscript.CreateObject("Wscript.Network")

ON ERROR RESUME Next
share = "\\pc024"
Drive = "p:"
If FileSysObj.DriveExists(share)=True Then
  if FileSysObj.DriveExists(Drive)=True Then
    'WSHNetwork.RemoveNetworkDrive Drive
    MsgBox "Success!" & share & "\" & drive & " does exist"
  else
    MsgBox "Error!" & share & "\" & drive & " does not exist"
  end If
end If
0
Comment
Question by:hmcgeehan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17019280
try

Drive = "p"
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17019291
then

if FileSysObj.DriveExists(Drive) Then
    'WSHNetwork.RemoveNetworkDrive Drive
    MsgBox "Success!" & share & "\" & drive & " does exist"
  else
    MsgBox "Error!" & share & "\" & drive & " does not exist"
  end If
0
 
LVL 6

Accepted Solution

by:
itdrms earned 20 total points
ID: 17026795
One liner at command line:
-------------------------------------------------------------------------------
for /f "delims=." %I in ('ping -n 1 pc024') do if "%I"=="Request timed out" (exit 55)

same in VBS:
-------------------------------------------------------------------------------
option explicit
dim share,WSHShell,cmdExec,cmdreturn
share = "pc024"

set WSHShell=Wscript.CreateObject("Wscript.Shell")
cmdExec = "for /f ""delims=."" %I in ('ping -n 1 "&share&"') do if ""%I""==""Request timed out"" (exit 55)"
cmdreturn = WSHShell.run("cmd /c "+ cmdExec,3,true)

if cmdreturn=0 Then
    cmdExec = "for /f ""delims=."" %I in ('ping -n 1 "&share&"') do if ""%I""==""Ping request could not find host "&share&""" (exit 65)"
    cmdreturn = WSHShell.run("cmd /c "+ cmdExec,3,true)
    if cmdreturn=0 Then
       MsgBox "Success! " & share &" responding"
    else
       MsgBox "Error! " & share &" not found in DNS"
    end if
else
    MsgBox "Error! " & share &" defined, but not responding"
end If

set WSHShell=Nothing



0
 
LVL 2

Expert Comment

by:TiwariVikas
ID: 17088983
Hi itdrms,

Great code !! I don't know whether the above code is useful in this particular question or not... but in general this is a very useful piece of code for me !!

Thanks a lot !!

Cheers,
VIkas.
0
 
LVL 6

Expert Comment

by:itdrms
ID: 17383656
well, since your asking, I'd appreciate getting the points.  I tested my script against the 3 possibilites of server state and the script worked properly to determine if a computer is up or down.  Thx
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question