How does C # programming get computer hardware information?

Source: Internet
Author: User
This article mainly introduces C # programming to obtain a variety of computer hardware information methods, combined with examples of C # to obtain the computer CPU, motherboard, hard disk, BIOS number and other information related operation skills and considerations, the need for friends can refer to the following

This paper describes the method of C # programming to obtain various computer hardware information. Share to everyone for your reference, as follows:

Get CPU Number:


ManagementClass mc = new ManagementClass ("Win32_Processor"); Managementobjectcollection MOC = MC. GetInstances (); string strid = null; foreach (ManagementObject mo in moc) {  Strid = mo. properties["Processorid"]. Value.tostring ();  break;} TextBox1.Text + = "CPU ID:" + Strid;

return Result:


Computer 1:cpu id:bfebfbff00000f27 computer 2:cpu id:bfebfbff00000f27 computer 3:cpu id:bfebfbff00000f29 computer 4:CPU ID:BFEBFBFF00000F29

Get Board Number:


ManagementClass mc = new ManagementClass ("Win32_baseboard"); Managementobjectcollection MOC = MC. GetInstances (); string strid = null; foreach (ManagementObject mo in moc) {  Strid = mo. properties["SerialNumber"]. Value.tostring ();  break;} TextBox1.Text + = "Motherboard ID:" + Strid;

return Result:


PC 1: Motherboard ID: PC 2: Motherboard id:cn24401483 PC 3: Motherboard id:azf241001101 PC 4: Motherboard ID:

Get the hard drive number:


ManagementClass mc = new ManagementClass ("Win32_physicalmedia");//online mention, with Win32_DiskDrive, but with Win32_ The drive information obtained by diskdrive does not contain the SerialNumber attribute. Managementobjectcollection MOC = MC. GetInstances (); string strid = null; foreach (ManagementObject mo in moc) {  Strid = mo. properties["SerialNumber"]. Value.tostring ();  break;} TextBox1.Text + = "hdd ID:" + Strid;

return Result:


PC 1: HDD id:4833395344463658202020202020202020202020 PC 2: Hard drive id:wd-wmajd1092385 pc 3: HDD ID : 4a353756354d5939202020202020202020202020 computer 4: Hard drive id:0637j2fw508014

Get BIOS Number:


ManagementClass mc = new ManagementClass ("Win32_BIOS"); Managementobjectcollection MOC = MC. GetInstances (); string strid = null; foreach (ManagementObject mo in moc) {  Strid = mo. properties["SerialNumber"]. Value.tostring ();  break;} TextBox1.Text + = "BIOS ID:" + Strid;

return Result:


Computer 1:bios ID: computer 2:bios id:cn24401483 computer 3:bios ID: PC 4:bios ID:

Summarize:

As seen from the above steps, obtaining the CPUID via win32_processor is incorrect, or the Win32_Processor field does not contain the CPU number information.

The motherboard information is obtained through Win32_baseboard, but not all motherboards are numbered or are not available for all system board numbers.

There should be no problem getting the hard drive number through Win32_physicalmedia. But online said can be obtained through win32_diskdrive, in fact, the information does not contain serialnumber.

The BIOS information is obtained by Win32_BIOS, which is almost the same as getting the motherboard information. That is, not all motherboard BIOS information is numbered.

In addition, you can output the information obtained from each of the fields above, and view all information attributes and corresponding values one by one. The code is as follows:


ManagementClass mc = new ManagementClass ("Win32_Processor"); Managementobjectcollection MOC = MC. GetInstances (); foreach (ManagementObject mo in moc) {TextBox1.Text + = "\r\n============cup information ==========="; foreach ( Propertydata PD in Mo. Properties) {   TextBox1.Text + = "\ r \ n" + PD. Name + "\ t";   if (PD. Value = null)   {     TextBox1.Text + = PD. Value.tostring ();   } } TextBox1.Text + = "\r\n\r\n=======================";}
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.