C# 获取操作系统版本

+-----------------------------------------‍------------------------------------------------------------------------------------------+
|                  | Windows | Windows | Windows | Windows NT | Windows | Windows | Windows | Windows |

+-----------------------------------------‍------------------------------------------------------------------------------------------+
|                  |       95     |     98        |      Me     |       4.0          |     2000    |      XP      |     Vista    |      7      |
+-----------------------------------------------------------------------------------------------------------------------------------+
| PlatformID |      1         |      1       |        1      |          2       |       2        |      2       |                |                |
+-----------------------------------------------------------------------------------------------------------------------------------+
| 主版本号   |      4          |       4       |         4       |         4        |      5        |      5       |       6       |        6      |
+-----------------------------------------------------------------------------------------------------------------------------------+
| 副版本号 |       0         |       10      |       90      |        0        |      0         |      1       |        0       |        1      |
+-----------------------------------------------------------------------------------------------------------------------------------+

根据上面这个表,从System.Environment中的OSversion取version比较.
XP 和 2K的Major 都是5, Minor不同,2k对应0,XP对应1.

System.Environment.OSVersion.Version.Major
System.Environment.OSVersion.Version.Minor  

Version ver = System.Environment.OSVersion.Version;
            string strClient = "";
            if (ver.Major == 5 && ver.Minor == 1)
            {
                strClient = "Win XP";
            }
            else if (ver.Major == 6 && ver.Minor == 0)
            {
                strClient = "Win Vista";
            }
            else if (ver.Major == 6 && ver.Minor == 1)
            {
                strClient = "Win 7";
            }
            else if (ver.Major == 5 && ver.Minor == 0)
            {
                strClient = "Win 2000";
            }
            else
            {
                strClient = "未知";
            }
posted @ 2011-03-18 00:33  把爱延续  阅读(6592)  评论(0编辑  收藏  举报