C#软件注册码的实现代码
发布时间:2021-10-14 06:14:38
第一步。根据卷标,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();
}
}
猜你喜欢
- 总结java里面关于获取当前时间的一些方法System.currentTimeMillis()获取标准时间可以通过System.curren
- 一、概述平衡二叉树具有以下性质:它是一 棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树。这个方案很好的
- 本文实例讲述了java实现列表、集合与数组之间转化的方法。分享给大家供大家参考。具体实现方法如下:package test; i
- 直接用idea clean install 进行打包maven项目时,如果没有进行设置会把测试文件也打包进去。想要忽略test文件将Mave
- 二维码是什么二维码 QR Code,全称为:Quick Response Code,最早用于日本汽车制造业追踪零部件。QR现有40个标准版本
- Java Resource路径首先一点很重要,Java中不存在标准的相对路径,各种相对路径取资源的方式都是基于某种规则转化为绝
- 简单介绍 多个线程可以通过调用ManualResetEvent对象的WaitOne方法进入等
- 出处:https://www.cnblogs.com/SunSpring作为初学者配置maven一般网上搜索。然后你就看到各种配置文件片段,
- WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言间的相互调用,通过Interne
- 首先引入依赖 implementation 'com.github.bumptech.glide:glid
- 本文实例讲述了Java实现求解一元n次多项式的方法。分享给大家供大家参考,具体如下:项目需要做趋势预测,采用线性拟合、2阶曲线拟合和指数拟合
- 介绍建造者模式(Builder Pattern):将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。建造者模式是一种
- 最近在做项目的时候发现,微服务使用feign相互之间调用时,存在session丢失的问题。例如,使用Feign调用某个远程API,这个远程A
- RestTemplate设计是为了Spring更好的请求并解析Restful风格的接口返回值而设计的,通过这个类可以在请求接口时直接解析对应
- 最近碰到个需要下载zip压缩包的需求,于是我在网上找了下别人写好的zip工具类。但找了好多篇博客,总是发现有bug。因此就自己来写了个工具类
- 前言用过Spring的人多多少少也都用过@Async注解,至于作用嘛,看注解名,大概能猜出来,就是在方法执行的时候进行异步执行。一、如何使用
- Android Studio是采用gradle来构建项目的,gradle是基于groovy语言的,如果只是用它构建普通Android项目的话
- 一、获取系统当前时间long startTime = System.currentTimeMillis(); //获取开始时间doSomet
- 线程锁和条件对象在大多数多线程应用中,都是两个及以上线程需要共享对同一数据的存取,所以有可能出现两个线程同时访问同一个资源的情况,这种情况叫
- 我们都知道Android应用软件基本上都会用到登录注册功能,那么对一个一个好的登录注册模块进行封装就势在必行了。这里给大家介绍一下我的第一个