通过批量"CMD"文件识别OS系统,体系结构并执行特定任务

Vak*_*ako 3 windows command cmd batch-file

我有一个(测试)批处理文件与此代码

如果存在"C:\ Users\All Users \ntuser.dat"转到Win 7如果存在"C:\ Documents and Settings\All Users \ntuser.dat"转到Win XP

:Win 7将在这里写下将在win7上运行的参数

C:\ W7\test.txt的

:赢得XP

将在这里写下将在winxp上运行的参数

和其他os + os架构一样

它工作,但我需要添加更多的OS识别选项..我需要该批处理文件来识别操作系统版本,架构(仅限Windows 2003R2 x64,Windows Xp x32和x64,Windows Vista x32和x64,Windows 7 x32和x64,Windows 8 x32和x64)

非常感谢高级!

End*_*oro 5

Aacini在SO上有一个很好的解决方案,但现在找不到并从我的"库"发布:

@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%
goto :eof


::Goto right version
goto %Version: =_%


:Windows_8
echo Windows 8

:Windows_7
echo Windows 7
Run Code Online (Sandbox Code Playgroud)

© dosacpsAacini