Windows 9x/Me 版本可变

Windows 9x/Me version in variable

如何将 Windows 9x/Me 版本存储到变量中?

我不知道 Windows 95、Windows 98 和 Windows Millennium 的 COMMAND.COM 是否支持将命令的输出分配给环境变量.我在机器运行 Windows 98 SE上测试绝对支持的是:

@echo off
set WinVer=unknown

rem Windows 95
ver | find "4.00.950" >nul
if not errorlevel 1 set WinVer=4.00.950

rem Windows 95 SR2
ver | find "4.00.1111" >nul
if not errorlevel 1 set WinVer=4.00.1111

rem Windows 98
ver | find "4.10.1998" >nul
if not errorlevel 1 set WinVer=4.10.1998

rem Windows 98 SE
ver | find "4.10.2222" >nul
if not errorlevel 1 set WinVer=4.10.2222

rem Windows Millennium
ver | find "4.90.3000" >nul
if not errorlevel 1 set WinVer=4.90.3000

echo Windows version is: %WinVer%

也许更适合该任务的批处理文件如下:

@echo off
ver | find "4.00." >nul
if not errorlevel 1 goto Win95
ver | find "4.10." >nul
if not errorlevel 1 goto Win98
ver | find "4.90." >nul
if not errorlevel 1 goto WinMe

echo ERROR: Could not determine Windows version!
goto EndBatch

:Win95
echo INFO: Detected OS as Windows 95.
rem More commands to run for Windows 95.
goto EndBatch

:Win98
echo INFO: Detected OS as Windows 98.
rem More commands to run for Windows 98.
goto EndBatch

:WinMe
echo INFO: Detected OS as Windows ME.
rem More commands to run for Windows ME.
goto EndBatch

rem Commands for other versions of Windows.

:EndBatch

请注意不要使用超过八个字符的标签。可以使用更长的标签名称,但对于 COMMAND.COM 只有前八个字符有意义,即 goto Windows98 将被解释为 goto Windows9 因此批处理文件将继续执行在以 Windows9.

开头的标签下方

此处使用的 Windows 版本字符串取自维基百科文章 MS-DOS