3

I have a program where I need to display a different link to a different download based on what version of windows a user is running.

Using this answer I am able to detect which version the OS is. Also using this answer I can detect if I am running on a 32 bit or 64 bit version of the OS.

This would suit my needs perfectly, however I came across this page which states that both Windows XP 64-Bit Edition and Windows Server 2003 use the version number 5.2.

How do I detect the difference between those two OS's?


As a side note, I do need to send them to a different location if they are on 2003 64 bit or on XP 64 bit, here are the links I am needing to send people to:

Community
  • 1
  • 1
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • This will give you the string name: http://stackoverflow.com/questions/6331826/get-os-version-friendly-name-in-c-sharp – Mike Trusov Mar 19 '13 at 21:56
  • Use `OSInfo.Edition` compare. ? – Greg Mar 19 '13 at 22:02
  • 1
    @Greg Can you provide a MSDN link to OSInfo [the only one I found](http://msdn.microsoft.com/en-us/library/ms752746%28v=vs.85%29.aspx) does not have a `Edition` property. – Scott Chamberlain Mar 19 '13 at 22:13
  • http://msdn.microsoft.com/en-us/library/ms724358.aspx http://www.codeproject.com/Articles/11101/OS-Name-Version-Product-Type http://www.codeguru.com/cpp/misc/misc/system/article.php/c8973/Determine-Windows-Version-and-Edition.htm – Greg Mar 19 '13 at 22:18
  • For the two people who downvoted, why do you feel my question "Does not show research effort, is unclear, or unuseful"? – Scott Chamberlain Mar 19 '13 at 22:47

2 Answers2

5

GetVersionEx will set wProductType to VER_NT_SERVER for Windows Server 2003/2008/2008R2/2012, versus VER_NT_WORKSTATION for Windows XP/7/8.

You already know how to get whether the OS is 32-bit or 64-bit, so with a bit of P/Invoke (GetVersionEx is here), you should be able to figure out the rest.

Alternatively, if you don't want to use P/Invoke, you could use WMI, and take a look at the Win32_OperatingSystem class, which has the same information in the ProductType property. I wouldn't bother doing it this way unless you really had to.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • 1
    I am already PInvoking to figure 64 bitness (no access to Is64BitOperatingSystem) so I will include it there. I will test it out and accept if it works. – Scott Chamberlain Mar 19 '13 at 21:57
-1

Assuming you're programming in .Net:

System.Environment properties include:

  • Is64BitOperatingSystem

  • Is64BitProcess

  • OSVersion

  • ProcessorCount

  • Etc etc

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • 1
    Please re-read my question. [Enviroment.Version](http://msdn.microsoft.com/en-us/library/system.environment.version.aspx) reports the same [major and minor number](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx) for both OS's. That is the entire point my my question! Also Is64BitOperatingSystem is a .net 4.0 or newer feature. My question is tagged .net 2.0 – Scott Chamberlain Mar 19 '13 at 21:47
  • You've got lots of options, including Win32 GetVersionEx() or the .Net "Environment" property. The point is there's no one magic value: you need to use a combination of, say, "version" and "platform". Or a combination of GetVersionEx() and GetCurrentHwProfile(). Etc. – paulsm4 Mar 19 '13 at 21:52
  • Ok, then show which combination it takes to tell the diffrence between the two systems and I will remove my -1, until then your answer "Is not useful" (the alt text for a downvote) – Scott Chamberlain Mar 19 '13 at 21:56
  • My link should have been to the "Environment" class, not "Environment.Version". Sorry if I wasn't clear. One way to differentiate is "Environment.OSVersion". Another is to look at the different OSVERSIONINFO fields returned in GetVersionEx(). – paulsm4 Mar 19 '13 at 21:59
  • PS: Here's a good link for detecting 64-bit OS in C#/.Net 2.0: [how-to-detect-windows-64-bit-platform-with-net](http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net) – paulsm4 Mar 19 '13 at 22:01
  • Please note that link you gave me I linked to it in my OP showing what I already was doing. Also, I meant to link to Environment.OSVersion.Version in my first comment. As to what it returns, AS I POSTED IN MY ORIGINAL QUESTION, it returns the same value for Major and Minor for both OSes. Now if you want to include a explanation (in the answer, comments) on how to use OSVERSIONINFO like [Roger did](http://stackoverflow.com/a/15511176/80274) I will remove the -1. Until then I still feel this answer deserves a -1 as you provide no information on how to tell the difference between XP and 2003 – Scott Chamberlain Mar 19 '13 at 22:08
  • Boy, what a twit ;). Anyway: -1. I think I gave you a couple of good ideas, and we can agree Roger Lipscome also gave you a couple of good ideas (including, failing all else, WMI). Good luck! PS: Greg's "OsInfo.Edition" is yet another good suggestion. – paulsm4 Mar 19 '13 at 22:55