小编典典

在.net中检测Windows版本

c#

如何在.net中检测Windows操作系统版本?

我可以使用什么代码?


阅读 503

收藏
2020-05-19

共1个答案

小编典典

System.Environment.OSVersion具有区分大多数Windows
OS主要版本(而非全部)所需的信息。它由三个组件组成,这些组件映射到以下Windows版本:

+------------------------------------------------------------------------------+
|                    |   PlatformID    |   Major version   |   Minor version   |
+------------------------------------------------------------------------------+
| Windows 95         |  Win32Windows   |         4         |          0        |
| Windows 98         |  Win32Windows   |         4         |         10        |
| Windows Me         |  Win32Windows   |         4         |         90        |
| Windows NT 4.0     |  Win32NT        |         4         |          0        |
| Windows 2000       |  Win32NT        |         5         |          0        |
| Windows XP         |  Win32NT        |         5         |          1        |
| Windows 2003       |  Win32NT        |         5         |          2        |
| Windows Vista      |  Win32NT        |         6         |          0        |
| Windows 2008       |  Win32NT        |         6         |          0        |
| Windows 7          |  Win32NT        |         6         |          1        |
| Windows 2008 R2    |  Win32NT        |         6         |          1        |
| Windows 8          |  Win32NT        |         6         |          2        |
| Windows 8.1        |  Win32NT        |         6         |          3        |
+------------------------------------------------------------------------------+
| Windows 10         |  Win32NT        |        10         |          0        |
+------------------------------------------------------------------------------+

要使您可以更完整地了解正在运行当前执行环境的Windows 确切
版本的,请签出该库

重要说明 :如果您的可执行程序集清单未明确声明您的exe程序集与Windows 8.1和Windows
10.0兼容,System.Environment.OSVersion则将返回Windows
8版本,即6.2,而不是6.3和10.0!资料来源:这里

2020-05-19