Table of Contents

OS - Windows - Printing

Bruce Sanderson's Windows Web - How to clean up printer drivers

Microsoft KB artikelen

A description of the user rights that a user must have to install or modify a local printer in Windows XP or Windows 2000
How to install a printer driver locally for a remote printer in Windows XP
Printerstuurprogramma's handmatig verwijderen en opnieuw installeren
Advanced troubleshooting for network printing problems in Windows XP
Advanced troubleshooting for when you cannot print in Windows XP
How to troubleshoot problems that you may experience when you try to print to a local printer by using Office programs in Windows XP

BUD file gerelateerd:
You receive an error message if you try to print a document on Windows 2000-based and Windows XP-based computers .bud files zijn bud.
You Cannot Print to a Local Printer After Windows 2000 Service Pack 2 Is Installed
Users cannot print after you install a service pack, update rollup, or printer hotfix on a server in Windows 2000 or in Windows Server 2003
You may receive an error message when you try to print a document to a network shared printer from a computer that is running Windows 2000

Printers toevoegen met AddPrinterConnection()

In VBScript met:
Syntax:

object.AddPrinterConnection(strLocalName, strRemoteName[,bUpdateProfile][,strUser][,strPassword])

object = WshNetwork object.

strLocalName = Sting value indicating the local name to assign to the connected printer.

strRemoteName = Sting value indicating the name of the remote printer.

bUpdateProfile = Optional. Boolean value indicating whether the printer mapping is stored in the current user's profile. If bUpdateProfile is supplied and is true, the mapping is stored in the user profile. The default value is false.

strUser = Optional. String value indicating the user name. If you are mapping a remote printer using the profile of someone other than current user, you can specify strUser and strPassword.

strPassword = Optional. String value indicating the user password. If you are mapping a remote printer using the profile of someone other than current user, you can specify strUser and strPassword.

Voorbeeld:

Set WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.AddPrinterConnection "LPT1", "\\Server\Print1"

Bron:MSDN - AddPrinterConnection Method

Bron:MSDN - AddWindowsPrinterConnection Method

Bron3:MS Tech Net - Microsoft® Windows® 2000 Scripting Guide - Managing Network Printers

“Instead of using AddWindowsPrinterConnection or RemoveWindowsPrinterconnection, take a look at AddPrinterconnection and RemovePrinterconnection which are better for legacy support”

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddPrinterConnection "LPT1", "\\Server\Print1"

Set WshNetwork = WScript.CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
WshNetwork.RemovePrinterConnection PrinterPath, true, true

Bron:Topic: Need help with logon script....

LET OP: Gebruik niet de FQDN van de printserver, maar de hostname!!!

Add printers with rundll32

Usage: rundll32 printui.dll,PrintUIEntry [options] [@commandfile]
   /a[file] binary file name
   /b[name] base printer name
   /c[name] unc machine name if the action is on a remote machine
   /dl delete local printer
   /dn delete network printer connection
   /dd delete printer driver
   /e display printing preferences
   /f[file] either inf file or output file
   /ga add per machine printer connections
   /ge enum per machine printer connections
   /gd delete per machine printer connections
   /h[arch] driver architecture one of the following, Alpha | Intel | IA64 | x64
   /ia install printer driver using inf file
   /id install printer driver using add printer driver wizard
   /if install printer using inf file
   /ii install printer using add printer wizard with an inf file
   /il install printer using add printer wizard
   /in add network printer connection
   /j[provider] print provider name
   /k print test page to specified printer, cannot be combined with command when installing a printer
   /l[path] printer driver source path
   /m[model] printer driver model name
   /n[name] printer name
   /o display printer queue view
   /p display printer properties
   /q quiet mode, do not display error messages
   /r[port] port name
   /s display server properties
   /Ss Store printer settings into a file
   /Sr Restore printer settings from a file
   Store or restore printer settings option flags that must be placed at the end of command:
	2	PRINTER_INFO_2
	7	PRINTER_INFO_7
	c	Color Profile
	d	PrinterData
	s	Security descriptor
	g	Global DevMode
	m	Minimal settings
	u	User DevMode
	r	Resolve name conflicts
	f	Force name
	p	Resolve port
   /u use the existing printer driver if it's already installed
   /t[#] zero based index page to start on
   /v[version] driver version one of the following, Windows 95, 98 and Me | Windows NT 4.0 | Windows NT 4.0 or 2000 | Windows 2000 or XP | Windows XP
   /w prompt the user for a driver if specified driver is not found in the inf
   /y set printer as the default
   /Xg get printer settings
   /Xs set printer settings
   /z do not auto share this printer
   /Y do not auto generate a printer name
   /K changes the meaning of /v and /h to accept 0,1,2,3, respectively for Windows x64 and Windows IA64 | Windows NT x86 | Windows NT Alpha_AXP | Windows 4.0
   /Z share this printer, can only be used with the /if option
   /? help this message
   @[file] command line argument file
   /Mw[message] show a warning message before committing the command
   /Mq[message] show a confirmation message before committing the command
   /W[flags] specifies flags and switches for the wizards (for APW & APDW)
	r	make the wizards to be restart-able from the last page
   /G[flags] specifies global flags and switches
	w	suppress setup driver warnings UI (super quiet mode)

Examples:
   Run server properties: 
rundll32 printui.dll,PrintUIEntry /s /t1 /n\\machine
   Run printer properties: 
rundll32 printui.dll,PrintUIEntry /p /n\\machine\printer
   Run add printer wizard localy: 
rundll32 printui.dll,PrintUIEntry /il 
   Run add printer wizard on \\machine: 
rundll32 printui.dll,PrintUIEntry /il /c\\machine
   Run queue view: 
rundll32 printui.dll,PrintUIEntry /o /n\\machine\printer
   Run inf install: 
rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "AGFA-AccuSet v52.3"
   Run add printer wizard using inf: 
rundll32 printui.dll,PrintUIEntry /ii /f %windir%\inf\ntprint.inf
   Add per machine printer connection: 
rundll32 printui.dll,PrintUIEntry /ga /c\\machine /n\\machine\printer /j"LanMan Print Services"
   Delete per machine printer connection: 
rundll32 printui.dll,PrintUIEntry /gd /c\\machine /n\\machine\printer
   Enumerate per machine printer connections: 
rundll32 printui.dll,PrintUIEntry /ge /c\\machine
   Add printer driver using inf: 
rundll32 printui.dll,PrintUIEntry /ia /c\\machine /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000 or XP" /f %windir%\inf\ntprint.inf
   Add printer driver using inf: 
rundll32 printui.dll,PrintUIEntry /ia /K /c\\machine /m "AGFA-AccuSet v52.3" /h "Windows NT x86" /v 3
   Remove printer driver: 
rundll32 printui.dll,PrintUIEntry /dd /c\\machine /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000 or XP"
   Remove printer driver: 
rundll32 printui.dll,PrintUIEntry /dd /K /c\\machine /m "AGFA-AccuSet v52.3" /h "Windows NT x86" /v 3
   Set printer as default: 
rundll32 printui.dll,PrintUIEntry /y /n "printer"
   Set printer comment: 
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" comment "My Cool Printer"
   Get printer settings: 
rundll32 printui.dll,PrintUIEntry /Xg /n "printer"
   Get printer settings saving results in a file: 
rundll32 printui.dll,PrintUIEntry /f "results.txt" /Xg /n "printer"
   Set printer settings command usage:
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" ?
   Store all printer settings into a file: 
rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat"
   Restore all printer settings from a file: 
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat"
   Store printer information on level 2 into a file : 
rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat" 2
   Restore  from a file printer security descriptor: 
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" s
   Restore  from a file printer global devmode and printer data: 
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" g d
   Restore  from a file minimum settings and resolve port name: 
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" m p

Sources:

Printer registry keys verwijderen

To resolve this issue, remove printers and printer drivers, and then delete the items that are under certain keys in the registry. Follow these steps:
1.	If possible, remove any printers that are listed in the Printers window.

To remove a printer, right-click the printer in the Printers window, click Delete, and then click Yes to confirm the deletion.
2.	In the Printers window, on the File menu, click Server Properties.
3.	On the Drivers tab, remove all of the installed printer drivers.

To remove a printer driver, click the driver, click Remove, and then click Yes to confirm.
4.	Start Registry Editor (Regedit.exe).
5.	Export the following registry keys:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print
6.	Delete any items that are listed under the following keys (do not delete the keys themselves):
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-2
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows NT x86\Drivers\Version-3
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Environments\Windows NT x86\Drivers\Version-2
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Environments\Windows NT x86\Drivers\Version-3
7.	Delete any non-default items that are listed under the following keys:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors
The list of Default monitors includes:

•	AppleTalk Printing Devices (When Services for Macintosh is installed)
•	BJ Language Monitor
•	Local Port
•	PJL Language Monitor
•	Standard TCP/IP Port
•	USB Monitor
•	Windows NT Fax Monitor (When a Fax Modem is installed)

For additional information about which items are not default, click the article number below to view the article in the Microsoft Knowledge Base:
260142 (http://support.microsoft.com/kb/260142/EN-US/) How to Troubleshoot Windows Printing Problems
8.	Delete any items that are listed under the following keys:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Printers
9.	Quit Registry Editor.
10.	Restart your computer, and then reinstall the necessary printers.

Bron:Error Message: Spoolsv.exe Has Generated Errors and Will Be Closed by Windows

Troubleshooting

XP Power Users can't install Printers: Solution

“Thanks for all the help on this one!!

I turned this in as a bug to Microsoft and got all kinds of response!!

Problem: After Installing SP1 on XP, the power users group cannot add printers.

Microsoft: This is by design, as part of security enhancements.

Solution: Access the local machines Local security settings. Expand Local Policies. Click on User Rights Assignment. Look for Load and unload device drivers. Double click this and choose to add a group. Click on object types and check the groups box. Say OK. Then click on Advanced, Find now. Select the power users group, or whoever you need. Bingo problem solved.

Hope this helps someone else out there!!

Thanks for all the help!

Dale”

Bron

MJMurphy (Expert):
Q: I am having a problem adding a startup script to the computer group policy on my workstations when I place the VB script in the policy it does apply but doesn’t install the printers is it possible to run the VB script in the computer group policy ?
A: Yes, the startup script can be added to the startup scripts setting of a GPO and then applied to the OU or container housing the computers you want to run the script against. The problem you're having, however, is a common GP issue, printers are associated with user accounts, Not the computer. Therefore, you want to create a separate GPO at the top GPO list with only your scripted solution configured, enable loopback processing in Merge mode and apply that policy to the computers container or OU to which it applies. The principal computer GPO should be applied when the computer starts, the user settings are applied when the user logs in, and the printer script runs after the user logs in, but the only setting changed should be the VB script.

Bron:Active Directory Week Q&A - October 1, 2004

Problemen met HP printer drivers

HP Customer Care - Microsoft Windows .BUD File Update on Server Needs Admin Rights to Recompile GPD Printer Definition Files
[THIN] Re: Bloody HP printer drivers
HP IT Resource Center - New HP drivers (print processors?) not working in XP properly. - This thread has been closed

Notes

Rename a printer from the command line

SET currentprintername=CutePDF Writer
SET newprintername=PDF Printer
"%SYSTEMROOT%\system32\cscript.exe" /nologo "%SYSTEMROOT%\System32\Printing_Admin_Scripts\en-US\prncnfg.vbs" -x -p "%currentprintername%" -z "%newprintername%"

Source: Microsoft TechNet - Prncnfg.vbs

Get a list of print jobs from Event Log

Tested on Windows Server 2008 R2.
The Microsoft-Windows-PrintService/Operational event log needs to Enabled for this. By default it is disabled.

Import-Module ActiveDirectory
 
Get-WinEvent -LogName "Microsoft-Windows-PrintService/Operational" | `
Where-Object {$_.Id -eq 307} | `
Select-Object `
TimeCreated,
@{Label="User";Expression={(Get-ADUser $_.UserId).Name}},
Message | `
Export-Csv -Path "C:\temp\PrintReport.csv" -NoTypeInformation

Get a list of printers with Name, IP, Driver, and Location

Tested on Windows Server 2016, and 2019.

Get-Printer | `
Select-Object `
Name,
@{Label="IP";Expression={(Get-PrinterPort -Name $_.PortName).PrinterHostAddress}},
DriverName,
Location | `
Sort-Object Name

Get a list of printer ports

Tested on Windows Server 2016, and 2019.

$arrPrinterPortProperties = "Name","PrinterHostAddress","PrinterHostIp","Protocol","PortNumber","SNMPCommunity","SNMPEnabled","SNMPIndex"
$objPrinterPorts = Get-Printerport
$objResult = @()
 
foreach ($objPrinterPort in $objPrinterPorts) {
 
  $objPrinterCimInstanceProperties = (Get-PrinterPort -Name $objPrinterPort.Name).CimInstanceProperties
 
  $objTemp = {} | Select-Object $arrPrinterPortProperties
 
  $objDesiredPrinterProperties = $objPrinterCimInstanceProperties | Where-Object {$arrPrinterPortProperties -contains $_.Name} | Select-Object Name,Value
 
  $objTemp.Name = $objPrinterPort.Name
  $objTemp.PrinterHostAddress = ($objDesiredPrinterProperties | Where-Object {$_.Name -match "PrinterHostAddress"}).Value
  $objTemp.PrinterHostIp = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "PrinterHostIp"}).Value
  $objTemp.Protocol = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "Protocol"}).Value
  $objTemp.PortNumber = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "PortNumber"}).Value
  $objTemp.SNMPCommunity = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "SNMPCommunity"}).Value
  $objTemp.SNMPEnabled = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "SNMPEnabled"}).Value
  $objTemp.SNMPIndex = ($objDesiredPrinterProperties | Where-Object {$_.Name -eq "SNMPIndex"}).Value
 
  if ( -Not ($objTemp.PrinterHostAddress -eq $null)) {
    $objResult += $objTemp
  }
 
}
 
$objResult | Format-Table -AutoSize