国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

權限管理系統之軟件注冊模塊

2019-11-17 02:56:10
字體:
來源:轉載
供稿:網友

權限管理系統之軟件注冊模塊

轉自:http://www.survivalescaperooms.com/jara/

軟件注冊是商業軟件必不可少的模塊,在整個程序中啟到舉足輕重的作用。

系統啟動時首先會檢測程序是否注冊,如果程序沒有注冊可以使用30次,試用次數完成后將彈出注冊界面。程序每次登陸都會將程序使用次數寫入到注冊表中,程序注冊是也會將注冊碼已加密的方式寫入到注冊表中。

復制代碼
   public static void RegMetod(bool isDownLoad)        {            try            {                SoftReg softReg = new SoftReg();                //判斷軟件是否注冊                RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey(Encrypt.EncryptDES("mySoftWare", Const.EncryptKey)).CreateSubKey(Encrypt.EncryptDES("Register.INI", Const.EncryptKey));                foreach (string strRNum in retkey.GetSubKeyNames())                {                    if (Encrypt.DecryptDES(strRNum, Const.EncryptKey) == softReg.GetRNum())                    {                        run(isDownLoad, "正式版", "");                        return;                    }                }                Int32 tLong;                try                {                    tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE//SOFTWARE//" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", 0);                }                catch                {                    Registry.SetValue("HKEY_LOCAL_MACHINE//SOFTWARE//" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", 0, RegistryValueKind.DWord);                }                tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE//SOFTWARE//" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", 0);                if (tLong < 30)                {                    int tTimes = tLong + 1;                    Registry.SetValue("HKEY_LOCAL_MACHINE//SOFTWARE//" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", tTimes);                    int xint = 30 - tTimes;                    //試用版不提供更新服務                    run(true, "試用版", xint.ToString());                }                else                {                    DialogResult result = Comm.MessageBox.YesNo("試用次數已到!您是否需要注冊?");                    if (result == DialogResult.Yes)                    {                        RegisterForm registerForm = new RegisterForm();                        registerForm.ShowDialog();                    }                    else                    {                        application.Exit();                    }                }            }            catch (Exception e)            {                Log.Error("程序注冊出錯!");                throw new Exception("程序注冊出錯:" + e.Message);            }        }
復制代碼

注冊界面:

復制代碼
        #region * 注冊        PRivate void btnReg_Click(object sender, EventArgs e)        {            if (string.IsNullOrEmpty(this.txtLicence.Text))            {                Client.Win.Comm.MessageBox.Info("注冊碼不能為空!");                return;            }            try            {                if (txtLicence.Text == softReg.GetRNum())                {                    Client.Win.Comm.MessageBox.Info("注冊成功!重啟軟件后生效!");                    RegistryKey retkey = Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey(Encrypt.EncryptDES("mySoftWare", Const.EncryptKey)).CreateSubKey(Encrypt.EncryptDES("Register.INI", Const.EncryptKey)).CreateSubKey(Encrypt.EncryptDES(txtLicence.Text, Const.EncryptKey));                    retkey.SetValue(Encrypt.EncryptDES("UserName",Const.EncryptKey),Encrypt.EncryptDES( "Rsoft",Const.EncryptKey));                    this.Close();                }                else                {                    Client.Win.Comm.MessageBox.Warn("注冊碼錯誤!");                    txtLicence.SelectAll();                }            }            catch (Exception ex)            {                throw new Exception(ex.Message);            }        }        #endregion
復制代碼

生成機器碼(由MAC地址和硬盤券盤號截取前面20位):

復制代碼
     ///<summary>        /// 生成機器碼        ///</summary>        ///<returns></returns>        public string GetMNum()        {            string strNum = Computer.Instance().MacAddress + Computer.Instance().VolumeSerialNumber; // GetCpu() + GetDiskVolumeSerialNumber();            string strMNum = string.Empty;            if (strNum.Length > 20)            {                strMNum = strNum.Substring(0, 20);    //截取前20位作為機器碼            }            else            {                strMNum = strNum;            }            return strMNum;        }
復制代碼

生成注冊碼:

復制代碼
        ///<summary>        /// 生成注冊碼        ///</summary>        ///<returns></returns>        public string GetRNum()        {            SetIntCode();            string strMNum = GetMNum();            for (int i = 1; i < charCode.Length; i++)   //存儲機器碼            {                charCode[i] = Convert.ToChar(strMNum.Substring(i - 1, 1));            }            for (int j = 1; j < intNumber.Length; j++)  //改變ASCII碼值            {                intNumber[j] = Convert.ToInt32(charCode[j]) + intCode[Convert.ToInt32(charCode[j])];            }            string strAsciiName = "";   //注冊碼            for (int k = 1; k < intNumber.Length; k++)  //生成注冊碼            {                if ((intNumber[k] >= 48 && intNumber[k] <= 57) || (intNumber[k] >= 65 && intNumber[k]                    <= 90) || (intNumber[k] >= 97 && intNumber[k] <= 122))  //判斷如果在0-9、A-Z、a-z之間                {                    strAsciiName += Convert.ToChar(intNumber[k]).ToString();                }                else if (intNumber[k] > 122)  //判斷如果大于z                {                    strAsciiName += Convert.ToChar(intNumber[k] - 10).ToString();                }                else                {                    strAsciiName += Convert.ToChar(intNumber[k] - 9).ToString();                }            }            return strAsciiName;        }
復制代碼

獲取電腦的基本信息:

復制代碼
 /// <summary>    /// Computer Information    /// </summary>    public class Computer    {        public string CpuID;        public string MacAddress;        public string DiskID;        public string ipAddress;        public string LoginUserName;        public string ComputerName;        public string SystemType;        public string TotalPhysicalMemory; //單位:M        public string VolumeSerialNumber;        private static Computer _instance;        public static Computer Instance()        {            if (_instance == null)                _instance = new Computer();            return _instance;        }        protected Computer()        {            VolumeSerialNumber = GetDiskVolumeSerialNumber();            CpuID = GetCpuID();            MacAddress = GetMacAddress();            DiskID = GetDiskID();            IpAddress = GetIPAddress();            LoginUserName = GetUserName();            SystemType = GetSystemType();            TotalPhysicalMemory = GetTotalPhysicalMemory();            ComputerName = GetComputerName();        }        ///<summary>        /// 獲取硬盤卷標號        ///</summary>        ///<returns></returns>        public string GetDiskVolumeSerialNumber()        {            try            {                ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");                ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=/"c:/"");                disk.Get();                return disk.GetPropertyValue("VolumeSerialNumber").ToString();            }            catch            {
上一篇:HttpHelper

下一篇:值類型與引用類型總結

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西充县| 左云县| 克拉玛依市| 延川县| 兰州市| 都匀市| 惠东县| 天等县| 阿瓦提县| 泰安市| 定西市| 苗栗县| 麦盖提县| 兰考县| 长汀县| 新绛县| 陕西省| 德州市| 武山县| 凤庆县| 呼玛县| 蓬安县| 乐山市| 德昌县| 本溪| 泾源县| 乡宁县| 吴江市| 汕尾市| 丰宁| 潞城市| 加查县| 蒙自县| 同江市| 科尔| 鄂伦春自治旗| 浑源县| 浑源县| 延长县| 通山县| 邹平县|