(转)C#实现注册码
原文地址:http://www.cnblogs.com/netcorner/archive/2011/08/31/2911922.html
开发软件时,当用到商业用途时,注册码与激活码就显得很重要了。现在的软件破解技术实在在强了,各种国内外大型软件都有注册机制,但同时也不断地被破解。下面发的只是一个常用版本,发出源码被破就更容易了,但我们学习的是技术。当然也为以后自己的软件不会被轻易破解。 第一步。根据卷标,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(, );//从生成的字符串中取出前24个字符做为机器码
return strMNum;
}
public static int[] intCode = new int[];//存储密钥
public static int[] intNumber = new int[];//存机器码的Ascii值
public static char[] Charcode = new char[];//存储机器码字
public static void setIntCode()//给数组赋值小于10的数
{
for (int i = ; i < intCode.Length; i++)
{
intCode[i] = i % ;
}
} 第二步。根据机器码 生成注册码
//生成注册码 public static string getRNum()
{
setIntCode();//初始化127位数组
for (int i = ; i < Charcode.Length; i++)//把机器码存入数组中
{
Charcode[i] = Convert.ToChar(getMNum().Substring(i - , ));
}
for (int j = ; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
{
intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);
}
string strAsciiName = "";//用于存储注册码
for (int j = ; j < intNumber.Length; j++)
{
if (intNumber[j] >= && intNumber[j] <= )//判断字符ASCII值是否0-9之间
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else if (intNumber[j] >= && intNumber[j] <= )//判断字符ASCII值是否A-Z之间
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else if (intNumber[j] >= && intNumber[j] <= )//判断字符ASCII值是否a-z之间
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else//判断字符ASCII值不在以上范围内
{
if (intNumber[j] > )//判断字符ASCII值是否大于z
{
strAsciiName += Convert.ToChar(intNumber[j] - ).ToString();
}
else
{
strAsciiName += Convert.ToChar(intNumber[j] - ).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", );
MessageBox.Show("感谢您已使用了" + tLong + "次", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", , RegistryValueKind.DWord);
MessageBox.Show("欢迎新用户使用本软件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", );
if (tLong < )
{
int Times = tLong + ;
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", Times);
}
else
{
MessageBox.Show("试用次数已到", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Application.Exit();
}
}
(转)C#实现注册码的更多相关文章
- MyEclipse生成注册码
今天正在使用的MyEclipse出现了使用过期,在网上发现一个可以生成注册码的程序,现在分享给各位. /** * myEclipse生成注册码 * 点击顶部:MyEclipse --> subs ...
- Axure 8.0.0.3312可用注册码
用户名:aaa 注册码:2GQrt5XHYY7SBK/4b22Gm4Dh8alaR0/0k3gEN5h7FkVPIn8oG3uphlOeytIajxGU 用户名:axureuser 序列号:8wFfI ...
- 从网上找的 visual studio 的各个版本下载地址,vs2010/vs2012/vs2013带注册码
从网上找的 visual studio 的各个版本下载地址,很全,从 6.0 一直 到 vs2013,要的拿去吧... Microsoft Visual Studio 6.0 下载:英文版360云盘下 ...
- navicat注册码
1. navicat for mysql 9 注册码 ::: NAVL-EHNC-7N7P-W6GM 2. navicat for mysql 9.17中文版 注册码 :: NAVM-5ZC ...
- Axure RP 7.0注册码
Axure RP 7.0注册码 用户名:axureuser 序列号:8wFfIX7a8hHq6yAy6T8zCz5R0NBKeVxo9IKu+kgKh79FL6IyPD6lK7G6+tqEV4LG ...
- MarkdownPad 2 在win10下出错:HTML 渲染错误(This view has crashed) 的解决办法 + MarkdownPad2.5 注册码
首先附上MarkdownPad2.5的注册码. 邮箱:Soar360@live.com 授权密钥: GBPduHjWfJU1mZqcPM3BikjYKF6xKhlKIys3i1MU2eJHqWGImD ...
- MySQL 注册码
最近开发是用MySQL数据库,之前安装后,每次打开Navicat Premium 都提示 “试用一个月”,“ 注册”,然后为了方便,就都选择了 试用的, 一个月后,就必须的输入注册码,(还有一个是 什 ...
- WinRAR 4.20 beta2 key!注册文件 注册码
WinRAR 4.20 beta2 key!注册文件 注册码 WinRAR 4.20 beta2注册文件 WinRAR 4.20 beta2 working key ================= ...
- sublime3破解版sublime3注册码
Sublime Text 3 官方网址:http://www.sublimetext.com/ Mac下载地址: http://c758482.r82.cf2.rackcdn.com/Sublime% ...
- ReSharper.8.0.14.856注册码
ReSharper.8.0.14.856注册码 用户名:ronle 注册码:ZoJzmeVBoAv9Sskw76emgksMMFiLn4NM 网络转载
随机推荐
- sublime 安装插件出现问题
一. 解决package Install不能安装 If for some reason the console installation instructions do not work for ...
- 20165308 学习基础和C语言基础调查
学习基础和C语言基础调查 技能学习 我认为给学生具体的, 能实践的, 能马上看到因果关系的教材和练习, 是激发学生兴趣, 好奇心, 求知欲的好方法. -- 引用自<做中学> 老师博客中注重 ...
- Mybatis中在log日志或控制台打印执行的sql
最近在调试代码时,需要查看当前操作执行的sql,在日志里没查到,经过修改logback配置后成功,现记录如下:一.Mybatis版本是3.0.6(我正在用的版本)该版本只需要修改logback.xml ...
- tensorflow学习笔记
常量的四则运算 import tensorflow as tf data1 = tf.constant(2) data2 = tf.constant(10) dataAdd=tf.add(data1, ...
- python一些东西
assert repr() >>> a ['d', 'c', 'c', 'f', 'a', 'a', 'b', 'c', 'd'] >>> sorted(a) [' ...
- 一道Linux 面试题
一个文本文件info.txt的内容如下:aa,201zz,502bb,1ee,42每行都是按照逗号分隔,其中第二列都是数字,请对该文件按照第二列数字从大到小排列 答案:cat info.txt|awk ...
- dojo:如何显示ListBox风格的选择框
常见的选择框控件:Selelct.FilteringSelect和ComboBox都是下拉框风格,而不是ListBox风格. dojo还提供了一个dijit.form.MultiSelect控件可以解 ...
- Typescript学习总结之泛型
泛型: 参数化的类型,一般用来限制结合的内容 class Student { constructor(public name: string) { } say() { console.log(this ...
- grep 正则问题 this version of PCRE is compiled without UTF support
问题 在使用grep -P,出现如下报错: grep: this version of PCRE is compiled without UTF support 原因 有些系统支持的正则规范不同. 解 ...
- file命令详解
Linux file命令 Linux file命令用于辨识文件类型. 通过file指令,我们得以辨识该文件的类型 用法: file [-bchikLNnprsvz0] [--apple] [--mim ...