Batch file to find Windows Version (XP or 7)
I had a need to find which version of Windows I’d be running a script against to install a version specific app (Windows Security Essentials). My version ONLY detects XP or 7, I used a few sites that gave me the idea on how to make the batch file.
Here:
http://www.computerhope.com/if.htm
http://www.windows-commandline.com/2009/01/find-windows-os-version-from-command.html
Here’s my batch file: find_winver_xp_or_7_ver.bat
Note that I only needed to know which version XP or 7 so I didn’t care about Vista, 2000, etc and I didn’t care (at least not yet) if it’s 64 bit vs 32 bit since all the stuff I’m currently using this for is 32 bit :p (You’re NOW in luck, I did need architecture stuff and posted my batch file doing so here: Link)
Let me know if this helps you – one person on the second link said he needed to have the same script but I think he neglected to post it anywhere…what’s up with that (Music from Saturday Night Live Song Play Now – “What’s up wit dat, what’s up wit dat…”)?
I can post my longer batch file if anyone’s interested that uninstalls Windows Defender, installs Windows Security Essentials and imports some Windows Security Essentials settings.
REM Check Windows Version
ver | findstr /i “5\.0\.” > nul
IF %ERRORLEVEL% EQU 0 goto ver_2000
ver | findstr /i “5\.1\.” > nul
IF %ERRORLEVEL% EQU 0 goto ver_XP
ver | findstr /i “5\.2\.” > nul
IF %ERRORLEVEL% EQU 0 goto ver_2003
ver | findstr /i “6\.0\.” > nul
IF %ERRORLEVEL% EQU 0 goto ver_Vista
ver | findstr /i “6\.1\.” > nul
IF %ERRORLEVEL% EQU 0 goto ver_Win7
goto warn_and_exit
:ver_Win7
:Run Windows 7 specific commands here
REM echo OS Version: Windows 7 (debug line)
goto end
:ver_Vista
:Run Windows Vista specific commands here
REM echo OS Version: Windows Vista (debug line)
goto end
:ver_2003
:Run Windows Server 2003 specific commands here
REM echo OS Version: Windows Server 2003 (debug line)
goto end
:ver_XP
:Run Windows XP specific commands here
REM echo OS Version: Windows XP (debug line)
goto end
:ver_2000
:Run Windows 2000 specific commands here
REM echo OS Version: Windows 2000 (debug line)
goto end
:warn_and_exit
echo Machine OS cannot be determined.
:end