C#完成注冊碼的辦法。本站提示廣大學習愛好者:(C#完成注冊碼的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成注冊碼的辦法正文
本文實例講述了C#完成注冊碼的辦法。分享給年夜家供年夜家參考。詳細以下:
開辟軟件時,當用到貿易用處時,注冊碼與激活碼就顯得很主要了。如今的軟件破解技巧其實在強了,各類國際外年夜型軟件都有注冊機制,但同時也赓續地被破解。上面發的只是一個經常使用版本,收回源碼被破就更輕易了,但我們進修的是技巧。固然也為今後本身的軟件不會被隨意馬虎破解。
第一步。依據卷標,CPU序列號,生成機械碼
// 獲得裝備硬盤的卷標號
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();
}
//取得CPU的序列號
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;
}
//生成機械碼
public static string getMNum()
{
string strNum = getCpu() + GetDiskVolumeSerialNumber();//取得24位Cpu和硬盤序列號
string strMNum = strNum.Substring(0, 24);//從生成的字符串中掏出前24個字符做為機械碼
return strMNum;
}
public static int[] intCode = new int[127];//存儲密鑰
public static int[] intNumber = new int[25];//存機械碼的Ascii值
public static char[] Charcode = new char[25];//存儲機械碼字
public static void setIntCode()//給數組賦值小於10的數
{
for (int i = 1; i < intCode.Length; i++)
{
intCode[i] = i % 9;
}
}
第二步。依據機械碼 生成注冊碼
//生成注冊碼
public static string getRNum()
{
setIntCode();//初始化127位數組
for (int i = 1; i < Charcode.Length; i++)//把機械碼存入數組中
{
Charcode[i] = Convert.ToChar(getMNum().Substring(i - 1, 1));
}
for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一個整數組中。
{
intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);
}
string strAsciiName = "";//用於存儲注冊碼
for (int j = 1; j < intNumber.Length; j++)
{
if (intNumber[j] >= 48 && intNumber[j] <= 57)//斷定字符ASCII值能否0-9之間
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else if (intNumber[j] >= 65 && intNumber[j] <= 90)//斷定字符ASCII值能否A-Z之間
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else if (intNumber[j] >= 97 && intNumber[j] <= 122)//斷定字符ASCII值能否a-z之間
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else//斷定字符ASCII值不在以上規模內
{
if (intNumber[j] > 122)//斷定字符ASCII值能否年夜於z
{
strAsciiName += Convert.ToChar(intNumber[j] - 10).ToString();
}
else
{
strAsciiName += Convert.ToChar(intNumber[j] - 9).ToString();
}
}
}
return strAsciiName;
}
第三步。檢討注冊狀態,若沒有注冊,可自界說試用
/// <summary>
/// 檢討注冊
/// </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())//斷定能否注冊
{
if (strRNum == clsTools.getRNum())
{
thControl(true);
return;
}
}
thControl(false);
Thread th2 = new Thread(new ThreadStart(thCheckRegist2));
th2.Start();
}
}
/// <summary>
/// 驗證試用次數
/// </summary>
private static void thCheckRegist2()
{
MessageBox.Show("您如今應用的是試用版,該軟件可以避免費試用3000000次!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
Int32 tLong;
try
{
tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0);
MessageBox.Show("感激您已應用了" + tLong + "次", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0, RegistryValueKind.DWord);
MessageBox.Show("迎接新用戶應用本軟件", "提醒", 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("試用次數已到", "正告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
}
}
願望本文所述對年夜家的C#法式設計有所贊助。