Disconnect already existing Mapped Drives using VB or VBScript

Posted on 2008-11-19
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
    LVL 11

    Accepted Solution

    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

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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    This article will show, step by step, how to integrate R code into a R Sweave document
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now