我已经搜索了很多答案,似乎找不到我要找的东西,所以如果已经回答,请原谅我。我也从来没有在这里发过帖子,如果我的格式有误,请见谅。
我正在尝试确定服务器的操作系统(2003 年或 2008 年),并根据结果运行命令。.bat 总是直接指向 ":last"。这就是我所拥有的 -
@echo off
cd\
set output="c:\osout.txt"
del %output%
set /p osinfo=Server?
wmic /node:%osinfo% os get caption > "c:\osout.txt"
findstr "2003" "c:\osout.txt"
IF %ERRORLEVEL% EQU 0 GOTO ver2003
IF %ERRORLEVEL% EQU 1 GOTO next
:next
findstr "2008" "c:\osout.txt"
IF %ERRORLEVEL% EQU 0 GOTO ver2008
IF %ERRORLEVEL% EQU 1 GOTO last
:ver2003
cd\
cls
echo ver2003
pause
:ver2008
cd\
cls
echo ver2008
pause
:last
cd\
cls
echo not 2003 or 2008
pause