?
Solved

RemoveNetworkDrive with wildcards

Posted on 2004-08-19
4
Medium Priority
?
583 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
[X]
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
4 Comments
 
LVL 8

Assisted Solution

by:mladenovicz
mladenovicz earned 150 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 225 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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