Digitalcandy
IS-IT--Management
I am using an edited version of markdmac's LoginScript.vbs, Thanks Mark, and I am having trouble with some code. I want to install and set default printers based on group membership. Below is my edited version which isn't creating or setting the default printer when I specify the correct UNC path.
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"
'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i)
Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300
'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True
'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
Case "Admin"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
Case "WorkerB"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
End Select
Next
'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
'Remove a specific printer
'WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True
'Check group membership, and install network printers
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In the example below, P_HP5000 is a group.
Case "P_HP5000"
WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5000"
End Select
Next
'Check group membership, and assign default printer
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In the example below, P_HP5000 is a group.
Case "P_HP5000"
WSHNetwork.SetDefaultPrinter "\\Server\HP5000"
End Select
Next
' This section of script will prevent the baloon 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
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'
'==========================================================================
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\Server /set /y"
'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "F:"
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i)
Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300
'Map drives needed by all
WSHNetwork.MapNetworkDrive "U:", "\\server\users",True
WSHNetwork.MapNetworkDrive "X:", "\\server\executables",True
'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
Case "Admin"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Admin Stuff",True
Case "WorkerB"
WSHNetwork.MapNetworkDrive "w:", "\\Server\Shared Documents",True
End Select
Next
'Remove ALL old printers
'Enumerate all printers first, after that you can select the printers you want by performing some string checks
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next
'Remove a specific printer
'WSHNetwork.RemovePrinterConnection "\\ServerOld\HP5si",True,True
'Check group membership, and install network printers
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In the example below, P_HP5000 is a group.
Case "P_HP5000"
WSHNetwork.AddWindowsPrinterConnection "\\Server\HP5000"
End Select
Next
'Check group membership, and assign default printer
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
'In the example below, P_HP5000 is a group.
Case "P_HP5000"
WSHNetwork.SetDefaultPrinter "\\Server\HP5000"
End Select
Next
' This section of script will prevent the baloon 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