How to disconnect a network drive using vbscript
Below is a script to disconnect a network drive using vbscript. We employ the services of WScript.Network object to do the same
Enjoy!. There are two functions below. One is the actual disconnect drive and the other one is to parse the command line arguments. We want to make sure the drive letter that has to be disconnected, is specified as an input parameter to the script.
'FileName : disconnectdrive.vbs
'Purpose : To disconnect specified network drive
'Usage : Usage : cscript //nologo disconnectdrive.vbs <drive>
'To Debug : cscript //D //X //nologo disconnectdrive.vbs <drive>
'Example : Usage : cscript //nologo disconnectdrive.vbs i:
'Date : 08/01/2008Function disconnectdrive()
set objNetwork = WScript.CreateObject(“WScript.Network”)
Set ObjFSO = CreateObject(“Scripting.FileSystemObject”)
strDrive = WScript.Arguments(0)if(ObjFSO.DriveExists(strDrive)) then
objNetwork.RemoveNetworkDrive strDrive, True, True
WScript.Echo “Disconnected network drive : ” & strDrive
end ifSet ObjFSO = nothing
Set objNetwork = nothing
End function
‘———————————————————————————————
Function parseArgs()
Dim filelen
filelen = WScript.Arguments.length
if filelen < 1 Then
WScript.Echo(“Usage : cscript //nologo disconnectdrive.vbs <drive>”)
WScript.Echo(“Example : cscript //nologo disconnectdrive.vbs i:”)
WScript.Quit()
end if
disconnectdrive()
End function
‘———————————————————————————————
parseArgs()
No comments yet.
Leave a comment
-
Archives
- June 2009 (1)
- April 2009 (1)
- March 2009 (1)
- August 2008 (5)
- July 2008 (4)
- May 2008 (2)
- April 2008 (3)
- February 2008 (3)
-
Categories
-
RSS
Entries RSS
Comments RSS