Determine Windows Version a batch file is running within?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jeff00seattle
Posts: 7
Joined: 06 Nov 2008 19:55

Determine Windows Version a batch file is running within?

#1 Post by jeff00seattle » 23 Feb 2010 11:35

Is there a way to determine what version a user's Windows version they are running a batch file without have to discover (I am assuming) through RegEdit?

I want to create a validation that a batch file can only be run in Vista or Windows 7.

Thanks

Jeff in Seattle

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Determine Windows Version a batch file is running within?

#2 Post by aGerman » 23 Feb 2010 13:00

This should work:

Code: Select all

@echo off &setlocal

REM if older than XP then reg.exe is unknown
if exist "%SystemRoot%\system32\reg.exe" (
  REM read the "ProductName" key
  for /f "tokens=3 delims=   " %%a in ('reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "ProductName" 2^>nul') do set "ProductName=%%a"
)

REM look for "vista" or "windows 7" (not case sensitive by using /i)
REM if found then jump to :OK label
echo.%ProductName%|findstr /i /c:"vista">nul && goto OK
echo.%ProductName%|findstr /i /c:"windows 7">nul && goto OK

REM otherwise (or if ProductName is not defined)
echo Your OS is too old.
pause
goto :eof

:OK
echo Right OS.
pause


Regards
aGerman

jeff00seattle
Posts: 7
Joined: 06 Nov 2008 19:55

Re: Determine Windows Version a batch file is running within?

#3 Post by jeff00seattle » 23 Feb 2010 14:23

Thanks,

I will give this a try.

Jeff
a Seattleite

Post Reply