判斷使用者使用的作業系統

private void GetOSVersion()
{
    // Get OperatingSystem information from the system namespace.
    System.OperatingSystem osInfo = System.Environment.OSVersion;

    // Determine the platform.
    switch (osInfo.Platform)
    {
        // Platform is Windows 95, Windows 98,
        // Windows 98 Second Edition, or Windows Me.
        case System.PlatformID.Win32Windows:
            intReturn = 0;
            switch (osInfo.Version.Minor)
            {
                case 0:
                    MessageBox.Show("Windows 95");
                    break;
                case 10:
                    if (osInfo.Version.Revision.ToString() == "2222A")
                        MessageBox.Show("Windows 98 Second Edition");
                    else
                        MessageBox.Show("Windows 98");
                    break;
                case 90:
                    MessageBox.Show("Windows Me");
                    break;
                default:
                    MessageBox.Show("OtherWin32Windows");
                    break;
            }
            break;

        // Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000,
        // or Windows XP.
        case System.PlatformID.Win32NT:
            switch (osInfo.Version.Major)
            {
                case 3:
                    MessageBox.Show("Windows NT 3.51");
                    break;
                case 4:
                    MessageBox.Show("Windows NT 4.0");
                    break;
                case 5:
                    if (osInfo.Version.Minor == 0)
                        MessageBox.Show("Windows 2000");
                    else if (osInfo.Version.Minor == 1)
                        MessageBox.Show("Windows XP");
                    else if (osInfo.Version.Minor == 2)
                        MessageBox.Show("Windows 2003 Server");
                    else
                        MessageBox.Show("OtherMinor" + osInfo.Version.Minor);
                    break;
                default:
                    MessageBox.Show("OtherWin32NT");
                    break;
            }
            break;

        case System.PlatformID.MacOSX:
        case System.PlatformID.Unix:
        case System.PlatformID.Xbox:
        case System.PlatformID.Win32S:
        case System.PlatformID.WinCE:
            MessageBox.Show("Error");
            break;
    }
}

留言