Deploy Printers Using Group Policy Preferences

Deploying printer in Windows Server 2008 using grou policy preferences is pretty straightforward. The web is filled with many manuals like this one:

What seems to be a major problem is ‘remembering’ the default printer when using replace option. The default behavour of Windows is the first added printer is being set as the default.
To resolve this, i’ve created a script (with some help from a great collegue). You do need te have a roaming profile or a tool like Immidio profiles to save current use keys. Add the logon.vbs and the logoff.vbs scripts to the user policy.

Set the c:\windows\system32\cscript.exe as application with the logon.vbs as a parameter.


Option Explicit
Dim wshShell, strSavekey, strPrtName, objNetwork
'Save default printer login script written by 
'Sebastiaan van Weelden and Edward Dijk
'Ictivity 2011
' Set string values
strSaveKey = "HKCU\SOFTWARE\Ictivity\"
Set WSHShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
strPrtName = WshShell.RegRead (strSaveKey & "Printer Name")
'wscript.echo strPrtName
'Add 4 seconds delay so the printers can be added by the policy
objNetwork.SetDefaultPrinter strPrtName

'Exit script

Logoff.vbs reads the key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device and cuts it into pieces.
It creates some keys in hkey_current_user\software\ictivity.
These keys are being ‘read’ at logon and after a while (this time can be set in logon.vbs) the last used printer is set as default.


Option Explicit
Dim strKey, wshShell, strSavekey, strPrtName, strPrtSpool, strPrt
Dim strValue
'Save default printer logout script written by 
'Sebastiaan van Weelden and Edward Dijk
'Ictivity 2011
' Set string values
strSaveKey = "HKCU\SOFTWARE\Ictivity\"
strPrtName = "Printer Name"
strPrt = "Printer Port"
strPrtSpool = "Spooler"
' Create WScript Shell object to read the registry
Set wshShell = CreateObject( "WScript.Shell" )
' Read the current default printer from registry
strKey = "HKEY_CURRENT_USER\Software\Microsoft" _ 
& "\Windows NT\CurrentVersion\Windows\Device"
strValue = Split( wshShell.RegRead( strKey ), "," )
'Write Printer Name
WshShell.RegWrite "HKCU\SOFTWARE\Ictivity\" & strPrtName, strValue(0), "REG_SZ"
'Write Spooler
WshShell.RegWrite "HKCU\SOFTWARE\Ictivity\" & strPrtSpool, strValue(1), "REG_SZ"
'Write Printer Port
WshShell.RegWrite "HKCU\SOFTWARE\Ictivity\" & strPrt, strValue(2), "REG_SZ"
'Exit script

The last thing to do is changing the computer policy. Windows will refresh the policy en thereby also readd the printers. This will result in a wrong default printer.
Change the following setting in the computer policy:

Good luck!

Special thanx to my script buddy Edward Dijk


Posted on 21/03/2011, in Windows. Bookmark the permalink. Leave a comment.

Comments are closed.

%d bloggers like this: