返回列表 上一主題 發帖

[分享] DOS以BAT檔指令去判斷作業系統

[分享] 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

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

TOP

        靜思自在 : 盡多少本份,就得多少本事。
返回列表 上一主題