Change Location of Mapped Drive using VBScript at Logon

group-policylogon-scriptswindows-server-2003

I have a script, applied by group policy, that runs at user logon to remove specific mapped drives if they exist and then remaps them. Here's an example of the script:

Option Explicit
Dim WshNetwork, objUser, objNetwork
Dim strRemotePath1
Dim strDriveLetter1

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objNetwork = CreateObject("WScript.Network")

on error resume next

strDriveLetter1 = "H:"

WshNetwork.RemoveNetworkDrive strDriveLetter1, True, True

strRemotePath1 = "\\LocationA\hr"

objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1, true

Wscript.Quit

The script works when I run it by double-clicking it. If I change the strRemotePath1 variable to "\LocationB\hr", the change is made when I double-click to run the script. The drive is removed and then re-added with the new location. I know for a fact that the script is running when I log in as evidenced by the GPMT tool's Last Run time.

However, every time I log in, that drive is back to the old location. Are these scripts cached?

Best Answer

Try adding a delay between removing the drive and adding the drive.

wscript.sleep 300

See if that helps.

Related Topic