iT邦幫忙

0

請問如何在批次檔中判斷作業系統

pop081 2010-02-05 17:22:2716531 瀏覽
  • 分享至 

  • twitterImage

小弟用了 %os% 結果是在xp底下顯示 windows_nt = =

用ver是可以正確顯示沒錯,但是上面會多空出一行,看起來很討厭...

請問還有別的方法嗎?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
6
蟹老闆
iT邦大師 1 級 ‧ 2010-02-05 18:30:10
最佳解答

替代方案:
ver|findstr "W"

pop081 iT邦新手 3 級 ‧ 2010-02-05 19:01:48 檢舉

這個很棒,上下都不會多一行了

不過還可以請教一個問題嗎?

如果我前面還想加一些字,要怎麼要才能正確使用echo加在同一行?

蟹老闆 iT邦大師 1 級 ‧ 2010-02-06 02:45:57 檢舉

echo 系統版本:&ver|findstr "M"
想到的只能這樣了,顯示效果會分行,如果可以不使用內建外部指令的話可以參考LMOD.COM這個功能強大的字串工具。

11
cooch
iT邦研究生 3 級 ‧ 2010-02-06 06:45:21

因為 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
0
舜~
iT邦高手 1 級 ‧ 2022-03-16 12:28:37

若用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

我要發表回答

立即登入回答