1. if 那幾行的 errorlevel 不需要加 "%"。
2. 這樣寫法,若 errorlevel 不等於 0、3 或 4,那怎麼辦?
3. 重複的那幾行 errorlevel 可以收在一起。
因為你只是要區別成功失敗,亦即 0=成功;其它=失敗,故改成這樣可能比較好:
語法:
@echo off
if %os%==Windows goto 9x
if %os%==Windows_NT goto NT
:9x
REM Win95/98
echo 你的作業系統是 Windows 95/98/98SE
%windir%\system\regsvr32.exe %windir%\system\msxml4.dll /s
goto errchk
:NT
REM WinNT/2K
echo 你的作業系統是 Windows NT/2K
%windir%\system32\regsvr32.exe %windir%\system32\msxml4.dll /s
errchk:
if errorlevel==0 goto ok
goto err
:ok
echo 作業成功
goto end
:err
echo 作業失敗
echo ------
pause
:end
試試看吧。好久沒寫批次檔了,有錯還請見諒。
書籤