Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm in the process of moving file servers. Once completed, I will have to change the UNC path that the mapped drive letters used network wide to point to the new machine. I want to handle the change through a VBS logon script that I'll attach to OUs to map different drives.

The goal for the script is to first grab the UNC path for the F: (or whatever drive); if it equals "\old_server\files" then disconnect it and then reconnect it as "\new_server\files". Otherwise, do nothing. There's 5 paths/drives total that this will need to happen for.

I tried using Computer Performance's Already Connected Script but couldn't get it to work. It didn't disconnect the old drive when testing it out on multiple machines.

Any help is appreciated.

share|improve this question
My thought of verifying whether the UNC path exists or not was to "lighten the load" on the computer so there wouldn't have to be a bunch of unnecessary disconnects/reconnects. I'm not even sure if that's a valid concern or not. If not I can just use RemoveNetworkDrive to get rid of stuff and re-add it with the correct path every logon. – mikepreble May 5 '11 at 18:30
I don't think it's going to put any additional load on the computer. It may actually make the logon process faster since there's no test being performed. It's simply deleting and remapping. – joeqwerty May 5 '11 at 18:36
A similar question, along with my script to map drives, can be found in Windows Server 2008 Mapped Drive Not Showing on Workstations – Chris S Jun 3 '11 at 17:30

If you have a domain, then I'd look at doing a Group Policy Preference for the drive mapping. You should be able to have it map a given UNC to a given drive, and automatically replace any old mappings that exist.

share|improve this answer

Since you're really only testing for the existence of the old mapping and deleting that in order to make the new mapping, why not just use a Net X: /delete for the drive letters that you typically have mapped and then proceed with your Net Use X: statements. It won't do any harm to delete and remap a connection if it already exists for the new server.

share|improve this answer
Using a batch file would work fine, but I'd really like to incorporate VBS – mikepreble May 5 '11 at 19:55
there is also a possibility (which may or may not apply in this instance) that the drive letter in question is mapped to something else, in which case it needs to be left alone. – John Gardeniers May 6 '11 at 2:27

Bit late but is this want you want? this would have to be run locally on each pc - e.g in a login script like you say

Set objShell = CreateObject("Wscript.Shell")

Set objNet = WScript.CreateObject("Wscript.Network") 

Set objExec = objShell.Exec("net use ") 
strMaps = LCase(objExec.StdOut.ReadAll)

for x=1 to ubound(mapArray) 

    if instr(mapArray(x),"i:") AND instr(mapArray(x),"\oldserver1\sharex$") then 
        objNet.RemoveNetworkDrive "i:",true,true
        objNet.MapNetworkDrive "I:" , "\newserver1\shareX" 
    end if

    if instr(mapArray(x),"j:") AND instr(mapArray(x),"\\oldserver2\shareY$") then
            objNet.RemoveNetworkDrive "J:"
            objNet.MapNetworkDrive "J:" , "\\newserver2\shareX$"  
    end if  

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.