Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RemoveNetworkDrive with wildcards

Posted on 2004-08-19
4
Medium Priority
?
585 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

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

618 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