Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

RemoveNetworkDrive with wildcards

Posted on 2004-08-19
4
574 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 48
Spell Check in VB6 13 126
Help me. 3 60
Automatic Email Reminder 4 57
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…
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…

840 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