- Publish the printers using the Group Policy Management Console (The print management console can also be used and is distributed as part of R2)
- Copy the PushPrinterConnection.exe (located on the R2 server in the PMCSnap directory under the Windows directory
- Add the PushPrinterConnection.exe to the computer start up scripts
- Use VBScript to set the default printer for the specified computer
The next step was to copy the PushPrinterConnection.exe executable to a central location (I used the domain scripts share -
\\domain\sysvol\domain\scripts). This file is used by the computer to essentially execute the RunDLL32 PrintUI.dll functionality that is available with the command line. The executable can be added to the computer start up scripts. I added the -log option so I could troubleshoot any problems with the printer installation.Because there are many printers and many computers located in different areas of the office, different computers will need different printers to be set as the default. The script to accomplish the is below and labeled "Set Default Printer".
The final problem that I ran into with adding the printers through group policy was the fact that on the surface, you can't remove the printers. The help desk staff was re-imaging the machines to get rid of the printers. I wrote a script that will do this below labeled "Remove Deployed Printers". The easiest way I could find to do this was to have a new group (maybe, "Clean Machines") and assign this script as a startup script using group policy. This way, just changing the computer's group membership to "Clean Machines" and rebooting it would remove the deployed printers upon reboot.
Note: The printers are actually added into the registry key
HKLM\SYSTEM\CurrentControlSet\Control\Print\ConnectionsThe script I wrote simply deletes this key. The printers could of course, be deleted from the registry manually.
'Set Default Printer
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
'Begin Printer installation
WScript.Sleep(35000)
Select Case WshNetWork.ComputerName
'Choose which printer to install for which computer to set as default
Case "WS-10440"
WshNetwork.SetDefaultPrinter "\\Server\PRN-224"
Case "WS-10525"
WshNetwork.SetDefaultPrinter "\\Server\PRN-224"
Case "WS-10531"
WshNetwork.SetDefaultPrinter "\\Server\PRN-225"
Case "WS-10710"
WshNetwork.SetDefaultPrinter "\\Server\PRN-224"
End Select
'Remove Deployed Printers
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPath = "SYSTEM\CurrentControlSet\Control\Print\Connections"
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath
Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
'MsgBox strKeyPath & "\" & strSubkey
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub
If this post was helpful or if you have any questions, please leave a comment and I will get back to you as soon as possible.
1 comments:
Thanks for this. I swear there are -no- printer connections at all on either Domain Server (2003R2), and yet they keep coming back on some (most) clients. Postal. Bad 50's SciFi movie...the Printers That Wouldn't Die. So I'll try this tomorrow.
I'm not a windows knowledgable type, just in the wrong place at the wrong time, so an ignorant question:
your script looks like a VB script, is that right?
1. Does the script remove printer connections that were added at both the machine and the user level? All users?
2. How do you run a VB from the GP startup? Is that the vbscript.exe [progname] ?
3. How hard would it be to modify the script to go through and just find and delete all the printers?
Thanks!
Post a Comment