?
Solved

Map Drives vbs causes errors

Posted on 2008-10-21
4
Medium Priority
?
212 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
[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
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:MatthiasVance
MatthiasVance earned 1000 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 1000 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

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

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
A hard and fast method for reducing Active Directory Administrators members.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
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