CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

Disconnecting a Network Drive

The following script uses the WshNetwork object's RemoveNetworkDrive method to disconnect a mapped network drive. The first parameter to this function is the drive letter. The optional second parameter is a boolean that indicates whether to force the drive to be disconnected even if it is in use (default false). The optional third parameter is also a boolean. It shows whether to update the user's profile with the change just made.

' Filename:  disconnect.vbs
' Author:  Br. David Carlson
' Date:  July 29, 2001
' Removes the network drive K, but only if it is Administrator who is logged in.
' Run this script when Administrator logs off.

Dim net

set net = Wscript.CreateObject("Wscript.Network")

if net.UserName = "Administrator" then
end if

The WshNetwork object has other useful methods, including ones such as AddPrinterConnection and RemovePrinterConnection.

Back to the Using WSH to Automate Tasks page

Author: Br. David Carlson
Last updated: August 03, 2006