public static int InitRegedit() { /*检查注册表*/ string SericalNumber = ReadSetting("", "SerialNumber", "-1"); // 读取注册表, 检查是否注册 -1为未注册 if (SericalNumber == "-1") { return(1); } /* 比较CPUid */ string CpuId = GetSoftEndDateAllCpuId(1, SericalNumber); //从注册表读取CPUid string CpuIdThis = GetCpuId(); //获取本机CPUId if (CpuId != CpuIdThis) { return(2); } /* 比较时间 */ string NowDate = SoftRegister.GetNowDate(); string EndDate = SoftRegister.GetSoftEndDateAllCpuId(0, SericalNumber); if (Convert.ToInt32(EndDate) - Convert.ToInt32(NowDate) < 0) { return(3); } return(0); }
public static void Test() { int res = SoftRegister.InitRegedit(); if (res == 0) { //Application.Run(new Form1()); } else if (res == 1) { //MessageBox.Show("软件尚未注册,请注册软件!"); } else if (res == 2) { //MessageBox.Show("注册机器与本机不一致,请联系管理员!"); } else if (res == 3) { //MessageBox.Show("软件试用已到期!"); } else { //MessageBox.Show("软件运行出错,请重新启动!"); } }