How to find out if a DOS batch script runs on Win 7 oder Win 10?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

How to find out if a DOS batch script runs on Win 7 oder Win 10?

#1 Post by pstein » 15 Apr 2017 02:31

How do I find out if a DOS batch script runs on Win 7 oder Win 10?

Thank you
Peter

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

Re: How to find out if a DOS batch script runs on Win 7 oder Win 10?

#2 Post by aGerman » 15 Apr 2017 04:42

You may process the output of the VER command.

Code: Select all

@echo off &setlocal
for /f "tokens=2 delims=[" %%i in ('ver') do for /f "tokens=2,3 delims=. " %%j in ("%%i") do set /a "winver=%%j * 100 + %%k"
echo "%winver%"

pause

The code multiplies the major version by 100 and adds the minor version. Thus, Win7 results in 601 while Win10 resultts in 1000.
Please see the List of Windows versions (column "Release version").
I assembled major and minor version as integer value in order to be able to easily compare it. E.g.

Code: Select all

if %winver% lss 1000 echo Previous to Win10.


Steffen

PaperTronics
Posts: 118
Joined: 02 Apr 2017 06:11

Re: How to find out if a DOS batch script runs on Win 7 oder Win 10?

#3 Post by PaperTronics » 20 Apr 2017 06:38

You can download the OS function from my website. Also be sure to read the article to find out how to use it.
Link :http://www.thebateam.org/2017/02/detect-current-operating-system-via-cmd.html#more

Post Reply