haripotter’s technorati

Just another WordPress.com weblog

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/2008

Function 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 if

Set 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()

August 2, 2008 - Posted by haripotter | HP Quality Center and QTP | , , , , , | No Comments Yet

No comments yet.

Leave a comment