客户端验证代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Microsoft.Win32;namespace 注册机{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } SoftReg softReg = new SoftReg(); private void Form1_Load(object sender, EventArgs e) { try { //判断软件是否注册 RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("mySoftWare").CreateSubKey("Register.INI"); foreach (string strRNum in retkey.GetSubKeyNames()) { if (strRNum == softReg.GetRNum()) { this.labRegInfo.Text = "此软件已注册!"; this.btnReg.Enabled = false; return; } } this.labRegInfo.Text = "此软件尚未注册!"; this.btnReg.Enabled = true; MessageBox.Show("您现在使用的是试用版,可以免费试用30次!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); Int32 tLong; //已使用次数 try { tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\mySoftWare", "UseTimes", 0); MessageBox.Show("您已经使用了" tLong "次!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("欢迎使用本软件!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\mySoftWare", "UseTimes", 0, RegistryValueKind.DWord); } //判断是否可以继续试用 tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\mySoftWare", "UseTimes", 0); if (tLong < 30) { int tTimes = tLong 1; Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\mySoftWare", "UseTimes", tTimes); } else { DialogResult result = MessageBox.Show("试用次数已到!您是否需要注册?", "信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { FormRegister.state = false; //设置软件状态为不可用 btnReg_Click(sender, e); //打开注册窗口 } else { Application.Exit(); } } }catch(Exception ex){ MessageBox.Show("请以管理员身份运行!"); this.Close(); } } private void btnReg_Click(object sender, EventArgs e) { FormRegister frmRegister = new FormRegister(); frmRegister.ShowDialog(); } private void btnClose_Click(object sender, EventArgs e) { Application.Exit(); } }}
注册机部分代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 生成注册码{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } SoftReg softReg = new SoftReg(); private void btnCreate_Click(object sender, EventArgs e) { try { string strHardware = this.txtHardware.Text; string strLicence = softReg.GetRNum(strHardware); this.txtLicence.Text = strLicence; } catch (System.Exception ex) { MessageBox.Show("输入的机器码格式错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void btnExit_Click(object sender, EventArgs e) { Application.Exit(); } }}
评论