public enum WindowsVersion ... { Win95, Win98, Win98Se, WinMe, WinNT351, WinNT4, Win2000, WinXP, Win2003, Unknown,} /**/ /// <summary>/// 获取Windows版本号/// </summary>/// <remarks>/// 好像 .NET 不能在 95/NT3/NT4 上运行,加了这些版本号识别有意义吗? :-(/// </remarks> public static WindowsVersion GetWindowsVersion() ... { // +----------------------------------------------------------------------------+ // |Windows | 95 | 98 | ME | NT3.51| NT4.0 | 2000 | XP | 2003 | // +----------------------------------------------------------------------------+ // |PlatformID | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | // +----------------------------------------------------------------------------+ // |Major | 4 | 4 | 4 | 4 | 4 | 5 | 5 | 5 | // +----------------------------------------------------------------------------+ // |Minor | 0 | 10 | 90 | 0 | 0 | 1 | 2 | 3 | // +----------------------------------------------------------------------------+ OperatingSystem osInfo = Environment.OSVersion; switch (osInfo.Platform) ...{ case PlatformID.Win32Windows: ...{ switch (osInfo.Version.Minor) ...{ case 0: return WindowsVersion.Win95; case 10: if (osInfo.Version.Revision.ToString() == "2222A") return WindowsVersion.Win98Se; else return WindowsVersion.Win98; case 90: return WindowsVersion.WinMe; } break; } case PlatformID.Win32NT: ...{ switch (osInfo.Version.Major) ...{ case 3: return WindowsVersion.WinNT351; case 4: return WindowsVersion.WinNT4; case 5: ...{ switch (osInfo.Version.Minor) ...{ case 0: return WindowsVersion.Win2000; case 1: return WindowsVersion.WinXP; case 2: return WindowsVersion.Win2003; } break; } } break; } } return WindowsVersion.Unknown;} private void button2_Click( object sender, EventArgs e) ... { MessageBox.Show(GetWindowsVersion().ToString()); }