Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

4 Answers

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

wscript.sleep 300

See if that helps.

share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment
up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

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.