Martin's technology blog – July 10, 2008
Blog content
Active categories:
- Vista (12)
- Office 2007 (1)
- Logitech (1)
- Darwin at work (1)
- Blog (1)
By date:
(No recent posts)
Blog calendar
| Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|
| << Jun | Aug >> | |||||
| 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 | 29 | 30 | 31 | |||
2008-07-10 | OS detection in a Windows shell script
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