Solved

RemoveNetworkDrive with wildcards

Posted on 2004-08-19
4
567 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

728 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

14 Experts available now in Live!

Get 1:1 Help Now