Link to home
Start Free TrialLog in
Avatar of DrewBryant1961
DrewBryant1961

asked on

2003 Active directory vb login script does not always execute.

Hello:

I have a Windows 2003 domain (one forest, one domain) that I am working on a vb login script to map drives based on group membership. Client pcs are Windows XP. Currently, drives are statically mapped to a server share; the users home folder is mapped via ADUC.

I used an existing script (script below) I found on the web and modified it to suit my environment. The script deletes drive mappings and remaps them based on whether they are members of a global group.

Right now the script is linked as a GPO to an OU with a single user account.

I have 3 issues/questions.

1.      The script does not always run. I can execute it from a command prompt without error. It runs sometimes, but not always.
2.      When it does run, it is slow. There is a 30 second delay from the time the items in the startup group load to the time the mapped drives are listed.
3.      When I modifying the script, I added a piece of code to overlay the OS and patch level over the system tray. I thought it might be something I wanted to use. I didnt care for it, so I removed this piece of code from the login script, posted the updated script in GPMC and rebooted the client pc. The overlay is still there. Ran a gpupdate /force from the client; still there. Where is this being executed from?

Windows Version Overlay Add On

'Configure the PC to show the Windows Version and Service Pack as an overlay to the desktop above the System Tray
'=====================================
HKEY_CURRENT_USER = &H80000001
strComputer = WSHNetwork.Computername
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Control Panel\Desktop"
objReg.CreateKey HKEY_CURRENT_USER, strKeyPath
ValueName = "PaintDesktopVersion"
dwValue = 1
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

Login script is attached.

All responses appreciated as I am new to scripting.
'==========================================================================
'
' NAME: LoginScript.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' URL   : http://www.thespidersparlor.com
' Copyright (c) 2003-2007
' DATE  : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'          Maps and disconnects drives. 
'
'==========================================================================
 
ON ERROR RESUME NEXT
 
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
 
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
 
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
 
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
 
'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "H:", True, True
WSHNetwork.RemoveNetworkDrive "J:", True, True
WSHNetwork.RemoveNetworkDrive "K:", True, True
WSHNetwork.RemoveNetworkDrive "M:", True, True
WSHNetwork.RemoveNetworkDrive "P:", True, True
WSHNetwork.RemoveNetworkDrive "Q:", True, True
WSHNetwork.RemoveNetworkDrive "R:", True, True
WSHNetwork.RemoveNetworkDrive "S:", True, True
WSHNetwork.RemoveNetworkDrive "T:", True, True
WSHNetwork.RemoveNetworkDrive "U:", True, True
 
'Give the PC time to do the disconnect, wait 200 milliseconds
wscript.sleep 200
 
'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
'WSHNetwork.MapNetworkDrive "H:", "\\server\users\" & UserString,True
WSHNetwork.MapNetworkDrive "S:", "\\nas\scratch",True
 
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
    Select Case UCase(GroupObj.Name)
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
    'Note the use of all upper case letters as mentioned above.
    'Note also that the groups must be Global Groups.
 
        Case "MEETINGS"
            WSHNetwork.MapNetworkDrive "h:", "\\nas\meetings",True
        Case "DEBT"
            WSHNetwork.MapNetworkDrive "j:", "\\nas\superdebt",True
            WSHNetwork.MapNetworkDrive "m:", "\\nas\superdebt\Mip2006",True
        Case "IMIS"
            WSHNetwork.MapNetworkDrive "k:", "\\nas\imis\reports",True
        Case "DORN"
            WSHNetwork.MapNetworkDrive "m:", "\\nas\dorn",True
        Case "SALARY"
            WSHNetwork.MapNetworkDrive "p:", "\\nas\salary",True
        Case "LEGTRACKING"
            WSHNetwork.MapNetworkDrive "q:", "\\nas\winleg",True
        Case "WAGESALARY"
            WSHNetwork.MapNetworkDrive "r:", "\\nas\wagescac",True
        Case "ATTORNEYS"
            WSHNetwork.MapNetworkDrive "t:", "\\nas\attorney",True
        Case "INSURANCE"
            WSHNetwork.MapNetworkDrive "u:", "\\nas\insurance",True
      End Select
Next
 
' This section of script will prevent the balloon window
' that appears when printing to a network shared printer
' after XP Service Pack 2 is installed.
'=====================================
 
Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"
 
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
 
'Quit the Script
wscript.quit

Open in new window

Avatar of Paka
Paka

Answers to 1 & 2: Comment out line 15 by putting a ' in front of it.  This will enable error reporting so you can see if something is timing out.

Answer 3:  The settings in Active Directory - especially when you make registry changes are "sticky" - meaning that when you make the change, it changes the registry one way or the other.  To get it back to default settings, you'll have to find the default registry setting and use the script or group policy to set it to the default value.
Avatar of DrewBryant1961

ASKER

Thanks for the reply.

The script bombs when it tries to delete a drive that is not mapped. The error message is something along the lines of "the network connection does not exist" however I only wanted to remove the drive letters listed, not one that a user may have mapped himself. For example, if a user has mapped drive i somewhere, I want the script to ignore it. I thought if the drive was not mapped on the client machine, the script would continue ignore it and continue.

Is it possible to do just that?

 


Oops; I meant:

I thought if the drive was not mapped on the client machine, the script would ignore it and continue.
ASKER CERTIFIED SOLUTION
Avatar of Paka
Paka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works great. Thank you.