Solved

Map Drives vbs causes errors

Posted on 2008-10-21
4
210 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
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 …
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 …

733 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