我可以检查网络文件夹是否存在
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 参数。
万一。