批处理文件: IF 和 ELSE 语句的输出在菜单脚本中被反转

批处理文件: IF 和 ELSE 语句的输出在菜单脚本中被反转

问题当 If (goto) 语句等于“Microsoft Windows 7 Professional”时,它将转到 else 语句,而不是 if 语句。当选择第一个 goto 语句时,将执行第二个 goto 语句。

for /f "skip=1 delims=" %%x in ('wmic /Node: "pc-%cn%" os get caption') do @echo.%%x
if "%%x"=="Microsoft Windows 7 Professional" (goto seven) else (goto ten)

我正在远程计算机上运行它(因此包含 /Node)。

这是整个批处理文件:

@ECHO OFF


:: +++++++++++++++++ ENTER PC +++++++++++++++++++
cls
echo.
echo PC Tasks
echo --------
echo.
set /p "cn=Enter Computer Name Extension: "


:: +++++++++++++++++++ MENU +++++++++++++++++++++
:begin
cls
echo.
echo 1) OS Build Version
echo 2) Exit
echo.
goto option

:option
set /p op=Type option #:
if "%op%"=="1" goto test
if "%op%"=="2" goto exit


:: ++++++++++++++++++++ OPTIONS ++++++++++++++++++++++

:test
:: Check for OS
for /f "skip=1 delims=" %%x in ('wmic /Node: "pc-%cn%" os get caption') do @echo.%%x
if "%%x"=="Microsoft Windows 7 Professional" (goto seven) else (goto ten) 
echo.
pause
goto option

:seven
:: Windows 7 Build Version
systeminfo /s pc-%cn% | findstr /B /C:"OS Name" /C:"OS Version"
echo.
goto option

:ten
:: Windows 10 Build Version
psexec \\pc-%cn% cmd.exe /c Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId
echo.
goto option

:exit
@exit

感谢所有能够提供帮助的人。

答案1

它似乎适用于以下语法。我删除了 Microsoft Windows 7 Professional 周围的引号。另外将 IF/ELSE 拆分为多行。

if "%%x"==Microsoft Windows 7 Professional (
goto seven
) else (
goto ten
) 

相关内容