Determine operating system and processor type in C#

后端 未结 4 1961
谎友^
谎友^ 2021-02-05 21:03

I want to check what type of operating system i use and what kind of processor. this should be check on run time. i tried using

System.Environment.GetEnvironment         


        
4条回答
  •  春和景丽
    2021-02-05 21:47

    To determine the operating system use this code:

    string OPSystemVersion = Environment.OSVersion.ToString();
    

    To determine the CPU name and type first add System.Management reference to your project, then you can use this code:

    public static string SendBackProcessorName()
            {
                ManagementObjectSearcher mosProcessor = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
                string Procname = null;
    
                foreach (ManagementObject moProcessor in mosProcessor.Get())
                {
                    if (moProcessor["name"] != null)
                    {
                        Procname = moProcessor["name"].ToString();
    
                    }
    
                }
    
                return Procname;
            }
    

提交回复
热议问题