Script to delete and add mapped drives in Server 2003.

I am looking to create a logon script that will remove all mapped drives from the client PC and then map the drives stated in the same script.  Here is what I have:

<script>

On Error Resume Next

set Net = CreateObject("Wscript.Network")
set Drives = Net.EnumNetworkDrives

for each item in Drives
     if right(item,1) = ":" then
          Net.RemoveNetworkDrive item
     end if
next

Net.MapNetworkDrive "H:", "\\10.0.0.2\Departments"
Net.MapNetworkDrive "X:", "\\10.0.0.103\Syteline.map"

<end script>

Can someone please confirm if this script will do what I am looking for?  

Thanks,

Chris
csimmons1324IT ManagerAsked:
Who is Participating?
 
LauraEHunterMVPConnect With a Mentor Commented:
I tend to use a .Run command to blow out all drive mappings:

Set WshShell = WScript.CreateObject("WScript.Shell")
oExec = wshShell.Run ("net use * /delete /y",0,TRUE)
0
 
MrLonandBCommented:
NET USE I: /DELETE
NET USE I: \\172.16.1.187\APPS

That one works for me. Created as a login.bat file, placed it in the sysvol folder of my domain controller and identified it in ADUC > User Properties > Profile > Login Script.
0
 
csimmons1324IT ManagerAuthor Commented:
MrLonandB,

My problem is that I don't know if my users have mapped any drives.  Therefore, I would have to create a NET USE <letter>: /Delete for every letter of the alphabet to make sure that I have removed every possible drive letter.  This seems very cumbersome.

Later,

Chris
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
csimmons1324IT ManagerAuthor Commented:
LauraEHunterMVP,

Is that a vb script or would I just put that into a .bat file?

Thanks,

Chris
0
 
LauraEHunterMVPCommented:
VBScript
0
 
csimmons1324IT ManagerAuthor Commented:
LauraEHunterMVP,

Then to map the drives I would use the following code in my vbscript, correct?

Net.MapNetworkDrive "H:", "\\10.0.0.2\Departments"
Net.MapNetworkDrive "X:", "\\10.0.0.103\Syteline.map"

Thanks,

Chris
0
 
MrLonandBCommented:
NET USE * /D

That will remove all mapped drives.
0
 
LauraEHunterMVPCommented:
Correct.  Delete all drive mappings using the code I listed, then map the ones you want using the MapNetworkDrive function.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.