C#生成軟件注冊碼

http://blog.csdn.net/dingxiaowei2013/article/details/8948220


開發軟件時,當用到商業用途時,注冊碼與激活碼就顯得很重要了。現在的軟件破解技術實在在強了,各種國內外大型軟件都有注冊機制,但同時也不斷地被破解。下面發的只是一個常用版本,發出源碼被破就更容易了,但我們學習的是技術。當然也為以後自己的軟件不會被輕易破解。

第一步。根據卷標,CPU序列號,生成機器碼
// 取得設備硬盤的卷標號
        public static string GetDiskVolumeSerialNumber()
        {
            ManagementClass mc = new ManagementClass(「Win32_NetworkAdapterConfiguration」);
            ManagementObject disk = new ManagementObject(「win32_logicaldisk.deviceid=」d:」");
            disk.Get();
            return disk.GetPropertyValue(「VolumeSerialNumber」).ToString();
        }

        //獲得CPU的序列號
        public 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;
        }
        //生成機器碼
        public static string getMNum()
        {
            string strNum = getCpu() + GetDiskVolumeSerialNumber();//獲得24位Cpu和硬盤序列號
            string strMNum = strNum.Substring(0, 24);//從生成的字符串中取出前24個字符做為機器碼
            return strMNum;
        }
        public static int[] intCode = new int[127];//存儲密鑰
        public static int[] intNumber = new int[25];//存機器碼的Ascii值
        public static char[] Charcode = new char[25];//存儲機器碼字
        public static void setIntCode()//給數組賦值小於10的數
        {
            for (int i = 1; i < intCode.Length; i++)
            {
                intCode[i] = i % 9;
            }
        }

第二步。根據機器碼 生成注冊碼
        //生成注冊碼     

       public static string getRNum()
        {
            setIntCode();//初始化127位數組
            for (int i = 1; i < Charcode.Length; i++)//把機器碼存入數組中
            {
                Charcode[i] = Convert.ToChar(getMNum().Substring(i – 1, 1));
            }
            for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一個整數組中。
            {
                intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);
            }
            string strAsciiName = 「」;//用於存儲注冊碼
            for (int j = 1; j < intNumber.Length; j++)
            {
                if (intNumber[j] >= 48 && intNumber[j] <= 57)//判斷字符ASCII值是否0-9之間
                {
                    strAsciiName += Convert.ToChar(intNumber[j]).ToString();
                }
                else if (intNumber[j] >= 65 && intNumber[j] <= 90)//判斷字符ASCII值是否A-Z之間
                {
                    strAsciiName += Convert.ToChar(intNumber[j]).ToString();
                }
                else if (intNumber[j] >= 97 && intNumber[j] <= 122)//判斷字符ASCII值是否a-z之間
                {
                    strAsciiName += Convert.ToChar(intNumber[j]).ToString();
                }
                else//判斷字符ASCII值不在以上范圍內
                {
                    if (intNumber[j] > 122)//判斷字符ASCII值是否大於z
                    {
                        strAsciiName += Convert.ToChar(intNumber[j] – 10).ToString();
                    }
                    else
                    {
                        strAsciiName += Convert.ToChar(intNumber[j] – 9).ToString();
                    }
                }
            }
            return strAsciiName;
        }

第三步。檢查注冊狀況,若沒有注冊,可自定義試用      

/// <summary>
        /// 檢查注冊
        /// </summary>
        private void CheckRegist()
        {

                this.btn_reg.Enabled = true;

                  RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(「software」, true).CreateSubKey(「wxk」).CreateSubKey(「wxk.INI」);
                foreach (string strRNum in retkey.GetSubKeyNames())//判斷是否注冊
                {
                    if (strRNum == clsTools.getRNum())
                    {
                        thControl(true);
                        return;
                    }
                }
                thControl(false);
                Thread th2 = new Thread(new ThreadStart(thCheckRegist2));
                th2.Start();

          }
        }
     
        /// <summary>
        /// 驗證試用次數
        /// </summary>
        private static void thCheckRegist2()
        {
            MessageBox.Show(「您現在使用的是試用版,該軟件可以免費試用3000000次!」, 「提示」, MessageBoxButtons.OK, MessageBoxIcon.Information);
            Int32 tLong;
            try
            {
                tLong = (Int32)Registry.GetValue(「HKEY_LOCAL_MACHINE\SOFTWARE\angel」, 「UseTimes」, 0);
                MessageBox.Show(「感謝您已使用了」 + tLong + 「次」, 「提示」, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                Registry.SetValue(「HKEY_LOCAL_MACHINE\SOFTWARE\angel」, 「UseTimes」, 0, RegistryValueKind.DWord);
                MessageBox.Show(「歡迎新用戶使用本軟件」, 「提示」, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            tLong = (Int32)Registry.GetValue(「HKEY_LOCAL_MACHINE\SOFTWARE\angel」, 「UseTimes」, 0);
            if (tLong < 3000000)
            {
                int Times = tLong + 1;
                Registry.SetValue(「HKEY_LOCAL_MACHINE\SOFTWARE\angel」, 「UseTimes」, Times);
            }
            else
            {
                MessageBox.Show(「試用次數已到」, 「警告」, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Application.Exit();
            }
        }


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REaDME.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值