Get computer hardware information in C #

Source: Internet
Author: User

Now I'll explain in the future how to use WMI (Windows Management instrumentation) in C # to get hardware information for your computer.

Our goal is to use the WMI API to get the following information for the computer under C #:

Number of physical processors
Number of logical processors
Number of digits
System architecture
Number of cores

Create a console application in Visual Studio, right-click the reference and select Add Reference, and then select System.Management.

Now that you have included system.management with the using statement, you can use the WMI class reference in your code.

Here is the complete code for generating hardware information.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.threading.tasks;namespace consoleapplication8{class Program {Static voidMain (string[] args) {getcpudetails (); }Private Static void getcpudetails()        {foreach(varIteminch NewSystem.Management.ManagementObjectSearcher ("SELECT * from Win32_ComputerSystem"). Get ()) {Console.WriteLine ("Number of physical processors: {0}", item["NumberOfProcessors"]); Console.WriteLine ("Number of Logical processors: {0}", item["NumberOfLogicalProcessors"]); }varNumberOfCores =0;foreach(varIteminch NewSystem.Management.ManagementObjectSearcher ("SELECT * from Win32_Processor"). Get ()) {numberofcores + =int. Parse (item["NumberOfCores"].                ToString ()); Console.WriteLine ("bitness: {0}", item["Addresswidth"]); Console.WriteLine ("Architecture: {0}", Getarchitecturedetail (int. Parse (item["Architecture"].            ToString ())); } Console.WriteLine ("Number of cores: {0}", numberofcores); }Private Static string Getarchitecturedetail(intArchitecturenumber) {Switch(Architecturenumber) { Case 0:return "x86"; Case 1:return "MIPS"; Case 2:return "Alpha"; Case 3:return "PowerPC"; Case 6:return "itanium-based Systems"; Case 9:return "x64";default:return "Unkown"; }        }    }}

Here is the output of the above program.

You can also browse through the Win32_ComputerSystem win32_processor WMI class to get more detailed information.

To make this article get treatise and ask questions, reprint please indicate the source:
Http://blog.csdn.net/nomasp

Get computer hardware information in C #

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.