Solved

Map Drives vbs causes errors

Posted on 2008-10-21
4
204 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
Comment Utility
I hope this helps you.

Kind regards,

Matthias Vance
objNetwork.RemoveNetworkDrive "K:"

Open in new window

0
 

Author Comment

by:HKFuey
Comment Utility
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
Comment Utility
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
Comment Utility

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now