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:
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 spoolerAfter that, you can remove the drivers by specifying the model of the printer (/dd = Delete Driver)
net start spooler
printui.exe /dd /m "Lexmark T642 (MS)"
Again, all these command can be execute silently by using the /q switch at the end.
Thank you so much for the commands!!! They work perfectly.
ReplyDeleteI don't need to restart the spooler service on Win7 before deleting the driver
This helped me out a lot. Thanks!
ReplyDeleteThank you!
ReplyDeleteSorry to dredge up an old thread, but I'm having a problem with this. I'm receiving the following error: "Printer connection cannot be removed. Double check the printer name and make sure that the printer is connected to the network."
ReplyDeleteI am absolutely sure that I am using the correct queue name for each device that I try to remove. Any ideas?
The only idea I would have is that you either lack the required access rights or the queue name includes characters that printui can't handle.
DeleteWe just have the same problem. The user can delete the printer with rightclick and "Remove Device". We want to remove it with printui but it gives us the same error.
DeleteIt works with rundll32 printui.dll,PrintUIEntry /dn /n
Thanks Tex !! Well Done!!! And you were the top hit in Bing for "delete printers command line"!
ReplyDeleteThank you, your article guided me in the right direction
ReplyDeleteIs it possible to remove all network printers shared from same print server ?
ReplyDelete