' ********************************************************************* ' ' Name : Verify Network Share.vbs ' Author : 3Ds (UK) Limited ' Description : VBScript to verify that a specified netwoek share ' exists. ' Script Type : Monitoring. ' Arguments : 1 - The name of the server or PC on which the share resides ' 2 - The name of the share to verify ' Returns : 0 - Success, 1 - failed to run, 2 - share does not exist. ' Notes : Requires Windows Scripting Host (for VBScript). ' ' WIZARD:PARAMS=1 = Name of the Server on which the share resides|2 = The name of the share to verify ' WIZARD:PARAMEXAMPLE=YourQueueName ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running|2 = The share name does not exist on the server specified.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objArgs ' Inbound command-line arguments Dim objWMIService ' Our WMI object reference Dim colShares ' Share information (collection) Dim strPC ' Our PC name Dim strShare ' Our share name ' ------ Main Logic ------ Set objArgs = WScript.Arguments ' Retrieve command line arguments If objArgs.Count <> 2 Then ' Insufficient arguments WScript.Echo "Error. One or more arguments missing, or too many specified" WScript.Quit(1) End If strPC = objArgs.Item(0) strShare = objArgs.Item(1) ' Connect to the WMI Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPC & "\root\cimv2") If Err.Number <> 0 Then ' Failed to retrieve the object WScript.Echo "Error. Unable to connect to WMI. " & Err.Description WScript.Quit(1) End If ' Get our share Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Name = '" & strShare & "'") If Err.Number <> 0 Then ' Failed to run the query WScript.Echo "Error. Unable to access network share information. " & Err.Description Set objWMIService = Nothing WScript.Quit(1) End If ' Do we have any data If colShares.Count < 1 Then ' No information available so assume the share does not exist WScript.Echo "Error. The network share could not be located." Set colShares = Nothing Set objWMIService = Nothing WScript.Quit(2) End If ' ------ Cleanup ------ ' Must exist Set colShares = Nothing Set objWMIService = Nothing WScript.Echo "OK. The network share was located successfully." WScript.Quit (0) ' ------ End of Script ------