Board logo

標題: [分享] DOS以BAT檔指令去判斷作業系統 [打印本頁]

作者: jslin    時間: 2011-1-17 14:25     標題: DOS以BAT檔指令去判斷作業系統

DOS以BAT檔指令去判斷作業系統

if "%OS%" == "Windows_NT"
OS為Windows NT /2000/ XP
不然則為 Windows 95/98/Me


%WinDir%
C:\Windows (Windows 95/98/Me/XP)
C:\WINNT (Windows NT/2000)

----------------------------------------------------

if "%OS%" == "Windows_NT"
goto RunNT2kXP
else
goto RunWin9xMe

:RunNT2kXp
.......cmd......
goto end

:RunWin9xMe
.......cmd....
goto end

:end

----------------------------------------------------

@echo off
@rem OS.bat

@rem Windows 2000 (NT 5.0)
@rem Windows XP (NT 5.1)
@rem Windows 2003 (NT 5.2)
@rem Windows Vista/2008 (NT 6.0)
@rem Windows 7/2008 R2 (NT 6.1)

REM detect Windows NT vs. 9x
echo %OS%
if "%OS%" == "Windows_NT" goto NT
goto Unsupport

: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
)

echo MyVer = %MyVer%
echo MajorVer == %MajorVer%
echo MinorVer == %MinorVer%
echo BuildNum == %BuildNum%

if "%MajorVer%" == "5" goto NT5
if "%MajorVer%" == "6" goto NT6

:NT5

@echo NT5
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto NT5x86
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto NT5x64
goto UnSupport

:NT5x86

@echo Windows 2000/XP/2003 x86
@rem do something
goto OK

:NT5x64

@echo Windows 2000/XP/2003 x64
@rem do something
goto OK

:NT6

if "%SESSIONNAME%" == "Console" goto NoAdmin
if "%PROCESSOR_ARCHITECTURE%" == "x86" goto NT6x86
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto NT6x64
goto UnSupport

:NT6x86

@echo Windows Vista/2008/7/2008 R2 x86
@rem do something
goto OK

:NT6x64

@echo Windows Vista/2008/7/2008 R2 x64
@rem do something
goto OK

:NoAdmin

@echo Please run "Command Prompt" as Administrator !
goto exit

:UnSupport

@echo OS is not supported !
goto exit

:OK

@rem do something

:exit

pause

作者: sunland    時間: 2014-5-9 14:02

雖然是很久的資訊,實在是有用.
保留一下. 謝謝




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)