如何判断操作系统是 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:22:31  来源:igfitidea点击:

How to tell if the OS is Windows XP or higher?

c#windows.net-2.0windows-xpversion

提问by AngryHacker

I am trying to play with the Environment.OSVersion.Versionobject 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.OperatingSystemobject, 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 Majorproperty is greater than or equal to 5, and if 5 then Minoris 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)。

List of Windows Version Numbers on MSDN.

MSDN 上的 Windows 版本号列表

回答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 - 这样,您就不会依赖于版本号。