C # generate a software registration code

Source: Internet
Author: User

When developing software for commercial purposes, the registration code and activation code become very important. Today's software cracking technology is really strong, and various large domestic and foreign software has a registration mechanism, but it is also constantly cracked. The following is just a common version. It is easier to break the source code, but we are learning the technology. Of course, in the future, your software will not be easily cracked.

 

Step 1. Machine code is generated based on the volume label and CPU serial number

// Obtain the volume ID of the device's hard disk

Public static string getdiskvolumeserialnumber ()

{

Managementclass MC = new managementclass ("win32_networkadapterconfiguration ");

Managementobject disk = new managementobject ("win32_logicaldisk.deviceid =" D :"");

Disk. Get ();

Return disk. getpropertyvalue ("volumeserialnumber"). tostring ();

}

 

// Obtain the CPU serial number

Public static string getcpu ()

{

String strcpu = NULL;

Managementclass mycpu = new managementclass ("win32_processor ");

Managementobjectcollection mycpuconnection = mycpu. getinstances ();

Foreach (managementobject myobject in mycpuconnection)

{

Strcpu = myobject. properties ["processorid"]. value. tostring ();

Break;

}

Return strcpu;

}

// Generate the machine code

Public static string getmnum ()

{

String strnum = getcpu () + getdiskvolumeserialnumber (); // obtain the 24-bit CPU and hard disk serial number

String strmnum = strnum. substring (0, 24); // extract the first 24 characters from the generated string as the machine code

Return strmnum;

}

Public static int [] intcode = new int [127]; // store the key

Public static int [] intnumber = new int [25]; // ASCII value of the stored machine code

Public static char [] charcode = new char [25]; // stores machine code

Public static void setintcode () // number of values assigned to the array smaller than 10

{

For (INT I = 1; I <intcode. length; I ++)

{

Intcode [I] = I % 9;

}

}

 

Step 2. Generate a registration code based on the machine code

// Generate the registration code

 

Public static string getrnum ()

{

Setintcode (); // initialize the 127-Bit Array

For (INT I = 1; I <charcode. length; I ++) // store the machine code in the array

{

Charcode [I] = convert. tochar (getmnum (). substring (I-1, 1 ));

}

For (Int J = 1; j <intnumber. length; j ++) // Save the ASCII value of the character to an integer group.

{

Intnumber [J] = intcode [convert. toint32 (charcode [J])] + convert. toint32 (charcode [J]);

}

String strasciiname = ""; // used to store the registration code

For (Int J = 1; j <intnumber. length; j ++)

{

If (intnumber [J]> = 48 & intnumber [J] <= 57) // determines whether the ASCII value of a character is between 0-9.

{

Strasciiname + = convert. tochar (intnumber [J]). tostring ();

}

Else if (intnumber [J]> = 65 & intnumber [J] <= 90) // determines whether the ASCII value of a character is between A-Z

{

Strasciiname + = convert. tochar (intnumber [J]). tostring ();

}

Else if (intnumber [J]> = 97 & intnumber [J] <= 122) // determines whether the ASCII value of a character is a-Z.

{

Strasciiname + = convert. tochar (intnumber [J]). tostring ();

}

Else // determines that the ASCII value of a character is not in the above range

{

If (intnumber [J]> 122) // determines whether the ASCII value of a character is greater than Z.

{

Strasciiname + = convert. tochar (intnumber [J]-10). tostring ();

}

Else

{

Strasciiname + = convert. tochar (intnumber [J]-9). tostring ();

}

}

}

Return strasciiname;

}

 

Step 3. Check the registration status. If no registration is available, you can customize the trial.

 

/// <Summary>

/// Check registration

/// </Summary>

Private void checkregist ()

{

 

This. btn_reg.enabled = true;

 

Registrykey retkey = Microsoft. win32.registry. currentuser. opensubkey ("software", true). createsubkey ("wxk"). createsubkey ("wxk. ini ");

Foreach (string strrnum in retkey. getsubkeynames () // determines whether to register

{

If (strrnum = clstools. getrnum ())

{

Thcontrol (true );

Return;

}

}

Thcontrol (false );

Thread Th1 = new thread (New threadstart (thcheckregist2 ));

Th2.start ();

 

}

}

/// <Summary>

/// Verification trial times

/// </Summary>

Private Static void thcheckregist2 ()

{

MessageBox. Show ("you are using a trial version. You can try this software for 3000000 times for free !", "Prompt", messageboxbuttons. OK, messageboxicon. information );

Int32 tlong;

Try

{

Tlong = (int32) Registry. getvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", 0 );

MessageBox. Show ("Thank you for using" + tlong + "Times", "prompt", messageboxbuttons. OK, messageboxicon. information );

}

Catch

{

Registry. setvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", 0, registryvaluekind. DWORD );

MessageBox. Show ("welcome new users to use this software", "prompt", messageboxbuttons. OK, messageboxicon. information );

}

Tlong = (int32) Registry. getvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", 0 );

If (tlong <3000000)

{

Int times = tlong + 1;

Registry. setvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", times );

}

Else

{

MessageBox. Show ("trial times have arrived", "warning", messageboxbuttons. OK, messageboxicon. Warning );

Application. Exit ();

}

}

C # generate a software registration code

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.