VBS Logon Scripts - RemoveNetworkDrive
VBScript to Disconnect Network Drive
Your logon scripts gain two benefits from RemoveNetworkDrive. Firstly, preventing errors when you are trying to map a network drive that's already connected. Secondly, removing an existing network drive is particularly useful when your scripts are at the testing stage and you don't want to keep going to explorer, and clicking disconnect.
Topics for RemoveNetworkDrive
For me, the situation is that I am testing a script that maps a network drive, when I run the script for a second time, I get an error message. Now I could use On Error Resume Next, but that may mask other problems with the script, so I add a RemoveNetworkDrive statement. My friend 'Barking' Eddie love logoff scripts, and he includes a RemoveNetworkDrive in his tidy-up routine.
Normally, you just need two elements, the method, RemoveNetworkDrive and the drive letter.
objNetwork.RemoveNetworkDrive "H:" or
Mastering the basics of RemoveNetworkDrive are easy. If there is a danger it's what I call 'over think'. You do not need a comma before the drive letter, and you do not need the name of the network share. What you do need is - just the plain drive letter.
Even mastering the advanced arguments is not difficult, just watch out for the commas, here is the full syntax:
RemoveNetworkDrive strDriveLetter, bForce, bUpdateProfile
The b in bForce and bUpdateProfile means Boolean, this helps us by knowing that we should just add true or false. bForce means remove the drive even if its in use. (Rather like 'coming ready or not' in hide and seek.)
Setting bUpdateProfile to true tells VBScript to update the user's profile.
Even though RemoveNetworkDrive is easy, we need preparation in the form of drive that has already been connected. Otherwise there would be nothing to remove and all you would get is Error: 'This network connection does not exist'
' AddDrive.vbs -
Instructions to RemoveNetworkDrive
VBS Learning Points
Note 1: The basic RemoveNetworkDrive is a simple command with no commas and only one argument - the drive letter.
Note 2: Surprisingly, you do not need the network path.
Guy Recommends SolarWinds' Free Network Monitor
Thus utility makes it easy to check the health of a router or firewall. Check the real-time performance, and availability statistics, for any device on your network. Get started with an extensive collection of "out-of-the-box" monitors for popular network devices. Give Network Monitor a whirl - it's free. Download your free Network Device Monitor
If you need more comprehensive
network analysis software:
Just in case you need the bForce or the bUpdateProfile switch here is an example for the full RemoveNetworkDrive Command.
' AddDrive.vbs -
Instructions to Remove Network Drive
' RemNetDrivebForce.vbs - Windows Logon Script
Note 1: Spot the bForce, and bUpdateProfile commands, true, true.
Note 2: To test these extra RemoveNetworkDrive arguments, open a mapped network drive. Now try running the script with and without the bForce.
Note 3: The bonus part of this script is the error correcting code. Take the time to see how the If ... then, end if construction works. Also the objShell Run, which opens the Explorer.
I like the Permissions Monitor because it enables me to see quickly WHO has permissions to do WHAT. When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!
Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource. Give this permissions monitor a try - it's free!
RemoveNetworkDrive is a handy VBScript method for those times when you want to delete a network drive letter. If you want to prevent error messages when you run a test script for a second time, then just include a RemoveNetworkDrive command to roll back the MapNetworkDrive command.
If you like this page then please share it with your friends
See more logon scripts examples