简体   繁体   English

批处理文件,用于确定XP Embedded上的Windows版本

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

I have an install script that needs to behave differently if running on XP/2003 or 7/R2, and it's been working perfectly fine. 我有一个安装脚本,如果在XP / 2003或7 / R2上运行,需要表现不同,并且它一直工作得非常好。 UNTIL a couple weeks ago I found out that it doesn't run on XPe (works fine on 7e), turns out find.exe is not included in XPe. 几个星期前,我发现它不能在XPe上运行(在7e上工作正常),结果发现find.exe不包含在XPe中。

My current script uses: 我当前的脚本使用:

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

I borrowed a colleagues XPe device to test a workable solution, I tried copying find.exe from XP Pro, but it still didn't work. 我借了一个同事XPe设备来测试一个可行的解决方案,我试着从XP专业版中复制find.exe,但它仍然没有用。 I tried varying versions (full path to findxp.exe, with/without .exe) of this, but it still doesn't work. 我尝试了不同的版本(findxp.exe的完整路径,有/没有.exe),但它仍然无法正常工作。 Here's the output from XPe. 这是XPe的输出。

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

All I really care to determine is if it's XP/2003, otherwise I'm assuming it's Vista (ha ha) or 2008 or newer. 所有我真正关心的是它是否是XP / 2003,否则我假设它是Vista(哈哈)或2008或更新。 Although I wouldn't object to a solution that told me if it was XPe, I guess that may or may not come in handy in the future, although it would probably make the script slighly more complicated as it would have to account for all versions of Windows. 虽然我不反对告诉我它是否是XPe的解决方案,但我想这可能会或者可能不会在将来派上用场,虽然它可能会使脚本变得更加复杂,因为它必须考虑到所有版本的Windows。

Thanks, Brian 谢谢,Brian

The code segment below is a direct replacement of your original code that don't require find.exe : 下面的代码段是直接替换不需要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

Check it out below. 请在下面查看。 Also, you can access it here: http://pastebin.com/iUtgN4ZU 此外,您可以在此处访问它: 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

Save the file as %WINDIR%\\vers.bat 将文件另存为%WINDIR%\\ vers.bat

And after that run from the command prompt: 之后从命令提示符运行:

vers

This will display which version of Windows. 这将显示哪个版本的Windows。

Try this: 尝试这个:

@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%

© Aacini at dostips © dosacpsAacini

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM