-3

I need to find which windows 10 is installed via a batch file.

If it is between 1607 and RS4 build I will install x.exe if it is rs4 or higher I will not install x.exe.

So I need an if/else statement to make it work?

threshold 1 1507 10240
threshold 2 1511 10586
redstone 1 1607 14393
redstone 2 1703 15063
redstone 3 1709 16299
redstone 4 1803 17134
redstone 5 1809 17650

Maybe to check if it is between 14393 to 16299 or I could just check if it is 1607 or anything else etc.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 1
    Have you tried anything so far? Please add code that shows your working. – amanb Apr 19 '18 at 20:21
  • Possible duplicate of [Windows batch os version check with if support](https://stackoverflow.com/questions/49513153/windows-batch-os-version-check-with-if-support) – Gerhard Apr 20 '18 at 06:16

1 Answers1

0

Here's one possible way, using WMIC:

@Echo Off
Set "VN="
For /F "EOL=V Tokens=*" %%A In (
    'WMIC OS Where "Version<'4'" Get Version 2^>Nul'
) Do For /F "Tokens=3 Delims=." %%B In ("%%A") Do Set "VN=%%B"
If Not Defined VN Exit /B
If %VN% GEq 11082 If %VN% LEq 16299 Set "VN="
If Defined VN Exit /B
Rem your install code goes here.

Notes:

There were three preview releases of Threshold 1 which are not covered by my WMIC code: 6.4.9841, 6.4.9860 and 6.4.9879

The first release covered by my first 6 lines is the preview version of Threshold 1 released on January 23 2015, 10.0.9926; every other release since should work up to that point!

The following releases are covered by my answer:

  • Redstone 1 Preview Releases: 10.0.11082 December 16 2015 up to 10.0.14390 July 15 2016
  • Redstone 1 Public Releases: 10.0.14393 From July 18 2016
  • Redstone 2 Preview Releases: 10.0.14901 August 11 2016 up to 10.0.15061 March 17 2017
  • Redstone 2 Public Releases: 10.0.15063 From March 20 2017
  • Redstone 3 Preview Releases: 10.0.16170 April 7 2017 up to 10.0.16296 September 22 2017
  • Redstone 3 Public Releases: 10.0.16299 From September 26 2017

Edit

This code is added for the purposes of an additional OP requirement in the comment section.

@Echo Off
Set "VN="
For /F "EOL=V Tokens=*" %%A In (
    'WMIC OS Where "Version<'4'" Get Version 2^>Nul'
) Do For /F "Tokens=3 Delims=." %%B In ("%%A") Do Set "VN=%%B"
If Not Defined VN Exit /B
If %VN% GEq 11082 If %VN% LEq 16299 Set "VN="
If Defined VN GoTo SkipInstall
Rem your install code goes here.

Exit /B

:SkipInstall
Rem your code for Threshold or Redstone 4 goes here.
Compo
  • 36,585
  • 5
  • 27
  • 39
  • thanks for help but it iseems not working because versions are wrong and set vn is not a command – Ege Gökhan Gürkan Apr 21 '18 at 10:04
  • @EgeGökhanGürkan , when I answered your question, you had asked for up to `RedStone 3`, you've now changed it to up to `Redstone 4`, that's not my code's fault, it's yours. I've now adjusted the code to suit. As for the version numbers, I've included the preview releases in my code, your edit only uses the public releases. _(BTW, the preview release of Redstone 4 is shipping now at release 17133)_. Also despite me not having used `set vn` anywhere in my code, it is a completely valid command. Please do not change anything in my code except for the last line! – Compo Apr 21 '18 at 10:34
  • @EgeGökhanGürkan, I have found the typo related to the `Set VN=` error, I think you were referring to and updated my answer accordingly. – Compo Apr 21 '18 at 12:14
  • thank you can i change the code for if it is not between r1 and r4 then go to :seccondpart rather than exit? i dont want it to exit. i need it to continie if it is that or not. just to different ways.. – Ege Gökhan Gürkan Apr 22 '18 at 21:01
  • @EgeGökhanGürkan, I've updated my answer, adding an **Edit** section to meet your additional request. _Please mark the answer as accepted, if it has solved the question originally posted_. – Compo Apr 22 '18 at 22:02
  • thanks it is great, it is solved thanks to you! – Ege Gökhan Gürkan Apr 23 '18 at 17:30