Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

GPO login behaves oddly with Windows 7

$
0
0
this one is very weird but it could be definitely something i'm coding wrong. simple login script:


1. remove all mapped drives
2. sleep for 1 second to allow new network mapping
3. add new mapped drive M:

very simple login script. when i run it manually on Windows XP or Windows 7 (logged in with user account and current mapped drives) it works exactly as expected. when used with GPO as a "User Configuration" -> Script -> Logon, and "Security Filtering" set with "Authenticated Users" it only works on Windows XP. meaning it does steps 1, 2, and 3 exactly as expected.

when testing the same GPO, logging in with a Windows 7 with the same username just tested on the XP machine, it runs the logon script but doesn't remove any of the mapped drives. i know it ran the script because i put different msgbox outputs so i know the GPO pushed the script down. here's the code, and "on error resume next" is commented out to check for errors but there are no errors

--- start code ---

'On Error Resume Next
wscript.sleep(60000)  'thought the login script was running too early but i even changed it to 5mins and i'm still getting false info from colDrives as login script, and only on Windows 7 operating system

const FileSrv = "\\server1" 'File SRV
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives()

msgbox (colDrives.Count)  'used for debugging.  when ran as a GPO login for Windows 7 it didn't find any mapped drives on my client desktops and there's currently 4 mapped drives but the msgbox output is 0.  when i don't run this as a logon script and run in on the same desktop manually the colDrives.Count output is 4 on the same desktop, very odd.

 For i = 0 to colDrives.Count-1 Step 2
     objNetwork.RemoveNetworkDrive colDrives.Item(i), True, True  'delete each network drive, and force disconnect
 Next

wscript.sleep(1000) 'allow time for mapping of new drive

objNetwork.MapNetworkDrive "M:", FileSrv & "\Networkshares", true  'map just one drive for testing
msgbox ("done")  'notify it was completed.  this way i know the GPO pushed the script down.

what i can figure out is that the code works when executed on the desktop for both XP and win 7. but when used as a login script for Windows 7 the colDrives.Count will equal 0, giving a false result. but when i run this script on the same desktop manually after logging in the colDrives.Count will equal 4 giving the correct result.

i also thought to myself maybe the login script is executing much to fast and too early. i put a wscript.sleep(60000) 1 minute and then execute, the colDrives.Count still equal 0 (false result).

so in conclusion it looks as though when ran as a login script, Windows 7 doesn't read or process the objNetwork.EnunNetworkDrives() correctly. Has anyone experience the same issue with Windows 7? that the vbs will work when executed locally on desktop but when used as a logon script it doesn't behave as expected. i'm trying to figure out a way around it. and yes we do have to remove all the mapped drives because the drive letters and paths change regularly, hence the disconnecting of all mapped drives. thanks in advance!



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>