Solved

RemoveNetworkDrive with wildcards

Posted on 2004-08-19
4
575 Views
Last Modified: 2010-05-18
Removing a network drive is easy enough. I would like to disconnect all mapped drives, then remap them in a login script. I would preferr not to have to have a line for each drive letter that exist. I thought there might be a way to use a wildcard in this. I like to keep things simple an short. Below is the script I am working from, nothing fancy.

on error resume next
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.RemoveNetworkDrive "D:"

WshNetwork.MapNetworkDrive "F:", "\\server\share"
WshNetwork.MapNetworkDrive "M:", "\\server\share"
WshNetwork.MapNetworkDrive "N:", "\\server\share"

Thanks
0
Comment
Question by:Curtv
4 Comments
 
LVL 8

Assisted Solution

by:mladenovicz
mladenovicz earned 50 total points
ID: 11858233
Dim oFSO        As Scripting.FileSystemObject
Dim oDrive      As Scripting.Drive
   
    Set oFSO = New Scripting.FileSystemObject
   
    For Each oDrive In oFSO.Drives
        If oDrive.DriveType = 3 Then Debug.Print oDrive.DriveLetter 'remove mapping code goes here
        End If
    Next
   
    Set oFSO = Nothing
0
 

Author Comment

by:Curtv
ID: 11881160
I think we missed the important part ( 'remove mapping code goes here) what would that be? I can delete individual drive mappings. I want to delete all drive mappings without listing each mapping.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 75 total points
ID: 11918312
Try this.

'Include a reference to Windows Script Host Object Model
Private Sub Command1_Click()
    Dim objWSH As New WshNetwork, _
        objDrives As WshCollection, _
        intCounter As Integer
    Set objDrives = objWSH.EnumNetworkDrives
    For intCounter = o To (objDrives.Count - 2) Step 2
        objWSH.RemoveNetworkDrive objDrives.Item(intCounter), True
    Next
    Set objDrives = Nothing
    Set objWSH = Nothing
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

713 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