C # operating system version detection (record ),

Source: Internet
Author: User

C # operating system version detection (record ),

We use System. Environment. OSVersion. Version to obtain the Version number of the operating System, and then determine the Version number based on the Version number.

Attribute of the Version class

 

Operating system Version number DwMajorVersion DwMinorVersion
Windows 10 10.0 10 0
Windows 8.1 6.3 6 3
Windows 8 6.2 6 2
Windows 7 6.1 6 1
Windows Server 2008 6.0 6 0
Windows Server 2003 5.2 5 2
Windows 2000 5.0 5 0

Reference: https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms724834 (v = vs.85). aspx

Note: In the official msdn documentation, the description → OSVersion attribute reports two identical versions (6.2.0.0) Windows 8 and Windows 8.1. In some cases, the OSVersion attribute may not return the OS version that matches the version of the specified Windows program compatibility mode feature.

Code:

    public class GetOSystem    {        private const string Windows2000 = "5.0";        private const string WindowsXP = "5.1";        private const string Windows2003 = "5.2";        private const string Windows2008 = "6.0";        private const string Windows7 = "6.1";        private const string Windows8OrWindows81 = "6.2";        private const string Windows10 = "10.0";        private string OSystemName;        public void setOSystemName(string oSystemName)        {            this.OSystemName = oSystemName;        }        public  GetOSystem()        {            switch (System.Environment.OSVersion.Version.Major + "." + System.Environment.OSVersion.Version.Minor)            {                case Windows2000:                    setOSystemName("Windows2000");                    break;                case WindowsXP:                    setOSystemName("WindowsXP");                    break;                case Windows2003:                    setOSystemName("Windows2003");                    break;                case Windows2008:                    setOSystemName("Windows2008");                    break;                case Windows7:                    setOSystemName("Windows7");                    break;                case Windows8OrWindows81:                    setOSystemName("Windows8.OrWindows8.1");                    break;                case Windows10:                    setOSystemName("Windows10");                    break;            }            Console.WriteLine(OSystemName);        }    }
GetOSyste
Class Program {static void Main (string [] args) {# region detection system new GetOSystem (); # endregion }}

Output result:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.