批处理文件:- 检测 windows 版本和 运行 exe 文件

Batch file:- Detect windows version and run exe file

我想从批处理中检测 windows 版本,并根据结果启动 exe 文件

示例代码无效

@echo off
setlocal
for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
if "%version%" geq "6.2" goto netfx_4
if "%version%" == "6.1" goto netfx_35
if "%version%" == "6.0" goto netfx_35

:netfx_35
 start "C:\Users\Ankur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.lnk"
exit 1
goto :EOF

:netfx_4
start "C:\Users\Ankur\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.lnk"
exit 1
goto :EOF

endlocal

for testing on place of exe i start notepad file

但此代码无效。

>= 是无效的比较运算符。试试geq(其他的是equneqlssleqgtr

@echo off
setlocal
for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
if "%version%" geq "6.2" goto netfx_4
if "%version%" == "6.1" goto netfx_35
if "%version%" == "6.0" goto netfx_35

:netfx_35
 start start "" name.exe
exit 1
goto :EOF

:netfx_4
start "" name.exe
exit 1
goto :EOF

endlocal

注意:- EXE 应位于批处理文件的相同位置

由于您正在寻找的版本是 OS,它使用 WMIC,我会沿着这条路走下去,(特别是 ver 的输出在技术上不是OS 版本).

@ECHO OFF

FOR /F "SKIP=1 TOKENS=1-2 DELIMS=." %%A IN ('WMIC OS GET VERSION'
) DO FOR %%C IN (%%A%%B) DO IF %%C GEQ 62 GOTO :netfx_4

:netfx_35
START "" "%AppData%\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad35.lnk"
GOTO :EOF

:netfx_4
START "" "%AppData%\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad4.lnk"
GOTO :EOF