사람들이 이름만 입력하여 네트워크 프린터를 추가할 수 있도록 스크립트를 작성하려고 합니다.
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++이 아닙니다 :)