' ********************************************************************* ' ' Name : UnmapNetworkDrive.vbs ' Author : 3Ds (UK) Limited ' Description : Example VBScript to unmap an existing shared drive. ' ' Arguments : 1 - Drive (letter) to unmap. ' ' WIZARD:PARAMS=1 = Drive letter to be unmapped (letter only, no ":") ' WIZARD:PARAMEXAMPLE=X ' ' Returns : 0 - Success ' 1 - An error occurred. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from running.||Script output also indicates "OK" for success, or "Error" with details of the faults found. ' ' Notes : Requires Windows Scripting Host (for VBScript). ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objArguments ' Command line arguments Dim objNetwork ' Network object Dim strDriveToUnMap ' The drive we want to unmap ' ------ Main Logic ------ ' Retrieve the drive to unmapped Set objArguments = WScript.Arguments strDriveToUnMap = objArguments.Item(0) If Len (strDriveToUnMap) = 0 Then WScript.Echo "Error. Cannot unmap drive. No drive letter specified" WScript.Quit (1) End If ' Check parameter If Len (strDriveToUnMap) > 1 Then WScript.Echo "Error. Cannot unmap drive. Drive specified is not in the correct format (specify letter only)" WScript.Quit (1) End If ' Create our network reference Set objNetwork = WScript.CreateObject("WScript.Network") If Err.Number <> 0 Then ' Error WScript.Echo "Error. Unable to create the network object. " & Err.Description WScript.Quit(1) End If ' Unmap the drive objNetwork.RemoveNetworkDrive strDriveToUnMap If Err.Number <> 0 Then ' Failed to unmap Set objNetwork = Nothing WScript.Echo "Error. Unable to unmap the drive " & strDriveToUnMap & ". " & Err.Description WScript.Quit (1) End If ' ------ Cleanup ------ Set objNetwork = Nothing WScript.Echo "OK. The drive was unmapped successfully" WScript.Quit (0) ' ------ End of Script ------