替代方案:
ver|findstr "W"
因為 Windows 版本有限,
所以可用另一種方式達到您的要求,
因為是用 Windows 內建的指令或程式去達成這件事,
所以 batch 檔內容有點長:
( batch 內容引用自 http://malektips.com/xp_dos_0025.html )
<pre class="c" name="code">
@echo off
ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003
ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp
ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto ver_2000
ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto ver_nt
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 Server 2008" > nul
if %ERRORLEVEL% == 0 goto ver_2008
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_2008
:Run Windows Server 2008 specific commands here.
echo Windows Server 2008
goto exit
:ver_vista
:Run Windows Vista specific commands here.
echo Windows Vista
goto exit
:ver_2003
:Run Windows Server 2003 specific commands here.
echo Windows Server 2003
goto exit
:ver_xp
:Run Windows XP specific commands here.
echo Windows XP
goto exit
:ver_2000
:Run Windows 2000 specific commands here.
echo Windows 2000
goto exit
:ver_nt
:Run Windows NT specific commands here.
echo Windows NT
goto exit
:warnthenexit
echo Machine undetermined.
:exit
若用PowerShell的話可這麼做,可以列出很詳細的各種版本編號
Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion" | Select ProductName,ReleaseId,InstallationType,CurrentMajorVersionNumber,CurrentMinorVersionNumber,CurrentBuild,UBR
ProductName : Windows Server 2019 Standard
ReleaseId : 1809
InstallationType : Server
CurrentMajorVersionNumber : 10
CurrentMinorVersionNumber : 0
CurrentBuild : 17763
UBR : 2114