Link to home
Start Free TrialLog in
Avatar of Steven Carnahan
Steven CarnahanFlag 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.  
SOLUTION
Avatar of Doug Williams
Doug Williams
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeahp, agreed, I very much thought we might even get something better, but thanks for the points I totally agree with the split =)
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
the second one was supposed to use "VER|FIND" rather than "VER_FIND"
Jofnn,
No you can't. VER is always resulting in "Microsoft Windows [version]". XP or 2000 or the like are not even mentioned.
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
lol Qlemo beet me to it ^^  tnx Qlemo ^^
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??
You are correct, but that stopped with W2003. Since then, all "versions" are "Microsoft Windows".
Avatar of 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]

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.