【发布时间】:2012-10-24 02:29:36
【问题描述】:
我需要使用批处理文件获取操作系统版本。我在网上看过很多例子,很多都使用了这样的代码:
@echo off
ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp
if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit
systeminfo | find "OS Name" > %TEMP%\osname.txt
FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i
echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7
echo %vers% | find "Windows Vista" > nul
if %ERRORLEVEL% == 0 goto ver_vista
goto warnthenexit
:ver_7
:Run Windows 7 specific commands here.
echo Windows 7
goto exit
:ver_vista
:Run Windows Vista specific commands here.
echo Windows Vista
goto exit
:ver_xp
:Run Windows XP specific commands here.
echo Windows XP
goto exit
:warnthenexit
echo Machine undetermined.
:exit
问题是当我在 Vista 或 Windows 7 上执行此操作时,我收到了消息
机器未确定
还有其他方法可以做我想做的事吗?
【问题讨论】:
-
我在这里要小心,任何接受升级到 Windows 10 的人都可能有旧版本号,我的机器是 windows 8.1,我升级到 10,它仍然显示 6.3注册表为“CurrentVersion”
-
systeminfo 输出取决于语言,例如在德语中是“Betriebssystemname”
标签: windows batch-file operating-system