Solved

VBSCRIPT - computer exists?

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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 107
User profile Size Report 3 74
Zip Folders Using Chilkat Routines 1 41
Batch file to convert a xlsx file to csv 5 102
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

803 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