如何判断操作系统是 Windows XP 还是更高版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2732432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell if the OS is Windows XP or higher?
提问by AngryHacker
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).
我正在尝试使用该Environment.OSVersion.Version
对象,但无法确定哪个版本会表明操作系统是 Windows XP 或更高版本(例如,我想排除 Windows 2000、ME 或以前的版本)。
回答by ParmesanCodice
Use the System.OperatingSystem
object, then filter on the Major & Minor version numbers.
使用System.OperatingSystem
对象,然后过滤主要和次要版本号。
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);
}
回答by Richard
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).
检查Major
属性是否大于或等于 5,如果 5 则Minor
至少为 1。(XP 为 5.1,2003 为 5.2,Vista/2008 为 6.0)。
回答by Stewart
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.
你不应该检查版本号。相反,您应该检查您需要的功能。如果它是您所追求的特定 API,例如 LoadLibrary 和 GetProcAddress - 这样,您就不会依赖于版本号。