0

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?

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
pk.
  • 6,451
  • 2
  • 42
  • 63
  • Why not add some 'wscript.echo' entries before critical lines for debugging purposes. – Zoredache Oct 23 '09 at 16:41
  • Zoredache, should they be showing up during the logon process? I added a few but they're not popping up. I'm not sure if it's just that they don't pop up or if they aren't being called. – pk. Oct 23 '09 at 20:52

4 Answers4

1

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

wscript.sleep 300

See if that helps.

GregD
  • 8,713
  • 1
  • 24
  • 36
  • I tried adding the delay, that didn't seem to help. It really seems to be running a cached version of the script. If I double-click the script to test it, everything is mapped correctly with the new location. As soon as I log off and log back in, it changes it back to the old, incorrect location. So it's running a script and mapping things fine (with or without the pause), it's just not running the correct version of the script. – pk. Oct 23 '09 at 19:21
1

I second the WScript.Sleep but you may even try a longer period of time. I recently had a script watched for text files dropped in a folder. With a wait of, I think, 300 it still skipped files. I bumped that up to 1000 (a full second) and it fixed my issue.

1

Make it simple. Just delete the H Drive and Recreate it. If the H Drive does not exist, the "On Error Resume Next" will bypass the error and continue the script.

on Error Resume Next

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

Set fs = WScript.CreateObject ("Scripting.FileSystemObject")

If fs.DriveExists("H:") = True then wn.RemoveNetworkDrive "H:", true, true

wn.MapNetworkDrive "H:" , "\LocationA\hr"

Mike

0

The issue turned out to be embarrassingly simple. I had another script in a different GPO that was mapping it to the old location that I wasn't aware of. I fixed this situation and, of course, it worked fine.

Thanks for the help.

pk.
  • 6,451
  • 2
  • 42
  • 63