Blog content

Latest posts

Active categories:

More tags ...

By date:

    (No recent posts)

Blog calendar

February 2018
Mo Tu We Th Fr Sa Su
 << Jan Mar >>
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28

Blog features

RSS feed icon RSS feed

RSS comment feed icon RSS comment feed

OS detection in a Windows shell script

posted by Martin Rubli at 07:26

There seem to be many ways to detect the Windows version (e.g. XP vs. Vista) from a batch file, some of them fairly complicated. It's not exactly as easy as it should be because there's no decent environment variable and the output of ver is difficult to parse.

However, I found the following to work just fine:

: OS detection
for /f "tokens=3" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentVersion') do (
	set WindowsVersion=%%i
if "%WindowsVersion%"=="5.1" set IsWindowsXP=1
if "%WindowsVersion%"=="6.0" set IsWindowsVista=1
: Show some debug information echo Windows version: %WindowsVersion% if defined IsWindowsXP echo IsWindowsXP = true if defined IsWindowsVista echo IsWindowsVista = true

Leave a comment

Your comment: