. Net to obtain machine hardware information

Source: Internet
Author: User

Recently, I helped people develop something about software registration. The other party must prevent a large number of copies and prevent general use of registration codes. So I thought of using hardware information of machines to generate registration codes, so it is involved in obtaining machine hardware information...

In the. NET environment (described in VC #), you need to use a class library (system. Management. dll) to obtain the hardware information of the machine. In Solution Explorer, add system. Management.

We canProgramCompile it into a. dll file for future calls;

In the programCodeUsing system. Management;

The Code is as follows:

1. Obtain the machine Name:

Public String gethostname ()
{
Return System. net. DNS. gethostname ();
}

2. Obtain the CPU ID

Public String getcpuid ()

{

Managementclass MC = new managementclass ("win32_processor ");
Managementobjectcollection MOC = mc. getinstances ();

String strcpuid = NULL;
Foreach (managementobject Mo in MoC)
{
Strcpuid = Mo. properties ["processorid"]. value. tostring ();
Break;
}
Return strcpuid;

}

3. Obtain the hard drive number

Public String getmainharddiskid ()

{

Managementobjectsearcher searcher = new managementobjectsearcher ("select * From win32_physicalmedia ");
String strharddiskid = NULL;
Foreach (managementobject Mo in searcher. Get ())
{
Strharddiskid = Mo ["serialnumber"]. tostring (). Trim ();
Break;
}
Return strharddiskid;

}

4. Obtain the bios and MAC address. This is complicated and requires netapi32.dll.

 

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.