首页 > 代码库 > 设计软件注册之一网卡序列号
设计软件注册之一网卡序列号
根据网卡序列号设计软件注册
通过注册软件获取本机网卡序列号,然后通过网卡序列号、随机数及指定算法生成注册码,最后将注册码写入注册表。
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Management; 10 11 namespace 利用网卡序列号设计软件注册程序 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void Form1_Load(object sender, EventArgs e) 21 { 22 label3.Text = Environment.MachineName.ToString(); 23 label4.Text = GetNetCardMacAddress(); 24 } 25 public string GetNetCardMacAddress() 26 { 27 //实例化MangementClass对象。 28 ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); 29 //创建ManagementObjectCollection对象。 30 ManagementObjectCollection moc = mc.GetInstances(); 31 string str = ""; 32 foreach (ManagementObject mo in moc)//遍历所得的集合 33 { 34 if ((bool)mo["IPEnabled"]==true) 35 { 36 str=mo["MacAddress"].ToString(); 37 } 38 39 } return str; 40 41 } 42 43 string[] strLanCode = new string[12];//网卡信息存储。 44 string[] strKey = { "Q","W","7","E","D","F","2","G","R","T","Y","8","P", 45 "N","B","V","C","X","Z","0","9","I","8","6","U","O", 46 "P","M","5","4","3","1","A","S","H","J","K","L"}; 47 public int intRand = 0; 48 private void button1_Click(object sender, EventArgs e) 49 { 50 string strCode = GetNetCardMacAddress(); 51 strCode = strCode.Substring(0, 2) + strCode.Substring(3, 2) + strCode.Substring(6, 2) 52 + strCode.Substring(9, 2) + strCode.Substring(12, 2) + strCode.Substring(15, 2); 53 string strb = strCode.Substring(0, 4) + strCode.Substring(4, 4) + strCode.Substring(8,4); 54 for (int i = 0; i < strLanCode.Length; i++) 55 { 56 strLanCode[i] = strb.Substring(i,1);//把网卡信息存入数组。 57 58 } 59 Random ra = new Random(); 60 switch (intRand) 61 { 62 case 0: 63 label5.Text = strCode.Substring(0, 4) + "-" + strCode.Substring(4, 4) + "-" + strCode.Substring(8, 4) + "-" + 64 strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + 65 strKey[ra.Next(0, 37)].ToString();//生成随机注册码。 66 intRand = 1; 67 break; 68 case 1: 69 label5.Text = strCode.Substring(0, 4) + "-" + strCode.Substring(4, 4) + "-" + strLanCode[ra.Next(0, 11)] + 70 strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + "-" + 71 strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + 72 strKey[ra.Next(0, 37)].ToString();//生成随机注册码。 73 intRand = 2; 74 break; 75 case 2: 76 label5.Text = strCode.Substring(0, 4) + "-" + strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + 77 strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + "-" + strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + 78 strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)]+ "-" +strKey[ra.Next(0, 37)].ToString() + 79 strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + 80 strKey[ra.Next(0, 37)].ToString();//生成随机注册码。 81 intRand = 3; 82 break; 83 case 3: 84 label5.Text = strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] + strLanCode[ra.Next(0, 11)] +"-"+ 85 strLanCode[ra.Next(0,11)]+strLanCode[ra.Next(0,11)]+strLanCode[ra.Next(0,11)]+strLanCode[ra.Next(0,11)]+"-"+ 86 strLanCode[ra.Next(0,11)]+strLanCode[ra.Next(0,11)]+strLanCode[ra.Next(0,11)]+strLanCode[ra.Next(0,11)]+"-"+ 87 strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + strKey[ra.Next(0, 37)].ToString() + 88 strKey[ra.Next(0, 37)].ToString();//生成随机注册码。 89 intRand = 0; 90 break; 91 } 92 } 93 94 private void button2_Click(object sender, EventArgs e) 95 { 96 //注册按钮 97 if (label5.Text=="") 98 { 99 MessageBox.Show("请生成注册码!","提示");100 }101 else102 {103 string strNameKey = textBox1.Text.TrimEnd()+ textBox2.Text.TrimEnd()+104 textBox3.Text.TrimEnd() + textBox4.Text.TrimEnd();//获取输入的注册码。105 string strNumber = label5.Text.Substring(0,4) + label5.Text.Substring(5,4) +106 label5.Text.Substring(10,4) + label5.Text.Substring(15,4);//获取生成的注册码。107 if (strNameKey==strNumber)//判断是否相等。108 {109 Microsoft.Win32.RegistryKey retkey1 =//打开对应的键值。110 Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE").OpenSubKey("ZHD").OpenSubKey("ZHD.INI", true);111 //MessageBox.Show(retkey1.GetSubKeyNames().ToString());112 foreach (String strName in retkey1.GetSubKeyNames())//判断注册码是否过期。113 {114 if (strName == strNameKey)//如果输入的和原始值相等,则表示过期。115 {116 MessageBox.Show("你的注册码已经过期!", "提示");117 return;118 }119 }120 Microsoft.Win32.RegistryKey retkey =121 Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("ZHD").CreateSubKey("ZHD.INI").CreateSubKey(strNumber.TrimEnd());122 retkey.SetValue("UserName","天成科技有限责任公司");123 MessageBox.Show("注册成功!","提示");124 }125 else126 {127 MessageBox.Show("注册码输入错误!","提示");128 }129 }130 }131 132 private void button3_Click(object sender, EventArgs e)133 {134 Application.Exit();135 }136 137 138 }139 }
效果如下:
设计软件注册之一网卡序列号
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。