用于检查打印机是否存在于本地的脚本,如果存在,则删除它

时间:2011-12-21 14:08:27

标签: printing batch-file

我正在编写Windows批处理文件,需要检查本地计算机上是否存在打印,如果是,则从计算机中删除映射的打印机。这是我用来删除打印机的代码。

RUNDLL32 printui.dll,PrintUIEntry /n \\server\printerName /dn

这很好用,但现在我需要一个条件语句,所以我先检查一下这台打印机是否存在。然后运行该行。我不知道怎么写这个。

2 个答案:

答案 0 :(得分:2)

您可以尝试这样的方法,只需将字符串替换为您要查找的打印机即可找到。

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

或者只是运行命令,如果它不存在则会出错,如果有,它会起作用吗?

希望这有帮助!

答案 1 :(得分:1)

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
相关问题