日期:2014-05-17  浏览次数:21192 次

请教在bat里面如何判断操作系统
要实现在一个bat里面判断windows操作系统类型,然后执行相应的一些程序。
谢谢!

------解决方案--------------------
可以利用%os% 和 ver 命令的输出
如:

REM BEGIN
REM
REM Figure out what operating system we 're running on before doing anything.
REM If running on Win9x, NT 4.0 or lower, throw error and exit.
REM detect Windows NT vs. 9x
if (%OS%)==(Windows_NT) goto NT
goto Unsupported

:NT
REM determine build of NT (if necessary)
for /f "delims=[] tokens=2 " %%i in ( 'ver ') do set MyVer=%%i
for /f "tokens=2 " %%i in ( 'echo %MyVer% ') do set MyVer=%%i
for /f "tokens=1,2,3 delims=. " %%i in ( 'echo %MyVer% ') do (
set MajorVer=%%i
set MinorVer=%%j
set BuildNum=%%k
)
set MyVer=
REM echo MajorVer == %MajorVer%
REM echo MinorVer == %MinorVer%
REM echo BuildNum == %BuildNum%
REM Check if they are running on NT 4.0, the code above returns 'is ' on NT 4.0
IF /I %MajorVer%==is GOTO Unsupported


IF /I '%1 '== ' ' GOTO GetChoice
SET Choice=%1
GOTO CreateIPSecPolicy
------解决方案--------------------
@echo off
rem 查看操作系统的具体名称
cd c:\
systeminfo > c:\test1.txt
cls
for /f "skip=1 tokens=1,2,* delims= " %%a in ( 'findstr "OS Name " c:\test1.txt ') do (
echo %%c
goto p
)

:p
echo ok
del c:\test1.txt