C\#소프트웨어 등록 코드 의 실현 코드

첫걸음볼 륨,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 C 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] C 10).ToString();
                    }
                    else
                    {
                        strAsciiName += Convert.ToChar(intNumber[j] C 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();
            }
        }

좋은 웹페이지 즐겨찾기