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.
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!
You can just skip the check and run your deletion command anyway.
To suppress the error popup just add the /q
option as specified in the rundll32 printui.dll documentation.
this yields:
RUNDLL32 printui.dll,PrintUIEntry /n \\server\printerName /dn /q
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With