using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Management; namespace 根据cpu序列号_磁盘序列号设计软件注册程序
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// 取得设备硬盘的卷标号
public string GetDiskVolumeSerialNumber()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"d:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
private void Form1_Load(object sender, EventArgs e)
{ }
//获得CPU的序列号
public 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;
}
//生成机器码
private void button1_Click(object sender, EventArgs e)
{
label2.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号
string[] strid = new string[];//
for (int i = ; i < ; i++)//把字符赋给数组
{
strid[i] = label2.Text.Substring(i, );
}
label2.Text = "";
Random rdid = new Random();
for (int i = ; i < ; i++)//从数组随机抽取24个字符组成新的字符生成机器三
{
label2.Text += strid[rdid.Next(, )];
}
}
public int[] intCode = new int[];//用于存密钥
public void setIntCode()//给数组赋值个小于10的随机数
{
Random ra = new Random();
for (int i = ; i < intCode.Length;i++ )
{
intCode[i] = ra.Next(, );
}
}
public int[] intNumber = new int[];//用于存机器码的Ascii值
public char[] Charcode = new char[];//存储机器码字 //生成注册码
private void button2_Click(object sender, EventArgs e)
{
if (label2.Text != "")
{
//把机器码存入数组中
setIntCode();//初始化127位数组
for (int i = ; i < Charcode.Length; i++)//把机器码存入数组中
{
Charcode[i] = Convert.ToChar(label2.Text.Substring(i - , ));
}//
for (int j = ; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
{
intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]); }
string strAsciiName = null;//用于存储机器码
for (int j = ; j < intNumber.Length; j++)
{
//MessageBox.Show((Convert.ToChar(intNumber[j])).ToString());
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();
} }
label3.Text = strAsciiName;//得到注册码 }
}
else
{ MessageBox.Show("请选生成机器码","注册提示"); }
}
//注册
private void button3_Click(object sender, EventArgs e)
{
if (label3.Text != "")
{
if (textBox1.Text.TrimEnd().Equals(label3.Text.TrimEnd()))
{ Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("ZHY").CreateSubKey("ZHY.INI").CreateSubKey(textBox1.Text.TrimEnd());
retkey.SetValue("UserName", "科技");
MessageBox.Show("注册成功");
}
else
{
MessageBox.Show("注册码输入错误"); } }
else { MessageBox.Show("请生成注册码","注册提示"); } } private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}// }
}

C# 生成机器码的更多相关文章

  1. [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析

    [WebKit内核] JavaScript引擎深度解析--基础篇(一)字节码生成及语法树的构建详情分析 标签: webkit内核JavaScriptCore 2015-03-26 23:26 2285 ...

  2. C#生成软件注册码

    开发软件时,当用到商业用途时,注册码与激活码就显得很重要了.现在的软件破解技术实在在强了,各种国内外大型软件都有注册机制,但同时也不断地被破解.下面发的只是一个常用版本,发出源码被破就更容易了,但我们 ...

  3. [WebKit内核] JavaScriptCore深度解析--基础篇(一)字节码生成及语法树的构建

    看到HorkeyChen写的文章<[WebKit] JavaScriptCore解析--基础篇(三)从脚本代码到JIT编译的代码实现>,写的很好,深受启发.想补充一些Horkey没有写到的 ...

  4. Python生成pyc文件

    Python生成pyc文件 pyc文件是py文件编译后生成的字节码文件(byte code).pyc文件经过python解释器最终会生成机器码运行.所以pyc文件是可以跨平台部署的,类似Java的.c ...

  5. 编译器开发系列--Ocelot语言1.抽象语法树

    从今天开始研究开发自己的编程语言Ocelot,从<自制编译器>出发,然后再自己不断完善功能并优化. 编译器前端简单,就不深入研究了,直接用现成的一款工具叫JavaCC,它可以生成抽象语法树 ...

  6. Java基础知识【上】(转载)

    http://blog.csdn.net/silentbalanceyh/article/details/4608272 (最终还是决定重新写一份Java基础相关的内容,原来因为在写这一个章节的时候没 ...

  7. ARM-汇编指令集(总结)

    ARM汇编指令集 指令.伪指令 (汇编)指令:   是机器码的助记符,经过汇编器编译后,由CPU执行. (汇编)伪指令:用来指导指令执行,是汇编器的产物,最终不会生成机器码. 有两种不同风格的ARM指 ...

  8. Java虚拟机(JVM)以及跨平台原理详细的介绍

    相信大家已经了解到Java具有跨平台的特性,可以"一次编译,到处运行",在Windows下编写的程序,无需任何修改就可以在Linux下运行,这是C和C++很难做到的.那么,跨平台是 ...

  9. 内网穿透神器(ngrok)服务端部署【分享一台自己的ngrok服务器】【多平台】

    Ngrok为何物 “ngrok 是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道.ngrok 可捕获和分析所有通道上的流量,便于后期分析和重放.”这是百度百科上给Ng ...

随机推荐

  1. 【Leetcode】【Easy】Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. 用 dbgrid 或 dbgrideh 如何让所显示数据自动滚动

    procedure TForm1.Timer1Timer(Sender: TObject);varm:tmessage;begin m.Msg:=WM_VSCROLL; m.WParamLo:=SB_ ...

  3. ZT 父子进程共享文件描述符

    转贴自倒霉熊的博客 [linux学习笔记-2]父子进程共享文件描述符 (2009-03-02 23:03:17) 转载▼ 标签: 学习 linux 子进程 文件描述符 杂谈 分类: 学习 #inclu ...

  4. Smart template的控件能否当成普通控件来用

    我的同事问过我这个问题: 只要弄清楚Smart control的原理,就能回答这个问题. 答案是: smart control可以像普通的控件一样在xml view中被定义和使用,但是必须结合ODat ...

  5. python入门4 python查看数据类型及类型转换

    查看数据类型:type() 类型转换:int(),float(),char(),ord(),str(),bool() #coding:utf-8 #/usr/bin/python "&quo ...

  6. OC static 和函数

    #include <stdio.h> // 定义一个one函数 // 完整地定义一个外部函数需要extern关键字 //extern void one() { // printf(&quo ...

  7. IOS 即时通讯的框架 配置环境

    一.了解XMPP 协议(标准)XMPP 即时通讯协议SGIP 短信网关协议 这手机发短信 移动支付和网页支付 0x23232[0,1] 0x23232 0x23232 0x23232 只有协议,必须会 ...

  8. Android 高级UI设计笔记09:Android实现无限滚动列表

    1. 无限滚动列表应用场景: ListView和GridView已经成为原生的Android应用实现中两个最流行的设计模式.目前,这些模式被大量的开发者使用,主要是因为他们是简单而直接的实现,同时他们 ...

  9. 使用vba doc转docx

    创建vbs文件,doctodocx.vbs内容如下: '创建一个word对象 set wApp=CreateObject("word.Application") '获取文件传递到参 ...

  10. Android学习笔记_17_Intent匹配规则(隐式意图)

    Android基本的设计理念是鼓励减少组件间的耦合,因此Android提供了Intent (意图) ,Intent提供了一种通用的消息系统,它允许在你的应用程序与其它的应用程序间传递Intent来执行 ...