?
Solved

VBSCRIPT - computer exists?

Posted on 2006-06-30
7
Medium Priority
?
879 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 80 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

650 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