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
Solved

VBSCRIPT - computer exists?

Posted on 2006-06-30
7
872 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
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
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 …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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