Q:

Script to check if printer exists locally, and if so, deletes it

I'm writing a windows batch file and need to check whether the print exists on the local computer, and if so, deletes the mapped printer from the computer. Here is the code that I'm using to delete the printer.
RUNDLL32 printui.dll,PrintUIEntry /n \\server\printerName /dn

This works fine, but now I need a conditional statement before this so I check if that printer exists first. Then run that line. I'm not sure how to write this.

A:

You could try something like this, just replace the string to find with the printer you want to find.
For /F "Tokens=4 delims=\" %%I In ('reg query HKCU\Printers\Connections ^|find /I "560C"') Do If "%%I"==",,ServerName,HP DeskJet 560C" goto :REMOVE
goto :SKIP
:REMOVE
RUNDLL32 printui.dll,PrintUIEntry /n \\server\printerName /dn
:SKIP

Or just run the command and if it doesn't exist it will error, if it does it will work?
Hope this helps!

