Modify Mapped Drive Path on Login

Is there a way to modify the path of a mapped drive using a login script? For Example, when a user logs into their PC I want the login script to search for the existent of a local drive mapping that contains the name of a specific server, if that server name exist then change it to a new server name. Then map the drive using the same drive letter, but with the new server name.

I'm using .scr and .kix scripts for this.

Script Flow
1. User logs into computer
2. Login script checks for existent of Server1 in drive mapping BEFORE drives are
    actually mapped.
   If Server1 is detected in drive mapping then continue with script (go to step 3).
   If Server1 not detected in drive mapping  then Exit script (go to step 6).
3. Login script detects Drive F=\\Server1\ShareA
4. Login script changes Drive F path to new server, Drive F=\\NewServer\ShareA
5. Login script now maps computer’s Drive F=\\NewServer\ShareA
6. Exits
ei00004Network AdministratorAsked:
Who is Participating?
Julian HansenConnect With a Mentor Commented:
You will have to unmap and remap the drive.

The login script will run after the drives have already been mapped.

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections

Dim sSearchDrive, sOldPath, sNewPath
sSearchDrive = "F:"

For i = 0 to oDrives.Count - 1 Step 2
    if oDrives.Item(i) = sSearchDrive then
            sOldPath = LCase(oDrives.Item(i+1))
            If inStr(sOldPath, "server1") Then
                sNewPath = Replace(sOldPath, "server1", "newserver")
                ' Force update and update profile
                wshNetwork.RemoveNetworkDrive sSearchDrive, True, True
                ' remap drive to new path
                wshNetwork.MapNetworkDrive sSearchDrive, sNewPath
            End If 
        Exit For
    End If

Open in new window

Jim P.Commented:
You can do this easily with a login batch script. The question is how do you identify which server to map to?

Is it an AD group? Their login ID? Is it time of day?
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.