0

我有一个安装脚本,如果在 XP/2003 或 7/R2 上运行,它的行为需要有所不同,而且它运行得非常好。直到几周前,我发现它不能在 XPe 上运行(在 7e 上运行良好),结果 find.exe 不包含在 XPe 中。

我当前的脚本使用:

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

我借了一个同事的XPe设备来测试一个可行的解决方案,我尝试从XP Pro复制find.exe,但它仍然不起作用。我尝试了不同的版本(findxp.exe 的完整路径,带/不带 .exe),但它仍然不起作用。这是 XPe 的输出。

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

我真正关心的是确定它是否是 XP/2003,否则我假设它是 Vista(哈哈)或 2008 或更新版本。虽然我不反对告诉我它是否是 XPe 的解决方案,但我想这可能会或可能不会在未来派上用场,尽管它可能会使脚本稍微复杂一些,因为它必须考虑所有版本的窗户。

谢谢,布赖恩

4

4 回答 4

2

下面的代码段是您不需要的原始代码的直接替换find.exe

for /F "delims=" %%a in ('ver') do set ver=%%a
if "%ver:5.=%" neq "%ver%" goto WinXP
goto Win7
于 2013-05-09T01:57:41.283 回答
0
@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
于 2013-05-06T17:58:35.327 回答
0

看看下面。此外,您可以在此处访问它: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。

于 2013-05-06T17:58:43.557 回答
0

尝试这个:

@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

于 2013-05-06T18:05:11.227 回答