Difference between revisions of "Printer configuration"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
(Added a section on removing (local) printers.)
(Lazy Way Windows 7)
Line 169: Line 169:
 
  <install cmd='"%WINDIR%\system32\spool\tools\printbrm.exe" -r -f %SOFTWARE%\Printers\%FileName% -O FORCE' />
 
  <install cmd='"%WINDIR%\system32\spool\tools\printbrm.exe" -r -f %SOFTWARE%\Printers\%FileName% -O FORCE' />
 
</source>
 
</source>
 +
 +
 +
=== NOTICE ===
 +
When exporting the .printerExport file, you can not export directly to the %software%\printers folder.  You will need to export the file to your local hard drive first, then copy it to the network share.  At least I have noticed this on my exports.  Spent half a day figuring that out.
 +
  
 
[[category:Silent Installers|Printer configuration]]
 
[[category:Silent Installers|Printer configuration]]
 
[[Category: Changing Windows settings]]
 
[[Category: Changing Windows settings]]

Revision as of 00:45, 12 August 2011

WPKG can be used for configuring printers and printer ports, too.

Adding TCP/IP printer ports

The following VBS script "addTcpipPort.vbs" adds a TCP/IP printer port, which can be then used by a printer installation:

Set args = WScript.Arguments
printerPortName = args.Item(0)
tcpipAddress    = args.Item(1)
tcpipPortNumber = args.Item(2)
Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = printerPortName
objNewPort.Protocol = 1
objNewPort.HostAddress = tcpipAddress
objNewPort.PortNumber = tcpipPortNumber
objNewPort.SNMPEnabled = False
objNewPort.Put_

Syntax:

cscript addTcpipPort.vbs <new port name> <printer address> <printer port>

Usage example, add a new printer port named "printerport1" with IP address "192.168.1.2" and port number "9100":

cscript addTcpipPort.vbs printerport1 192.168.1.2 9100


Removing Printers

Sometimes it is nice to clean out old printer entries, especially when deploying printer configurations for the first time. A hint from http://blogs.technet.com/b/heyscriptingguy/archive/2005/12/01/how-can-i-remove-all-the-local-printers-from-a-computer.aspx does the tick for you:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = FALSE")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

Adding Printers

When a new printer is configured on a server, it still has to be "installed" on a workstation.

A simple way to do it is the usage of startup scripts: executed with Administrator or SYSTEM rights - to install a printer on a workstation, and, user logon scripts, to install a printer for a user.

First, install a printer on a server and make sure it prints.

If it prints, add a line like this to /home/samba/unattended/packages/wpkg/wpkg-start.bat (the batch file where the WPKG is started):

 rundll32 printui.dll,PrintUIEntry /q /y /ga /in /n \\servername\printername

with the appropriate servername and printername. Will set installed printer as default.

This has a drawback, that it'll be used by all machines and run with user permissions. If you are adding non-domain printer to workstation in domain, make sure that point and print restrictions are disabled.

To install a printer on certain workstations only, a WPKG entry like below could be used:

<packages>
 <package id="printer" name="room 17" revision="1" priority="0" reboot="false">
 <check type="registry" condition="equals" path="HKLM\SYSTEM\CurrentControlSet\Control\Print\Connections\,,servername,printername\Server" value="\\servername" />
   <install cmd="rundll32 printui.dll,PrintUIEntry /ga /n\\servername\printername" />
   <install cmd="net stop spooler" />
   <install cmd="net start spooler" />
   <remove cmd="rundll32 printui.dll,PrintUIEntry /gd /n\\servername\printername" />
   <remove cmd="net stop spooler" />
   <remove cmd="net start spooler" />
   <upgrade cmd="rundll32 printui.dll,PrintUIEntry /ga /n\\servername\printername" />
   <upgrade cmd="net stop spooler" />
   <upgrade cmd="net start spooler" />
 </package>
</packages>

The lazy way

... or you could use printmig (pre-vista only) ... All you need to do is install the printers on one machine and export them from printmig... You will get a nice cab file this way...

<packages>
 
	<package
		id="printer"
		name="printer"
		revision="0"
		reboot="postponed"
		priority="5" 
		execute="once">
	
		<install cmd="%SOFTWARE%\printer\printmig.exe -i -r %SOFTWARE%\printer\printer.cab" />
	</package>
 
</packages>

This won't work for shared printers. ( However it works for IP printers.)

More silent printer installation options here.

Another lazy way (Vista)

For Vista, you can migrate your printers with printbrm.

- Open the Administrative Tools folder, and then click Print Management.

- In the Print Management tree, right-click the name of the computer that contains the printer queues that you want to export, and then click Export printers to a file. This starts the Printer Migration Wizard.

- On the Select the file location page, specify the location to save the printer settings, and then click Next to save the printers. For this example, it'll be "printer_labo.export". It contains a Brother HL-1470N printer.

The deployement after that is:

<package
	id="labo-printer" 
	name="Labo Printer" 
	revision="1" 
	priority="0" 
	reboot="false">

 <check type="registry" condition="equals" path="HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Brother HL-1470N\Name" value="Brother HL-1470N" />
   <install cmd="c:\windows\system32\spool\tools\printbrm.exe -r -f %SOFTWARE%\Printers\printer_labo.export -O FORCE" />
   <install cmd='rundll32 printui.dll,PrintUIEntry /y /n "Brother HL-1470N"' />
 </package>

Lazy Way Windows 7

For Windows 7, it is the pretty much the same as Vista you can migrate your printers with printbrm.

- Open the Administrative Tools folder, and then click Print Management.

- In the Print Management tree, right-click the name of the computer that contains the printer queues that you want to export, and then click Export printers to a file. This starts the Printer Migration Wizard.

- On the Select the file location page, specify the location to save the printer settings, and then click Next to save the printers.

For example our export is "BR-Prt-Smeagol.printExport". It contains a HP Color Laserjet 3800 printer named Office Color Laserjet 3800 - Smeagol.

The deployment after that is:

<package
	id="Printer Smeagol"
	name="Office Printer - Smeagol"
	revision="1.00"
	priority="0"
	reboot="false">

	<variable name="Printer" value="Office Color Laserjet 3800 - Smeagol" />
	<variable name="FileName" value="BR-Prt-Smeagol.printerExport" />
 
	<check
		type="registry"
		condition="equals"
		path="HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\%Printer%\Name"
		value="%Printer%" />
		
 <install cmd='"%WINDIR%\system32\spool\tools\printbrm.exe" -r -f %SOFTWARE%\Printers\%FileName% -O FORCE' />


NOTICE

When exporting the .printerExport file, you can not export directly to the %software%\printers folder. You will need to export the file to your local hard drive first, then copy it to the network share. At least I have noticed this on my exports. Spent half a day figuring that out.