Solved

VBSCRIPT - computer exists?

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 78
sumDigits  challenge 7 62
question about windows batch/script 3 41
how to use wail2ban ?? 13 40
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 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.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now