机器码


[c-sharp]
  view plain copy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. //  
  9. using System.Management;//引用Net system.management.dll  
  10.   
  11. namespace WFrom  
  12. {  
  13.     public partial class Form3 : Form  
  14.     {  
  15.         public int[] intCode = new int[127];//用于存密钥  
  16.         public int[] intNumber = new int[25];//用于存机器码的Ascii值  
  17.         public char[] Charcode = new char[25];//存储机器码字  
  18.   
  19.         public Form3()  
  20.         {  
  21.             InitializeComponent();  
  22.         }  
  23.   
  24.         //获得CPU的序列号  
  25.         public string getCpu()  
  26.         {  
  27.             string strCpu = null;  
  28.             ManagementClass myCpu = new ManagementClass("win32_Processor");  
  29.             ManagementObjectCollection myCpuConnection = myCpu.GetInstances();  
  30.             foreach (ManagementObject myObject in myCpuConnection)  
  31.             {  
  32.                 strCpu = myObject.Properties["Processorid"].Value.ToString();  
  33.                 break;  
  34.             }  
  35.             txtCPU.Text = strCpu;  
  36.             return strCpu;  
  37.         }  
  38.   
  39.         //获取设备硬盘的卷标号  
  40.         public string GetDiskVolumeSerialNumber()  
  41.         {  
  42.             ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");  
  43.             ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=/"d:/"");  
  44.             disk.Get();  
  45.             txt硬盘.Text = disk.GetPropertyValue("VolumeSerialNumber").ToString();  
  46.             return disk.GetPropertyValue("VolumeSerialNumber").ToString();  
  47.         }  
  48.   
  49.         //生成机器码  
  50.         private void button1_Click(object sender, EventArgs e)  
  51.         {  
  52.             txtCPU加硬盘.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号  
  53.             string[] strid = new string[24];  
  54.             for (int i = 0; i < 24; i++)  
  55.             {  
  56.                 strid[i] = txtCPU加硬盘.Text.Substring(i, 1);//把字符赋给数组  
  57.             }  
  58.   
  59.             txtCPU加硬盘.Text = "";  
  60.             Random rdid = new Random();  
  61.             for (int i = 0; i < 24; i++)  
  62.             {  
  63.                 txtCPU加硬盘.Text += strid[rdid.Next(0, 24)];//从数组随机抽取24个字符组成新的字符生成机器码  
  64.             }  
  65.         }  
  66.   
  67.         //使用机器码生成注册码     
  68.         public void setIntCode()//给数组赋值个小于10的随机数  
  69.         {  
  70.             Random ra = new Random();  
  71.             for (int i = 1; i < intCode.Length; i++)  
  72.             {  
  73.                 intCode[i] = ra.Next(0, 9);  
  74.             }  
  75.         }  
  76.   
  77.         //生成注册码          
  78.         private void button2_Click(object sender, EventArgs e)  
  79.         {  
  80.             if (txtCPU加硬盘.Text != "")  
  81.             {  
  82.                 //把机器码存入数组中                  
  83.                 setIntCode();//初始化127位数组                  
  84.                 for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中                  
  85.                 {  
  86.                     Charcode[i] = Convert.ToChar(txtCPU加硬盘.Text.Substring(i - 1, 1));  
  87.                 }  
  88.   
  89.                 for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。                  
  90.                 {  
  91.                     intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);  
  92.                 }  
  93.   
  94.                 string strAsciiName = null;//用于存储机器码                  
  95.                 for (int j = 1; j < intNumber.Length; j++)  
  96.                 {                    
  97.                     if (intNumber[j] >= 48 && intNumber[j] <= 57)//判断字符ASCII值是否0-9之间                      
  98.                     {  
  99.                         strAsciiName += Convert.ToChar(intNumber[j]).ToString();  
  100.                     }  
  101.                     else if (intNumber[j] >= 65 && intNumber[j] <= 90)//判断字符ASCII值是否A-Z之间                      
  102.                     {  
  103.                         strAsciiName += Convert.ToChar(intNumber[j]).ToString();  
  104.                     }  
  105.                     else if (intNumber[j] >= 97 && intNumber[j] <= 122)//判断字符ASCII值是否a-z之间                      
  106.                     {  
  107.                         strAsciiName += Convert.ToChar(intNumber[j]).ToString();  
  108.                     }  
  109.                     else//判断字符ASCII值不在以上范围内  
  110.                     {  
  111.                         if (intNumber[j] > 122)//判断字符ASCII值是否大于"z"  
  112.                         {  
  113.                             strAsciiName += Convert.ToChar(intNumber[j] - 10).ToString();  
  114.                         }  
  115.                         else  
  116.                         {  
  117.                             strAsciiName += Convert.ToChar(intNumber[j] - 9).ToString();  
  118.                         }  
  119.                     }  
  120.                     txt生成注册码.Text = strAsciiName;//得到注册码  
  121.                 }  
  122.             }  
  123.             else  
  124.             {  
  125.                 MessageBox.Show("请选生成机器码""注册提示");  
  126.             }  
  127.         }  
  128.   
  129.         //用户输入注册码注册软件  
  130.         private void button3_Click(object sender, EventArgs e)  
  131.         {  
  132.             if (txtCPU加硬盘.Text != "")  
  133.             {  
  134.                 if (txt注册.Text.TrimEnd().Equals(txtCPU加硬盘.Text.TrimEnd()))  
  135.                 {  
  136.                     Microsoft.Win32.RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software"true).CreateSubKey("ZHY").CreateSubKey("ZHY.INI").CreateSubKey(txt注册.Text.TrimEnd());  
  137.                     retkey.SetValue("UserName""MySoft");  
  138.                     MessageBox.Show("注册成功");  
  139.                 }  
  140.                 else  
  141.                 {  
  142.                     MessageBox.Show("注册码输入错误");  
  143.                 }  
  144.             }  
  145.             else  
  146.             {  
  147.                 MessageBox.Show("请生成注册码""注册提示");  
  148.             }  
  149.         }  
  150.   
  151.         private void btn清空_Click(object sender, EventArgs e)  
  152.         {  
  153.             txtCPU.Text = "";  
  154.             txt硬盘.Text = "";  
  155.             txtCPU加硬盘.Text = "";  
  156.             txt生成注册码.Text = "";  
  157.             txt注册.Text = "";  
  158.         }  
  159.     }  
  160. }  

[c-sharp]  view plain copy
  1. namespace WFrom  
  2. {  
  3.     partial class Form3  
  4.     {  
  5.         /// <summary>  
  6.         /// 必需的设计器变量。  
  7.         /// </summary>  
  8.         private System.ComponentModel.IContainer components = null;  
  9.   
  10.         /// <summary>  
  11.         /// 清理所有正在使用的资源。  
  12.         /// </summary>  
  13.         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>  
  14.         protected override void Dispose(bool disposing)  
  15.         {  
  16.             if (disposing && (components != null))  
  17.             {  
  18.                 components.Dispose();  
  19.             }  
  20.             base.Dispose(disposing);  
  21.         }  
  22.  
  23.         #region Windows 窗体设计器生成的代码  
  24.   
  25.         /// <summary>  
  26.         /// 设计器支持所需的方法 - 不要  
  27.         /// 使用代码编辑器修改此方法的内容。  
  28.         /// </summary>  
  29.         private void InitializeComponent()  
  30.         {  
  31.             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form3));  
  32.             this.button1 = new System.Windows.Forms.Button();  
  33.             this.label1 = new System.Windows.Forms.Label();  
  34.             this.label2 = new System.Windows.Forms.Label();  
  35.             this.button2 = new System.Windows.Forms.Button();  
  36.             this.label3 = new System.Windows.Forms.Label();  
  37.             this.button3 = new System.Windows.Forms.Button();  
  38.             this.txt注册 = new System.Windows.Forms.TextBox();  
  39.             this.txtCPU = new System.Windows.Forms.TextBox();  
  40.             this.txt硬盘 = new System.Windows.Forms.TextBox();  
  41.             this.txtCPU加硬盘 = new System.Windows.Forms.TextBox();  
  42.             this.btn清空 = new System.Windows.Forms.Button();  
  43.             this.label4 = new System.Windows.Forms.Label();  
  44.             this.txt生成注册码 = new System.Windows.Forms.TextBox();  
  45.             this.label5 = new System.Windows.Forms.Label();  
  46.             this.groupBox1 = new System.Windows.Forms.GroupBox();  
  47.             this.groupBox2 = new System.Windows.Forms.GroupBox();  
  48.             this.groupBox3 = new System.Windows.Forms.GroupBox();  
  49.             this.groupBox1.SuspendLayout();  
  50.             this.groupBox2.SuspendLayout();  
  51.             this.groupBox3.SuspendLayout();  
  52.             this.SuspendLayout();  
  53.             //   
  54.             // button1  
  55.             //   
  56.             this.button1.Location = new System.Drawing.Point(309, 30);  
  57.             this.button1.Name = "button1";  
  58.             this.button1.Size = new System.Drawing.Size(100, 23);  
  59.             this.button1.TabIndex = 0;  
  60.             this.button1.Text = "生成机器码";  
  61.             this.button1.UseVisualStyleBackColor = true;  
  62.             this.button1.Click += new System.EventHandler(this.button1_Click);  
  63.             //   
  64.             // label1  
  65.             //   
  66.             this.label1.AutoSize = true;  
  67.             this.label1.Location = new System.Drawing.Point(12, 29);  
  68.             this.label1.Name = "label1";  
  69.             this.label1.Size = new System.Drawing.Size(59, 12);  
  70.             this.label1.TabIndex = 1;  
  71.             this.label1.Text = "CPU序列号";  
  72.             //   
  73.             // label2  
  74.             //   
  75.             this.label2.AutoSize = true;  
  76.             this.label2.Location = new System.Drawing.Point(6, 57);  
  77.             this.label2.Name = "label2";  
  78.             this.label2.Size = new System.Drawing.Size(65, 12);  
  79.             this.label2.TabIndex = 2;  
  80.             this.label2.Text = "硬盘卷标号";  
  81.             //   
  82.             // button2  
  83.             //   
  84.             this.button2.Location = new System.Drawing.Point(309, 146);  
  85.             this.button2.Name = "button2";  
  86.             this.button2.Size = new System.Drawing.Size(100, 23);  
  87.             this.button2.TabIndex = 3;  
  88.             this.button2.Text = "生成注册码";  
  89.             this.button2.UseVisualStyleBackColor = true;  
  90.             this.button2.Click += new System.EventHandler(this.button2_Click);  
  91.             //   
  92.             // label3  
  93.             //   
  94.             this.label3.AutoSize = true;  
  95.             this.label3.Location = new System.Drawing.Point(18, 84);  
  96.             this.label3.Name = "label3";  
  97.             this.label3.Size = new System.Drawing.Size(53, 12);  
  98.             this.label3.TabIndex = 4;  
  99.             this.label3.Text = "CPU+硬盘";  
  100.             //   
  101.             // button3  
  102.             //   
  103.             this.button3.Location = new System.Drawing.Point(309, 209);  
  104.             this.button3.Name = "button3";  
  105.             this.button3.Size = new System.Drawing.Size(100, 23);  
  106.             this.button3.TabIndex = 5;  
  107.             this.button3.Text = "输入注册码注册";  
  108.             this.button3.UseVisualStyleBackColor = true;  
  109.             this.button3.Click += new System.EventHandler(this.button3_Click);  
  110.             //   
  111.             // txt注册  
  112.             //   
  113.             this.txt注册.Location = new System.Drawing.Point(77, 20);  
  114.             this.txt注册.Name = "txt注册";  
  115.             this.txt注册.Size = new System.Drawing.Size(208, 21);  
  116.             this.txt注册.TabIndex = 6;  
  117.             //   
  118.             // txtCPU  
  119.             //   
  120.             this.txtCPU.Location = new System.Drawing.Point(77, 20);  
  121.             this.txtCPU.Name = "txtCPU";  
  122.             this.txtCPU.Size = new System.Drawing.Size(208, 21);  
  123.             this.txtCPU.TabIndex = 7;  
  124.             //   
  125.             // txt硬盘  
  126.             //   
  127.             this.txt硬盘.Location = new System.Drawing.Point(77, 48);  
  128.             this.txt硬盘.Name = "txt硬盘";  
  129.             this.txt硬盘.Size = new System.Drawing.Size(208, 21);  
  130.             this.txt硬盘.TabIndex = 8;  
  131.             //   
  132.             // txtCPU加硬盘  
  133.             //   
  134.             this.txtCPU加硬盘.Location = new System.Drawing.Point(77, 75);  
  135.             this.txtCPU加硬盘.Name = "txtCPU加硬盘";  
  136.             this.txtCPU加硬盘.Size = new System.Drawing.Size(208, 21);  
  137.             this.txtCPU加硬盘.TabIndex = 9;  
  138.             //   
  139.             // btn清空  
  140.             //   
  141.             this.btn清空.Location = new System.Drawing.Point(309, 269);  
  142.             this.btn清空.Name = "btn清空";  
  143.             this.btn清空.Size = new System.Drawing.Size(100, 23);  
  144.             this.btn清空.TabIndex = 10;  
  145.             this.btn清空.Text = "清空";  
  146.             this.btn清空.UseVisualStyleBackColor = true;  
  147.             this.btn清空.Click += new System.EventHandler(this.btn清空_Click);  
  148.             //   
  149.             // label4  
  150.             //   
  151.             this.label4.AutoSize = true;  
  152.             this.label4.Location = new System.Drawing.Point(6, 29);  
  153.             this.label4.Name = "label4";  
  154.             this.label4.Size = new System.Drawing.Size(65, 12);  
  155.             this.label4.TabIndex = 11;  
  156.             this.label4.Text = "生产注册码";  
  157.             //   
  158.             // txt生成注册码  
  159.             //   
  160.             this.txt生成注册码.Location = new System.Drawing.Point(77, 20);  
  161.             this.txt生成注册码.Name = "txt生成注册码";  
  162.             this.txt生成注册码.Size = new System.Drawing.Size(208, 21);  
  163.             this.txt生成注册码.TabIndex = 12;  
  164.             //   
  165.             // label5  
  166.             //   
  167.             this.label5.AutoSize = true;  
  168.             this.label5.Location = new System.Drawing.Point(42, 29);  
  169.             this.label5.Name = "label5";  
  170.             this.label5.Size = new System.Drawing.Size(29, 12);  
  171.             this.label5.TabIndex = 13;  
  172.             this.label5.Text = "注册";  
  173.             //   
  174.             // groupBox1  
  175.             //   
  176.             this.groupBox1.Controls.Add(this.txtCPU);  
  177.             this.groupBox1.Controls.Add(this.label1);  
  178.             this.groupBox1.Controls.Add(this.label2);  
  179.             this.groupBox1.Controls.Add(this.label3);  
  180.             this.groupBox1.Controls.Add(this.txt硬盘);  
  181.             this.groupBox1.Controls.Add(this.txtCPU加硬盘);  
  182.             this.groupBox1.Location = new System.Drawing.Point(8, 12);  
  183.             this.groupBox1.Name = "groupBox1";  
  184.             this.groupBox1.Size = new System.Drawing.Size(295, 110);  
  185.             this.groupBox1.TabIndex = 14;  
  186.             this.groupBox1.TabStop = false;  
  187.             this.groupBox1.Text = "步骤1";  
  188.             //   
  189.             // groupBox2  
  190.             //   
  191.             this.groupBox2.Controls.Add(this.label4);  
  192.             this.groupBox2.Controls.Add(this.txt生成注册码);  
  193.             this.groupBox2.Location = new System.Drawing.Point(8, 128);  
  194.             this.groupBox2.Name = "groupBox2";  
  195.             this.groupBox2.Size = new System.Drawing.Size(295, 57);  
  196.             this.groupBox2.TabIndex = 15;  
  197.             this.groupBox2.TabStop = false;  
  198.             this.groupBox2.Text = "步骤2";  
  199.             //   
  200.             // groupBox3  
  201.             //   
  202.             this.groupBox3.Controls.Add(this.txt注册);  
  203.             this.groupBox3.Controls.Add(this.label5);  
  204.             this.groupBox3.Location = new System.Drawing.Point(8, 191);  
  205.             this.groupBox3.Name = "groupBox3";  
  206.             this.groupBox3.Size = new System.Drawing.Size(295, 58);  
  207.             this.groupBox3.TabIndex = 15;  
  208.             this.groupBox3.TabStop = false;  
  209.             this.groupBox3.Text = "步骤3";  
  210.             //   
  211.             // Form3  
  212.             //   
  213.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);  
  214.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;  
  215.             this.ClientSize = new System.Drawing.Size(441, 304);  
  216.             this.Controls.Add(this.groupBox2);  
  217.             this.Controls.Add(this.groupBox3);  
  218.             this.Controls.Add(this.groupBox1);  
  219.             this.Controls.Add(this.btn清空);  
  220.             this.Controls.Add(this.button3);  
  221.             this.Controls.Add(this.button2);  
  222.             this.Controls.Add(this.button1);  
  223.             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));  
  224.             this.Name = "Form3";  
  225.             this.Text = "Form3";  
  226.             this.groupBox1.ResumeLayout(false);  
  227.             this.groupBox1.PerformLayout();  
  228.             this.groupBox2.ResumeLayout(false);  
  229.             this.groupBox2.PerformLayout();  
  230.             this.groupBox3.ResumeLayout(false);  
  231.             this.groupBox3.PerformLayout();  
  232.             this.ResumeLayout(false);  
  233.   
  234.         }  
  235.  
  236.         #endregion  
  237.   
  238.         private System.Windows.Forms.Button button1;  
  239.         private System.Windows.Forms.Label label1;  
  240.         private System.Windows.Forms.Label label2;  
  241.         private System.Windows.Forms.Button button2;  
  242.         private System.Windows.Forms.Label label3;  
  243.         private System.Windows.Forms.Button button3;  
  244.         private System.Windows.Forms.TextBox txt注册;  
  245.         private System.Windows.Forms.TextBox txtCPU;  
  246.         private System.Windows.Forms.TextBox txt硬盘;  
  247.         private System.Windows.Forms.TextBox txtCPU加硬盘;  
  248.         private System.Windows.Forms.Button btn清空;  
  249.         private System.Windows.Forms.Label label4;  
  250.         private System.Windows.Forms.TextBox txt生成注册码;  
  251.         private System.Windows.Forms.Label label5;  
  252.         private System.Windows.Forms.GroupBox groupBox1;  
  253.         private System.Windows.Forms.GroupBox groupBox2;  
  254.         private System.Windows.Forms.GroupBox groupBox3;  
  255.     }  
  256. }  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值