Avatar of Steven Carnahan
Steven Carnahan
Flag for United States of America asked on

Check OS version through batch file

Looking for a batch file to determine OS and branch accordingly.

EX:

If OS = Windows 95 goto w95
if OS = Windows XP goto wxp
etc.

This should have been placed in Windows Batch.  
Shell ScriptingWindows Batch

Avatar of undefined
Last Comment
Steven Carnahan

8/22/2022 - Mon
SOLUTION
Doug Williams

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
renov8r

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Doug Williams

Or, since you are only trying to determine the difference between win95 and winxp, you could use the existing environment variable "OS" like this

goto %OS%

Windows 200 and up is set to "Windows_NT".  You will have to check to see what Windows 95 has.
ASKER CERTIFIED SOLUTION
Ben Personick (Previously QCubed)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ben Personick (Previously QCubed)

Yeahp, agreed, I very much thought we might even get something better, but thanks for the points I totally agree with the split =)
Jofnn

You can use

VER|FIND "Windows 2000" >NUL
If errorlevel 0 goto WhateverYouWantForWin2k
VER_FIND "Windows XP" >NUL
If errorlevel 0 goto WhateverYouWantForWinXP

etc etc
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jofnn

the second one was supposed to use "VER|FIND" rather than "VER_FIND"
Qlemo

Jofnn,
No you can't. VER is always resulting in "Microsoft Windows [version]". XP or 2000 or the like are not even mentioned.
Ben Personick (Previously QCubed)

Jofnn, Ver will not include the "Windows 2000" "Windows XP" (etc.) tags it will only ever include a version number.

  Some version numbers are even the same even though you or I might want them to be considered differently.

  Check my posted solution to see a full list of version numbers from Windows NT 3.1 to Windows Server 2008 R2
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ben Personick (Previously QCubed)

lol Qlemo beet me to it ^^  tnx Qlemo ^^
Jofnn

Qlemo/QCubed - the "VER" command does actually return the name as well (in Win2K Pro & WinXP Pro at least) in the following format:

Microsoft Windows xx [Version x.x.xxxx]

I use it in a few of my scripts to determine the OS so that it controls which menu the user is presented with... so I know for sure that it works... Having said that - this may be something in the PRO OS's??
Qlemo

You are correct, but that stopped with W2003. Since then, all "versions" are "Microsoft Windows".
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Steven Carnahan

ASKER
This has turned into a lively discussion now.  I have increased the overall point value to 500 but am hesitant to close it again just yet.

Jofnn:  Qlemo is correct. The results of running VER on a windows 2003 server:  
Microsoft Windows [Version 5.2.3790]

vs. running on a windows XP Pro workstation:
Microsoft Windows XP [Version 5.1.2600]

Steven Carnahan

ASKER
It seems the discussion has died down but I do appreciate everyone's input. Thank you again QCubed for the code and everyone else for confirming what QCubed and I were thinking. Since the question was for QCubed to post his code I awarded him 200 of the 500 and split the remaining 300 (100 each) between the others.

Thank you again everyone.