簡體   English   中英

批處理文件,用於確定XP Embedded上的Windows版本

[英]Batch file to determine Windows version on XP Embedded

我有一個安裝腳本,如果在XP / 2003或7 / R2上運行,需要表現不同,並且它一直工作得非常好。 幾個星期前,我發現它不能在XPe上運行(在7e上工作正常),結果發現find.exe不包含在XPe中。

我當前的腳本使用:

ver | find "5." > nul
if %ERRORLEVEL% == 0 goto WinXP
    goto Win7

我借了一個同事XPe設備來測試一個可行的解決方案,我試着從XP專業版中復制find.exe,但它仍然沒有用。 我嘗試了不同的版本(findxp.exe的完整路徑,有/沒有.exe),但它仍然無法正常工作。 這是XPe的輸出。

ver   | findxp.exe "5."  1>nul
The system cannot find the file specified.

所有我真正關心的是它是否是XP / 2003,否則我假設它是Vista(哈哈)或2008或更新。 雖然我不反對告訴我它是否是XPe的解決方案,但我想這可能會或者可能不會在將來派上用場,雖然它可能會使腳本變得更加復雜,因為它必須考慮到所有版本的Windows。

謝謝,Brian

下面的代碼段是直接替換不需要find.exe原始代碼:

for /F "delims=" %%a in ('ver') do set ver=%%a
if "%ver:5.=%" neq "%ver%" goto WinXP
goto Win7
@ECHO OFF
SET OSVersion=Unknown

VER | FINDSTR /L "5.0" > NUL
IF %ERRORLEVEL% EQU 0 SET OSVersion=2000

VER | FINDSTR /L "5.1." > NUL
IF %ERRORLEVEL% EQU 0 SET OSVersion=XP

VER | FINDSTR /L "5.2." > NUL
IF %ERRORLEVEL% EQU 0 SET OSVersion=2003

VER | FINDSTR /L "6.0." > NUL
IF %ERRORLEVEL% EQU 0 SET OSVersion=Vista

VER | FINDSTR /L "6.1." > NUL
IF %ERRORLEVEL% EQU 0 SET OSVersion=7

IF %OSVersion%==Unknown (
 ECHO Unable to determine your version of Windows.
) ELSE (
 ECHO You appear to be using Windows %OSVersion%
)

ECHO.
PAUSE

請在下面查看。 此外,您可以在此處訪問它: http//pastebin.com/iUtgN4ZU

    @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

將文件另存為%WINDIR%\\ vers.bat

之后從命令提示符運行:

vers

這將顯示哪個版本的Windows。

嘗試這個:

@echo off
setlocal EnableDelayedExpansion

::Identify OS
for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8) do (
   if "!Version!" equ "this" (
      set Version=Windows %%a
   ) else if "!ver: %%a=!" neq "%ver%" (
      set Version=this
   )
)

::Identify bit
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
   set Type=64 bit
) else (
   set Type=32 bit
)

::Display result
echo %Version% %Type%

© dosacpsAacini

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM