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.

 

 

9 comments:

  1. Thank you so much for the commands!!! They work perfectly.
    I don't need to restart the spooler service on Win7 before deleting the driver

    ReplyDelete
  2. This helped me out a lot. Thanks!

    ReplyDelete
  3. Sorry 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."

    I am absolutely sure that I am using the correct queue name for each device that I try to remove. Any ideas?

    ReplyDelete
    Replies
    1. 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.

      Delete
    2. We 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.
      It works with rundll32 printui.dll,PrintUIEntry /dn /n

      Delete
  4. Thanks Tex !! Well Done!!! And you were the top hit in Bing for "delete printers command line"!

    ReplyDelete
  5. Thank you, your article guided me in the right direction

    ReplyDelete
  6. Is it possible to remove all network printers shared from same print server ?

    ReplyDelete