[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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
0
csimmons1324
Asked:
csimmons1324
  • 3
  • 3
  • 2
1 Solution
 
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
 
LauraEHunterMVPCommented:
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
 
csimmons1324Author 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
csimmons1324Author Commented:
LauraEHunterMVP,

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

Thanks,

Chris
0
 
LauraEHunterMVPCommented:
VBScript
0
 
csimmons1324Author 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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now