C# Example code for obtaining computer hardware information
/// <summary> /// Get the CPU number/// </summary> /// <returns>CPU number</returns>public static List<string> GetCPUID() { List<string> lstInfo =new List<string>(); ManagementClass cimobject = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = (); foreach (ManagementObject mo in moc) { string cpuInfo = ["ProcessorId"].();//cpu serial number (cpuInfo); } return lstInfo; } /// <summary> /// Get hardware information/// </summary> /// <returns>Hardware information collection</returns>public static List<string> GetHardDiskInfo() { List<string> lstInfo = new List<string>(); ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc1 = (); foreach (ManagementObject mo in moc1) { string HDid = (string)["Model"].Value; (HDid); } return lstInfo; } /// <summary> /// Get Mac address/// </summary> /// <returns>Mac address collection</returns>public static List<string> GetMacAddress() { List<string> lstInfo = new List<string>(); ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = (); foreach (ManagementObject mo in moc) { if ((bool)mo["IPEnabled"] == true) { (mo["MacAddress"].ToString()); } (); } return lstInfo; } /// <summary> /// Get motherboard information/// </summary> /// <returns>Motherboard information collection</returns>public static List<string> GetBoard() { List<string> lstInfo = new List<string>(); ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_baseboard"); foreach (ManagementObject mo in ()) { (mo["SerialNumber"].ToString()); break; } return lstInfo; }
The above is the detailed content of the sample code for obtaining computer hardware information in C#. For more information about obtaining hardware information in C#, please pay attention to my other related articles!
Related Articles
C# operation registryKey class
This article introduces the RegistryKey class of C# operation registry, and the article introduces it in detail through sample code. It has certain reference value for everyone's study or work. Friends who need it can refer to it.2022-05-05Implementing a simple drawing tool using C#
This article mainly introduces in detail how to use the simple drawing tool developed by C#. You can export the effects of signature simple drawing in the form of pictures. If you need it, you can follow the editor to learn it.2024-02-02Open a Unity project step
This article tells how to open a Unity project, including detailed pictures and text introduction steps. I hope this article will be helpful to you.2021-06-06A brief discussion on PreviewTextInput in c# WPF
This article mainly introduces the relevant information about PreviewTextInput in C# WPF, which helps everyone better understand and learn to use C#. Interested friends can learn about it.2021-03-03C# Method to determine whether the current program is run by the administrator
This article mainly introduces the method of C# to determine whether the current program is run by the administrator. It can determine whether the current program is run by the administrator through a very simple system function call. It is a very practical technique. Friends who need it can refer to it.2014-11-11C# implements a 3-step manual construction of DataGridView
This article mainly introduces the method of C# to manually create DataGridView with 3 steps. It analyzes the principles and techniques of C# to manually create DataGridView with certain reference value. Friends who need it can refer to it.2015-09-09C# serial port communication concept and simple implementation method
This article mainly introduces you to the concept of C# serial port communication and simple implementation methods. The example code is introduced in this article in detail, which has a certain reference learning value for everyone's learning or using C#. If you need it, let's learn together.2019-03-03Detailed explanation of QR code generation factory
This article mainly shares the docking codes of 3 free QR code interfaces and the points and differences obtained from testing. It has good reference value, let's take a look at it if you need it2016-12-12How to implement specific solutions for timing push
During my work, I encountered a person who needed to push news, articles and other content to the client regularly. Small projects cannot use large frameworks. At this time, I searched online for a long time but couldn't find a suitable solution. Until I saw an article written by a big guy, I provided a very good idea. This article was inspired by him and then shared with you.2021-04-04DevExpress implements a method to obtain a RepositoryItem based on row and column indexes
This article mainly introduces the method of DevExpress to obtain RepositoryItem based on row and column index. Friends who need it can refer to it2014-08-08