I am trying to play with the Environment.OSVersion.Version object and can't really tell what version would indicate that the OS is Windows XP or higher (e.g. I want to exclude Windows 2000, ME or previous versions).
+6
A:
Check the Major
property is greater than or equal to 5, and if 5 then Minor
is at least 1. (XP was 5.1, 2003 was 5.2, Vista/2008 were 6.0).
Richard
2010-04-28 19:13:29
...and Windows 7 is 6.1
Esko
2010-04-28 19:15:01
Note that WinXP 32-bit is version 5.1; WinXP 64-bit is version 5.2.
William Leara
2010-04-28 19:18:54
And this is exactly why you should look for the thing you need instead of checking the version number, and why Win7 is version 6.1 and not 7.0. Checking the version number is easy to get wrong, and doesn't always tell you what you wanted to know.
Stewart
2010-04-28 19:57:55
+8
A:
Use the System.OperatingSystem
object, then just filter on the Major & Minor version numbers.
I've used these functions in the past:
static bool IsWinXPOrHigher
{
OperatingSystem OS = Environment.OSVersion;
return (OS.Platform == PlatformID.Win32NT) && ((OS.Version.Major > 5) || ((OS.Version.Major == 5) && (OS.Version.Minor >= 1)));
}
static bool IsWinVistaOrHigher
{
OperatingSystem OS = Environment.OSVersion;
return (OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6);
}
ParmesanCodice
2010-04-28 19:16:45
@AngryHacker PlatformID.Win32 = "The operating system is Windows NT or later.", so yes.
ParmesanCodice
2010-04-28 20:54:54
@ParmesanCodice, I changed the code for IsWinXp to check whether it's Windows XP or higher. Same with Vista.
AngryHacker
2010-04-28 21:42:02
+3
A:
You shouldn't check the version number. Instead, you should check for the functionality you need. If it is a specific API you're after for example, LoadLibrary and GetProcAddress it - that way, you're not dependent on the version number.
Stewart
2010-04-28 19:18:02