Saturday, March 22, 2014

Deleting local or network printers as well as printer drivers from the command line

To delete printers from the command line, you can use printui.exe which is supported on Windows 7 or above.

Deleting a locally connecter printer is done by using the /dl command which stands for “Delete Local”. This command must be executed from an elevated command prompt.

  printui.exe /dl /n "NAME_OF_PRINTER"

If you wish to make the operation silent, just enter /q like this:

  printui.exe /dl /n "NAME_OF_PRINTER" /q

Managing network connected printer is also possible with printui.exe. Given there is a printer called PR-XX-03 on FS-ZZ-TU-1:

image

To remove this printer, use the command /dn for “Delete Network Printer”

  printui.exe /dn /n "\\fs-zz-tu-1\pr-xx-03”

Note: You have to use the \servername\queuename format, the name displayed within Devices and Printers is “beautified” for the user.

If you wish to remove the drivers for this printer also, you need to restart the printer spooler first. That’s because the driver files are loaded within the spooler process so they can’t be removed directly.

  net stop spooler
net start spooler
After that, you can remove the drivers by specifying the model of the printer (/dd = Delete Driver)
  printui.exe /dd /m "Lexmark T642 (MS)"

Again, all these command can be execute silently by using the /q switch at the end.