![批处理:如何检查网络共享打印机是否存在?](https://linux22.com/image/1615184/%E6%89%B9%E5%A4%84%E7%90%86%EF%BC%9A%E5%A6%82%E4%BD%95%E6%A3%80%E6%9F%A5%E7%BD%91%E7%BB%9C%E5%85%B1%E4%BA%AB%E6%89%93%E5%8D%B0%E6%9C%BA%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%EF%BC%9F.png)
我可以检查网络文件夹是否存在
IF EXIST \\192.168.1.2\SharedFolder\ (echo It exist)
但我无法检查网络打印机是否存在。
IF EXIST \\192.168.1.2\printername (echo It exist)
答案1
下列脚本来自 Robvanderwoude.com测试打印机是否存在:
REM NOTE: RUNDLL32.exe and PRINTUI.exe always return Errorlevel=0
REM The trick: Try to get the printer settings into a file
REM If No file is created = The Printer does not exist
SET PrinterName=FIT FP-32L Raster
SET TESTfile=%TEMP%\PrtExist.txt
REM Delete %TESTfile% to avoid false positives
DEL %TESTfile% /F /Q
REM Try to get the printer settings into a file
RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Xg /n "%PrinterName%" /f "%TESTfile%" /q
IF EXIST "%TESTfile%" (
ECHO %PrinterName% printer exists
) ELSE (
ECHO %PrinterName% printer does NOT exists
)
PAUSE
答案2
我在寻找改进 deleteprinters.bat 的方法以解决这些中断我的脚本的弹出消息“未找到打印机”时发现了这个主题。
但在这种情况下,最简单的处理方法就是在 RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry 后添加 /q 参数。
万一。