Solved

Map Drives vbs causes errors

Posted on 2008-10-21
4
209 Views
Last Modified: 2010-04-24
I have this script to map drives in AD 2003: -
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "K:" , "\\files\shared"
objNetwork.MapNetworkDrive "S:" , "\\files\users"

The users get errors if drive is already mapped does anyone know the syntax to delete then map drives?
0
Comment
Question by:HKFuey
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:MatthiasVance
MatthiasVance earned 250 total points
ID: 22765945
I hope this helps you.

Kind regards,

Matthias Vance
objNetwork.RemoveNetworkDrive "K:"

Open in new window

0
 

Author Comment

by:HKFuey
ID: 22765960
Hi MatthiasVance
I did try that but I get errors if the drive is not mapped already!
0
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 250 total points
ID: 22765970
You can use 'On Error Resume Next' at the beginning of your script if you don't need error handling. If you do need error handling instead, we need to find a different solution.

Kind regards,

Matthias Vance
0
 
LVL 8

Expert Comment

by:mikainz
ID: 22766756

You can use the EnumNetworkDrives Method of the Wscript.Network object

something like

            set objdrive = objNetwork.EnumNetworkDrives
            For intDrive = 0 to objDrive.Count -1 Step 2
                  intNetLetter = IntNetLetter +1
                  letter=objDrive.Item(intDrive)
                  unc=objDrive.Item(intDrive +1)
                  If letter="K:" and unc <> "\\files\shared" Then
                        oNet.RemoveNetworkDrive "K:", true, true
                  End If
                  If letter="S:" and unc<>"\\files\users\" Then
                        oNet.RemoveNetworkDrive "S:", true, true
                  End If
            Next
            oNet.MapNetworkDrive "K:", "\\files\shared", true
                                oNet.MapNetworkDrive "S:", "\\files\users", true
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 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