Windows
windows xp批處理 - 檢查列印機是否存在
我正在尋找一個批處理功能來檢查列印機是否已經存在於 windows xp 系統上。
我編寫了以下腳本:
set PRINTEREXISTS=0 For /F "Tokens=8 delims=\" %%I IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" ^|find /I"r016-printer01"') Do ( echo %%I set PRINTEREXISTS=1 ) if "%PRINTEREXISTS%"=="0" ( echo Printer doesn't exist ) else ( echo Printer exists )
但是,這有時會輸出列印機名稱,然後
Printer doesn't exist
即使它不應該因為PRINTEREXISTS=1
…(不是 reg 查詢的問題,而是批處理腳本)有任何想法嗎?
批處理文件?為什麼至少不是一個 vbscript。就像是:
strPrinterName ="r016-printer01" Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer where name = '" & strPrinterName & "'") If colPrinters.Count <> 0 Then wscript.echo "Printer exists" else wscript.echo "Printer doesn't exist" End If