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.