C#軟件注冊(cè)碼的實(shí)現(xiàn)代碼
第一步。根據(jù)卷標(biāo),CPU序列號(hào),生成機(jī)器碼
// 取得設(shè)備硬盤的卷標(biāo)號(hào)
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的序列號(hào)
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;
}
//生成機(jī)器碼
public static string getMNum()
{
string strNum = getCpu() + GetDiskVolumeSerialNumber();//獲得24位Cpu和硬盤序列號(hào)
string strMNum = strNum.Substring(0, 24);//從生成的字符串中取出前24個(gè)字符做為機(jī)器碼
return strMNum;
}
public static int[] intCode = new int[127];//存儲(chǔ)密鑰
public static int[] intNumber = new int[25];//存機(jī)器碼的Ascii值
public static char[] Charcode = new char[25];//存儲(chǔ)機(jī)器碼字
public static void setIntCode()//給數(shù)組賦值小于10的數(shù)
{
for (int i = 1; i < intCode.Length; i++)
{
intCode[i] = i % 9;
}
}
第二步。根據(jù)機(jī)器碼 生成注冊(cè)碼
//生成注冊(cè)碼
public static string getRNum()
{
setIntCode();//初始化127位數(shù)組
for (int i = 1; i < Charcode.Length; i++)//把機(jī)器碼存入數(shù)組中
{
Charcode[i] = Convert.ToChar(getMNum().Substring(i – 1, 1));
}
for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一個(gè)整數(shù)組中。
{
intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);
}
string strAsciiName = “”;//用于存儲(chǔ)注冊(cè)碼
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值不在以上范圍內(nèi)
{
if (intNumber[j] > 122)//判斷字符ASCII值是否大于z
{
strAsciiName += Convert.ToChar(intNumber[j] – 10).ToString();
}
else
{
strAsciiName += Convert.ToChar(intNumber[j] – 9).ToString();
}
}
}
return strAsciiName;
}
第三步。檢查注冊(cè)狀況,若沒(méi)有注冊(cè),可自定義試用
/// <summary>
/// 檢查注冊(cè)
/// </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())//判斷是否注冊(cè)
{
if (strRNum == clsTools.getRNum())
{
thControl(true);
return;
}
}
thControl(false);
Thread th2 = new Thread(new ThreadStart(thCheckRegist2));
th2.Start();
}
}
/// <summary>
/// 驗(yàn)證試用次數(shù)
/// </summary>
private static void thCheckRegist2()
{
MessageBox.Show(“您現(xiàn)在使用的是試用版,該軟件可以免費(fèi)試用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(“試用次數(shù)已到”, “警告”, MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
}
}
相關(guān)文章
C#身份證識(shí)別相關(guān)技術(shù)功能詳解
這篇文章主要介紹了C#身份證識(shí)別相關(guān)技術(shù)詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07C#數(shù)據(jù)結(jié)構(gòu)之順序表(SeqList)實(shí)例詳解
這篇文章主要介紹了C#數(shù)據(jù)結(jié)構(gòu)之順序表(SeqList)實(shí)現(xiàn)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了順序表的定義、原理與具體實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11深入理解C#中new、override、virtual關(guān)鍵字的區(qū)別
下面小編就為大家?guī)?lái)一篇深入理解C#中new、override、virtual關(guān)鍵字的區(qū)別。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06C#怎么實(shí)現(xiàn)手機(jī)短信發(fā)送功能
為了個(gè)人信息的安全,很多網(wǎng)站都有短信發(fā)送的功能,究竟是怎么實(shí)現(xiàn)的呢?對(duì)于個(gè)人站長(zhǎng)來(lái)說(shuō)的話,通過(guò)使用sms短信通知api接口相對(duì)比較簡(jiǎn)單,下面小編給大家介紹具體實(shí)現(xiàn)過(guò)程,對(duì)c#怎么實(shí)現(xiàn)手機(jī)短信發(fā)送功能感興趣的朋友一起學(xué)習(xí)吧2015-12-12