@ECHO OFF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TITLE Detect OS Version - Pre-Post Vista
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Purpose: Check for PUBLIC folder to determine OS type and execute actions.
:: Version: 1.3
:: Author: ZeusABJ
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Clear screen to hide "UNC paths not supported" error message:
CLS
:: Define Variables:
SET _OSType=Unknown
SET _OSArch=Unknown
:: Verify PUBLIC environment variable is defined:
IF DEFINED PUBLIC (
SET _OSType=Vista-2008 or later
) ELSE (
SET _OSType=XP-2003 or earlier
)
:: Verify PROGRAMFILES(X86) environment variable is defined:
IF DEFINED PROGRAMFILES(X86) (
SET _OSArch=x64
) ELSE (
SET _OSArch=x86
)
:: Display result:
ECHO You appear to be running an %_OSArch% version of Windows %_OSType%.
:: Uncomment to view script results:
ECHO.
PAUSE
EXIT
Just for grins here's an even more granular method using WMIC:
@ECHO OFF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TITLE Detect OS Version - WMIC Method
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Purpose: Determine OS version using the WMI database.
:: Version: 2.0
:: Author: ZeusABJ
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Clear screen to hide "UNC paths not supported" error message:
CLS
:: Define Variables:
SET _OSVersion=Unknown
:: Query WMI to get the OS Caption to detect OS version:
WMIC OS GET Caption | FINDSTR /c:"2000" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=2000
WMIC OS GET Caption | FINDSTR /c:"Windows XP" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=XP
WMIC OS GET Caption | FINDSTR /c:"Server 2003" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=2003
WMIC OS GET Caption | FINDSTR /c:"Vista" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=Vista
:: Note: The additional "r" after "Server" is not a typo:
WMIC OS GET Caption | FINDSTR /c:"Serverr 2008" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=2008
WMIC OS GET Caption | FINDSTR /c:"Windows 7" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=7
WMIC OS GET Caption | FINDSTR /c:"Server 2008 R2" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=2008R2
WMIC OS GET Caption | FINDSTR /c:"Windows 8" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=8
WMIC OS GET Caption | FINDSTR /c:"Server 2012" > NUL
IF %ERRORLEVEL% EQU 0 SET _OSVersion=2012
:: Display result:
IF %_OSVersion%==Unknown (
ECHO Unable to determine Windows version.
) ELSE (
ECHO You appear to be using Windows %_OSVersion%
)
:: Uncomment to view script results:
ECHO.
PAUSE
EXIT
Hope somebody finds this useful!
NP, glad you found them useful!
ReplyDelete