123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Management;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml;
- namespace OTSMeasureApp
- {
- class CRegistration
- {
-
- public bool RegistrationVerification()
- {
- if (!checkRegistration())//文件授权法
- {
- //return false;
- try
- {
- uint[] code;
- code = new uint[2];
- code[0] = 101;
- code[1] = 102;
- //狗加密法
- SenseShield.DogDecrypting.decrypting(code);//参数为许可号
-
- }
- catch (Exception ex)
- {
- //MessageBox.Show("Error: missing dog authorization");
- return false;
- }
- }
-
- return true;
- }
- private bool checkRegistration()
- {
- string CPUID, DiskID;
- CPUID = getCpu();
- DiskID = GetDiskVolumeSerialNumber();
- var ID = ReadXML("./Config/SysData/RegistrationProofreading.txt");
- if (ID.Count == 0)
- {
- return false;
- }
- List<string> list_str = new List<string>();
- List<string> list_time = new List<string>();
- ID.TryGetValue("ID", out list_str);
- ID.TryGetValue("Time", out list_time);
- string setCPU = ConvertString(list_str[0]);
- string setDisk = ConvertString(list_str[1]);
- string setYear = ConvertString(list_time[0]);
- string setMonth = ConvertString(list_time[1]);
- string setDay = ConvertString(list_time[2]);
- if (CPUID != setCPU || DiskID != setDisk)
- {
- return false;
- }
- DateTime dt = DateTime.ParseExact(setYear + setMonth + setDay + "235959", "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
- if (DateTime.Now > dt)
- {
- return false;
- }
- return true;
- }
- // 获得CPU的序列号
- private static 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 static string GetDiskVolumeSerialNumber()
- {
- ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
- disk.Get();
- return disk.GetPropertyValue("VolumeSerialNumber").ToString();
- }
- private static IDictionary<String, List<String>> ReadXML(string address)
- {
- IDictionary<String, List<String>> infos = new Dictionary<String, List<String>>();
- if (File.Exists(address))
- {
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(address);
- XmlNode xn = xmlDoc.SelectSingleNode("infos");
- XmlNodeList xnl = xn.ChildNodes;
- foreach (XmlNode xnf in xnl)
- {
- XmlElement xe = (XmlElement)xnf;
- XmlNode nameNode = xe.SelectSingleNode("ID");
- string name = nameNode.InnerText;
- Console.WriteLine(name);
- XmlNode filelist = xe.SelectSingleNode("filelist");
- List<String> list = new List<string>();
- foreach (XmlNode item in filelist.ChildNodes)
- {
- list.Add(item.InnerText);
- }
- infos.Add(name, list);
- }
- }
- return infos;
- }
- private string ConvertString(string str)
- {
- string str_out;
- string[] arr = str.Split(',');
- byte[] be = new byte[arr.Count()];
- for (int i = 0; i < arr.Count(); i++)
- {
- be[i] = Convert.ToByte(arr[i]);
- }
- str_out = Encoding.Unicode.GetString(be);
- return str_out;
- }
- }
- }
|