Link to home
Start Free TrialLog in
Avatar of grjitdept
grjitdept

asked on

How to use FileSystem object in vbscript to check C$ share on a server is accesible to verify server is alive...

Hi,

In question 22970139 an expert helped me develop the simple vbscript shown below that basically pings each server listed in an external text file, then returns a result for each server, formats all the results into a single string and then passes the string as the subject of a command line emailer (BMail). The script works a treat, but it was mentioned that I could also build in a FileSystem check to check the availability of the C$ share on each server being tested, as extra proof the server is alive.

So how in VBScript would I go about checking whether the C share on a remote server is 'accessible'?
SET objFSO = CreateObject("Scripting.FileSystemObject")
SET objInputfile = objFSO.OpenTextFile("serverhealthcheckserverlist.txt")
Set objShell = WScript.CreateObject( "WScript.Shell" )
resultsStr = ""
 
DO WHILE NOT objInputfile.AtEndOfStream
strComputer = objInputfile.readline
 
SET objExec = objShell.Exec("ping -n 2 -w 1000 " & strComputer)
strPingResults = LCase(objExec.StdOut.ReadAll)
IF InStr(strPingResults, "ttl") THEN
	resultsStr = resultsStr & strComputer & "_OK__"
ELSE
	resultsStr = resultsStr & strComputer & "_FAIL__"
END IF
LOOP
 
objShell.Run("bmail -s grj-exch01 -t ITalert@greatrail.com -f alert@greatrail.com -h -a ServerHealth -b " & resultsStr)
'msgbox(resultsStr)
 
Set objShell = Nothing
Set resultsStr = Nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of asawatzki
asawatzki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grjitdept
grjitdept

ASKER

Hi,

Thanks for this - looks good - when I run it for active servers though it always returns afail. It seems to me that you check for the value of err.number on line 16, and it's value is previously set on Line 13, but I don't see how this value would ever change. Doesn't Line 14 want to change the value of err.number?
OK ignore that last comment - a little more testing revealed I needed a '\' after the c$ as it's checking for a folder - without the \ it returns an error number of 51, hence it isn't 0 and fails the test... I now understand how the error.number works as well.

Thanks for your help!
Has anyone else gotten this to work?  I tried to get it to run but like grjitdept stated, it always fails.  I tried adding the \c$\  to the script but it still comes up as fail.  
Avatar of Chris Dent

Following this from another post.

Null is a reserved word, it returns "illegal assignment" when used in the context above. Change the "null" variable name to something else and it should spring to life.

Chris