+-----------------------------------------------------------------------------------------------------------------------------------+ | | 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 = "未知";
}