C # software registration code

Source: Internet
Author: User

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

Copy codeThe Code is as follows: // 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 codeCopy codeThe Code is as follows: // 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.Copy codeThe Code is as follows: // <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 ();
}
}

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.