在批次檔中使用錯誤等級新增網路印表機

在批次檔中使用錯誤等級新增網路印表機

我正在嘗試編寫一個腳本,以便人們只需輸入網路印表機的名稱即可新增網路印表機。

REM Adding network printer 

@echo off
:addprinter
set /p printer="Please enter the name of the printer you wish to add: "
echo.
echo Adding %printer%
echo.


REM Add printer
rundll32 printui.dll,PrintUIEntry /in /n\\printserver\%printer%
if %errorlevel% == 1 (
        echo.
        echo Printer not recognized
        echo.
goto :addprinter
)
if %errorlevel% == 0 (
        echo.
        echo Printer added
        echo.
    timeout /t 3 > nul
    goto :default
)


:default

問題是錯誤等級檢查不起作用,它們總是會傳回錯誤等級 0,即使印表機新增失敗也是如此。

這裡有人可以幫助我嗎?

答案1

這意味著

if %errorlevel% 1 (

代替

if %errorlevel% == 1 (

批次檔不是 C++ :)

相關內容