?
Solved

Disconnect already existing Mapped Drives using VB or VBScript

Posted on 2008-11-19
2
Medium Priority
?
329 Views
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.
Thanks
Heather
0
Comment
Question by:habbotha
  • 2
2 Comments
 
LVL 11

Accepted Solution

by:
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
Next
WScript.Echo "All 

Open in new window

0
 
LVL 11

Expert Comment

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

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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