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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
0
Julian HansenCommented:
You will have to unmap and remap the drive.

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

Solution:
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
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.