We help IT Professionals succeed at work.

New podcast episode! Our very own Community Manager, Rob Jurd, gives his insight on the value of an online community. Listen Now!

x

Check OS version through batch file

3,269 Views
Last Modified: 2012-06-27
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.  
Comment
Watch Question

Doug WilliamsOfficer, Network Engineer
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Doug WilliamsOfficer, Network Engineer

Commented:
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.
Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT

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

Commented:
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

Commented:
the second one was supposed to use "VER|FIND" rather than "VER_FIND"
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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)Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT

Commented:
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
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT

Commented:
lol Qlemo beet me to it ^^  tnx Qlemo ^^

Commented:
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"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
You are correct, but that stopped with W2003. Since then, all "versions" are "Microsoft Windows".
Steven CarnahanAssistant Vice President\Network Manager
CERTIFIED EXPERT

Author

Commented:
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 CarnahanAssistant Vice President\Network Manager
CERTIFIED EXPERT

Author

Commented:
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.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.