您如何将 Windows 9x/Me 版本存储到变量中?
问问题
92 次
1 回答
0
我不知道COMMAND.COM
Windows 95、Windows 98 和 Windows Millennium 是否支持将命令的输出分配给环境变量。我在运行 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 版本字符串取自 Wikipedia 文章MS-DOS。
于 2020-07-29T07:45:11.583 回答