Disconnect already existing Mapped Drives using VB or VBScript

Posted on 2008-11-19
Medium Priority
Last Modified: 2012-05-05
Hi there
I need to create a script that Disconnects all Mapped Drives on the users PC.  
I am new to VBscript and not sure where to go with this one.  Please could someone advice me or help me with code.  I have been looking on the net but not coming up with anything.
Question by:habbotha
  • 2
LVL 11

Accepted Solution

Antagony1960 earned 2000 total points
ID: 22993435
The snippet below should do it, but it will forcibly remove a connections whether it's in use or not. If you don't want it to do that, remove the ", True" part from line 4, but you'll have to put in an error handler to deal with drives which are still in use.
Set WN = WScript.CreateObject("WScript.Network")
Set AD = WN.EnumNetworkDrives()
For i = 0 To AD.Count - 1 Step 2	
   WN.RemoveNetworkDrive AD.Item(i), True
WScript.Echo "All 

Open in new window

LVL 11

Expert Comment

ID: 22993444
Sorry, I didn't finish of the echo line. It should have been:

WScript.Echo "All Mapped Network Drives have been Disconnected!"

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question