4

A few network printers have been removed from the print server and I wish to automatically remove them by a script (e.g. using objPrinter.delete_ in vbs) from any client still referencing them; preferably, I would like to really know which printers I'm deleting in those cases and automatically connect an appropriate replacement printer. This would not be difficult if I could read the list of such defunct printers in the first place.

The situation in the GUI is that the printers still show up under "Devices and printers" with the printer symbol showing only the default printer icon,being greyed out, and a yellow warning triangle shown next to it. But the printer does not get listed e.g. by the WMI query "SELECT * FROM Win32_Printer". Is there any other query that would succeed for this?

3
  • Do you know the name of the printers? Are you also looking to remove the printer driver inf/dll files along with the printer connection? I have done the reverse of this, adding printers with vbs.
    – David
    Jan 4, 2016 at 7:13
  • @David There are many of these printers but I might be able to compile a list (even a list like "if they formerly had this printer, they better get that printer"). A full cleanup may not be required. Adding printers (say, based on office floors) is of course a fine and I've done that as well, but the current task is about printers the users might have added over the years because sometimes they need a printer somewhere else, for example. I also already managed to do an "if this old printer then that new printer" replacement skript that worked if the old ones still existed - but here they don't Jan 4, 2016 at 7:20
  • Did you try to remove them from Print Management?
    – Scorpion99
    Jan 8, 2016 at 20:05

3 Answers 3

7
+25

To delete a network printer through the command-line and without GUI, is possible through updating the registry.

The following two registry keys contain installed printer definitions :

HKEY_CURRENT_USER\Printers\Connections
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Providers\LanMan Print Services\Servers\Printers

You need to find the names of the sub-keys of the above that contain the network printers you wish to delete. Once you know their names, this also becomes a method for checking if a certain printer is currently installed. Delete the sub-keys, then reboot to verify that the printer stays deleted.

There are certain important points here :

  1. The Print Spooler service may need to be stopped.
  2. The printer queue must be empty, found at the folder C:\Windows\System32\spool\PRINTERS\. You can't remove a printer if you have items in the print queue. See also the article How to Forcefully Clear the Print Queue in Windows.
  3. The GUI way to delete a printer is by running as Administrator printui /s /t2, select the printer, click Remove button, check "Remove driver and driver package" and click OK.

Some more details can be found in the article Fix for Cannot Remove or Delete Network Printer in Windows.

0

Used Revo Uninstaller to make sure everything was removed and printer continued to show up as being shared. After trying everything across the web I opened the device manager which showed the drivers still there and uninstalled those and my problem was solved.

0
-1

I was having the same issue only none of the Print Management / removal / deletion / registry deletes from HKLM\System\ControlSet001\Enum\SWD\PRINTENUM & HKLM\System\CurrentControlSet\Enum\SWD\PRINTENUM, HKEY_CURRENT_USER\Printers\Connection and HKEY_USERS.DEFAULT\Printers worked. I tried all of the following:

Empty the spooler folder: When a deleted printer keeps reappearing, it could be because there are still jobs associated with that printer are still in the spooler and can't be flushed. In Server 2012 R2 and previous versions, you'll want to check the following path: C:\WINDOWS\system32\spool\PRINTERS. There you'll see spool files with .shd and .shl extensions. Delete all of the files it contains, then restart the spooler service. Delete the driver: On rare occasions, a driver will be associated with a particular printing device and cause it to persist. In the event that a printer cannot be removed because access is denied in Server 2012 R2, try deleting the driver. This can cause a lot of problems if other clients are still using that driver, so be sure to do it during a quiet period. Reboot the server and see if the ghost printer is gone. If so, you can safely reinstall the driver. Try upgrading to a newer version if the previous one was outdated. Play the printer spooler game: Sometimes removing the printer can require a little added dexterity on your part. Some admins have reported that they have had to stop the spooler, then start it, and then immediately attempt to delete the printer via the Print Management console before the spooler has finished starting. It might take a few tries. Check for stray registry keys and redirects: If you're finding that a ghost printer cannot be removed because access is denied in Server 2012 R2, there's a chance that it is still in the registry. Lingering registry keys can prevent a printer from being deleted. To remove a printer from the registry in Windows Server 2012 R2, try scanning the registry keys and running a repair process with a software tool.

I had 42 printers, mostly 4 to 5 copies of the same printer, and no matter what I tried they would just keep coming back. In the end, in desperation just before I was about to rebuild the machine, I tried CCleaner's registry clean (there are probably better ones but had this one on hand and this has fixed the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .