Tag Archives: Printer Management

How to configure and managing network printer on windows server and clients.

Network Printer Management from Command Prompt

rundll32 printui.dll,PrintUIEntry

printui.dll is an library for automated network printer management tasks with features used by the printer configuration dialog boxes. These features can also be called from a script or command-line batch file, or run interactively through the command prompt.

printui.dll runs with rundll32.exe to provide tools for demanding tasks, add printers, manage, delete, and add network printer connection.

Network Printer Management printui.dll

Open printer server properties

Printer server properties open rundll32 printui.dll,PrintUIEntry /s
Open properties of printer server

Network printer management use printui.dll Connect to the network printer:

rundll32.exe printui.dll,PrintUIEntry /in /n \\server\LaserJet

The LaserJet network printer which is shared on the SERVER, is installed on the client computer and connected to the server.

Setup printer using driver INF-file:

rundll32 printui.dll,PrintUIEntry /if /b "AddressLabel" /f C:\Driver\Zebra\ZBRN\ZBRN.inf /r "10.10.10.89" /m "ZDesigner GK420t" /Z

/if Installs printer using the specified INF-file
/b Basic printer name AddressLabel
/f Path to the printer driver INF-file
/r Portname or IP address
/m Model name of the printer driver from the INF-file
/Z Share this printer, use only with option “/if”

Delete local printer driver:

rundll32 printui.dll,PrintUIEntry /dd /m "LaserJet" /q

/dd Deletes the local printer driver
/m Model name of the printer driver
/q Do not display possible error messages

Delete network printer connection:

rundll32 printui.dll,PrintUIEntry /dn /n "LaserJet" /q

/dn Deletes the network printer connection.
/n The name of the printer.

  Help on printui.dll is get with the following command in the command prompt.

rundll32 printui.dll,PrintUIEntry /?

Network Printer Management Batch example:

Example add network printer connection using printui.dll run from Loginscript.

@echo off
@REM Batch Network printer connection
if /i %computername:~0,2%==BE goto Bern 
if /i %computername:~0,2%==BS goto Basel
if /i %computername:~0,7%==SPECTRE goto LAPTOP
goto END
:Bern
@REM Network printer connection Bern
rundll32 printui.dll,PrintUIEntry /in /n \\SERVER\LaserJet_BE
goto END
:Basel
@REM Network printer connection Basel
rundll32 printui.dll,PrintUIEntry /in /n \\SERVER\LaserJet_BS
goto END
:LAPTOP
@REM Network printer connection SPECTRE
rundll32 printui.dll,PrintUIEntry /in /n \\SERVER\OfficeJet_HO
goto END
:END

Conclusion

I hope this post can help with network printer management using the printui.dll, a library for automated Windows network printer management tasks with functions used by the printer configuration dialog boxes. These functions are also called from scripts or a command-line batch file, or run interactively from the command prompt.

Windows cannot connect to the printer

Do you Trust this Printer? Windows cannot connect to the printer. Operation 0x00000006 failed

If you try adding a network printer, the error message appears “Windows cannot connect to the printer”, then may this post can help to solve this issue.

PrintNightmare Printer Issues due to August cumulative update

Windows updates released August 10, 2021 and later will, by default, require administrative privilege to install drivers. Underlying a serious vulnerability in the Windows print spooler (CVE-2021-1678), Microsoft released a patch that was distributed through the August cumulative update. This leads to problems with printing for many users.

With the August Update, the vulnerability has been closed by requiring the installation of printer drivers via administrative rights by default. If there is a newer driver on the server than on the client, the client will attempt to update it by prompting you to enter an admin password.

In fact, the only solution is to reset the behavior back to the state it was before the August update.

Registry Changes default behavior

Microsoft provide an new registry key for this, this is the Key RestrictDriverInstallationToAdministrators with a value of 0 to allow users to install printer drivers. The key does not exist by default. Run by group policy or from script to open a command prompt as administrator and pasting as follows.

REG ADD "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows NT\Printers\PointAndPrint" /v RestrictDriverInstallationToAdministrators /t REG_DWORD /d 0 /f

  This measure removes protection against exploits of CVE-2021-1678. Microsoft therefore recommends this step only temporarily to avoid work interruptions.

  A reboot is not required when creating or changing this registry value.

Change behavior of Point and Print Restrictions to trusted servers via group policy

Specify trusted servers with the group policy Point-and-Print-Restrictions under Computer Configuration => Policies => Administrative Templates => Printer.

Restore path to printer driver in registry

Using Windows Printer Shares on a Server, it can happen when adding a network printer, it fails by the client, the reason is that the installation wizard no longer find the printer driver in the local driver store. The wizard looks for the directory path to the printer driver in the registry Key InfPath.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Drivers\Version-3\

Now that the path to the printer driver is no longer valid, the path must be searched in the registry of the server, here in this example it is the printer Sharp MX-C401 PCL6, which saves the path to the printer driver with the INF file in the Key InfPath, the path is here as follows:

C:\Windows\System32\DriverStore\FileRepository\sn0emdeu.inf_amd64_284362ba62125445\

The path is inserted in the Key InfPath as a value, which is probably empty, where the change requires admin rights, regedit.exe run as an administrator, or temporarily grant the user admin rights.

  If there is another printer on the client with the same driver, this value can be copied by InfPath, and the printer with an invalid value, or where the value is empty, can be pasted by double-clicking InfPath.

Installing printers manually

Now open the administrative share print$ to the print server on the client, where the printer drivers of the server are located.

For example, \\SERVER02\print$

Under the print$ share are the printer drivers of the installed printers on the print server. In our example at \\SERVER02\print$\x64\PCC are printer drivers for the Windows 64 bit system architecture.

Search here for the appropriate CAB archive file that has the same driver, i.e. file name, as the file in the RegistryKey InfPath,here is sn0emdeu.inf.

Unzip the compressed CAB archive file matching the printer from the print$ share with 7-Zip and copy the files to the path taken from InfPath.

Connecting and adding network printers is now possible as usual.

  Another simple solution is to add a new printer installed via printer, where by selecting LPT1 as the port, even if LPT1 does not exist, it is re-entered correctly when the path is installed in the InfPath registry key, so that the printer connection to network printers works again, the previously installed printer on LPT1 can be deleted with Device Removal.

  Note. Windows Update KB5005652, released on August 10, 2021, requires administrator privileges by default to install drivers. This change has been made the default behavior to minimize risk on all Windows devices.