C # obtain computer hardware information (cpu id, motherboard ID, hard disk ID, and BIOS)

Source: Internet
Author: User

In the recent learning process, I thought of extracting system hardware information for some verification. Therefore, I learned and verified how to use the. NET system. Management class to obtain hardware information. Verification is performed on four computers and the XP SP3 system. The verification process is recorded here.

   Note:

Computer 1 (Lenovo brand computer );

Computer 2 (HP brand computer );

Computer 3 (Lenovo-branded computers );

Computer 4 (compatible machine );

Obtain the cpu id:
View plaincopy to clipboardprint?
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;
           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;

    Returned results:

       Computer 1: cpu id: bfebfbff00000f27

       Computer 2: cpu id: bfebfbff00000f27

       Computer 3: cpu id: bfebfbff00000f29

       Computer 4: cpu id: bfebfbff00000f29

Obtain the motherboard Number:
View plaincopy to clipboardprint?
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;
           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;

     Returned results:

       Computer 1: motherboard ID:

       Computer 2: motherboard ID: cn24401483

       Computer 3: motherboard ID: azf241001101

       Computer 4: motherboard ID:

 

Obtain the hard disk Number:
View plaincopy to clipboardprint?
Managementclass MC = new managementclass ("win32_physicalmedia "); 
// As mentioned on the internet, win32_diskdrive is used, but the hard disk information obtained using win32_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 + ="Hard Disk ID:" + Strid;
           Managementclass MC = new managementclass ("win32_physicalmedia ");
           // As mentioned on the internet, win32_diskdrive is used, but the hard disk information obtained using win32_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 + ="Hard Disk ID:" + Strid;

     Returned results:

       Computer 1: Hard Disk ID: 4833395344463658202020202020202020202020

       Computer 2: Hard Disk ID: WD-WMAJD1092385

       Computer 3: Hard Disk ID: 4a353756354d5939202020202020202020202020

       Computer 4: Hard Disk ID: 0637j2fw508014

Obtain the BIOS Number:
View plaincopy to clipboardprint?
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;
           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;

    Returned results:

       Computer 1: bios id:

       Computer 2: bios id: cn24401483

       Computer 3: bios id:

       Computer 4: bios id:

 

   Summary:

   The preceding steps show that the cpuid obtained through win32_processor is incorrect, or the win32_processor field does not contain the cpu id information.

   Use win32_baseboard to obtain information about the motherboard, but not all the boards have numbers, or not all system boards can be obtained.

   There should be no problem in obtaining the hard disk number through win32_physicalmedia. However, it can be obtained through win32_diskdrive. In fact, the obtained information does not include serialnumber.

   Obtain BIOS information through win32_bios, which is similar to obtaining information about the motherboard. That is to say, not all BIOS information on the motherboard is numbered.

   In addition, the information obtained from the preceding fields can be output to view all information attributes and corresponding values one by one. The Code is as follows:

View plaincopy to clipboardprint?
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 ========================= "; 

 

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.