Batch:如何檢查網路共用印表機是否存在?

Batch:如何檢查網路共用印表機是否存在?

我可以檢查網路資料夾是否存在

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 參數。

萬一。

相關內容