Printing. One of the most basic features of any computer and it still cause so many problems for so man people. Between legacy printer drivers, millions of printer brands/models as well as outdated drivers shipped with each printer sold – then no: We haven’t seen the last printer related issue yet.
That old driver
Many printer drivers from “back in the day when I bought my old printer” simply aren’t compatible with newer versions and/or 64 bit version of Windows. This can cause Windows to seemingly “loose” the connection to printers from time to time. The culprit is usually the driver, which can cause the local print Spooler or Netbios service to stall or crash completely. Now, obviously you should attempt to resolve this by removing the old printer drivers, and installing the latest compatible drivers from the manufacturers website. However sometimes that simply is not possible. I therefore decided to write a shortlist of my personal “let’s try to…” commands, in the hopes of helping someone in a similar situation.
Restarting the print spooler
Now, usually the first you one tries is restarting the Print spooler. This can easily be done from the services.msc snap-in, but I find that’s it’s a good idea to be a bit more thorough. Therefore I usually also stop the TCP/IP NetBIOS Helper service and delete any pending jobs in %windir%\System32\Spool\Printers\.
Using a batch script it can be done as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
cls @echo off set waittimer=5 echo Stopping services... net stop "Print Spooler" net stop "TCP/IP NetBIOS Helper" echo Waiting %waittimer% seconds... PING -n %waittimer% 127.0.0.1>nul echo Clearing spool cache... del /F /Q %windir%\System32\Spool\Printers\*.* echo Starting services... net start "Print Spooler" net start "TCP/IP NetBIOS Helper" pause & exit |
The batch job above should be fairly straight forward. First the two services are stopped. Then a small pause (good practice…well, I like it anyway). Then I delete everything from %windir%\System32\Spool\Printers\, which contains pending print jobs. Then I start the services again.
Uninstalling network printers from the commandline
Sometimes useful when you want to remove a specific printer from one or more machines, as this method allows both uninstalling local and network printers.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cls @echo off SET /p pserver=Hostname (ex. Server01) ? SET /p pdevice=Printername (ex. Printer01) ? echo Uninstalling %pdevice% on %pserver% rundll32 printui.dll,PrintUIEntry /dn /n \\%pserver%\%pdevice% echo Installing %pdevice% from %pserver% rundll32 printui.dll,PrintUIEntry /in /n \\%pserver%\%pdevice% pause & exit |
The command /dn defines that you want to delete the printer and /n allows you to specify the printer via it’s hostname. Same thing when installing. The /in option tells it to install and, once again, /n lets you define the printer via it’s name.
For a full list of command line options when using printUI, simply run:
1 |
rundll32 printui.dll,PrintUIEntry |
It works on most Windows versions.
Using WMIC to uninstall printers
Using the Windows Management Instrumentation Command-line / Console provides us with the cool features when uninstalling printers.
Uninstalling all Network printers
1 |
wmic printer where "Local='FALSE'" delete |
Obviously you can do the reverse as well, where you remove all local printers but non of the networked ones
1 |
wmic printer where "Local='TRUE'" delete |
One important note. Turns out that this only removes printers installed as network printer – It DOES NOT remove printers which are network printers, but are installed via a local TCP IP port. To remove these you need to specify them separately. This could be done as such:
1 |
wmic printer where "PortName LIKE 'IP_%%'" delete |
Which will remove (delete) all TCP printers using an IP.