(转)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 网络转载
随机推荐
- VS打包项目详细解析
使用VS打包项目,其实很多简单.微软官方文档很详尽,故不再细述,只列出相关链接 1创建安装项目 如何:创建或添加部署项目 2 添加项目输出 如何:向部署项目中添加项 3添加用户界面 部署中的用户 ...
- sublime 安装插件出现问题
一. 解决package Install不能安装 If for some reason the console installation instructions do not work for ...
- python之路---09 初始函数 参数
二十七.初始函数 1.函数: 对代码块和功能的封装和定义 2.格式及语法 def 函数名() # 定义 函数体 函数名() # 调用 3. r ...
- zabbix--3.0--2
zabbix页面注意事项 1. 工作中使用zabbix常遇到的问题:生产一台机器告警了顺手关闭了,然后忘记打开了 2.监控项这里,也尽量不禁用,而是删除.能删除就删除 3.使用触发器的过程中,有时候 ...
- 第2节 常用软件安装-JDK和Tomcat
本文转自:http://blog.sina.com.cn/s/blog_15126e2170102w5o8.html 一.JDK的安装与配置 1.从官网下载jdk,注意是jdk不是jre.最好从官网下 ...
- 我发起了一个 .Net 开源 数据库 项目 SqlNet
大家好 , 我发起了一个 .Net 开源 数据库 项目 SqlNet . 项目计划 是 用 C# 写一个 关系数据库 . 可以先参考我之前写的 2 篇文章 : 谈谈数据库原理 https://w ...
- create a simple COM object
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAArsAAAGYCAIAAADN0b3QAAAgAElEQVR4nO29749c1b2nW/4Lzh8wUr
- MySQL 中,\g和\G的作用
MySQL 中,\g和\G的作用: \g 的作用是 go (\g) Send command to mysql server. \G 的作用是将查询到的结果,每行显示一个字段和字段值,方便查看 ego ...
- TypeScript 之 模块
https://m.runoob.com/manual/gitbook/TypeScript/_book/doc/handbook/Modules.html 外部模块简写 外部模块简写:declare ...
- 在Ubuntu上使用noip动态域名的方法(ddns)
首先,注册一个noip.com的帐号. 注册的步骤见这篇教程:http://www.cnblogs.com/infopi/p/3991407.html 建立目录 第1行进入当前用户的home目录 第2 ...