C # Read machine code _CPU serial Number _ Generate registration code class

Source: Internet
Author: User

usingSystem.Management;//you need to add a system.management reference to your project     Public classSoftreg {/// <summary>        ///get the volume label of the device's hard disk/// </summary>        /// <returns></returns>         Public stringGetdiskvolumeserialnumber () {ManagementClass mc=NewManagementClass ("Win32_NetworkAdapterConfiguration"); ManagementObject Disk=NewManagementObject ("win32_logicaldisk.deviceid=\ "c \""); Disk.            Get (); returnDisk. GetPropertyValue ("VolumeSerialNumber").        ToString (); }        /// <summary>        ///get the serial number of the CPU/// </summary>        /// <returns></returns>         Public stringgetcpu () {stringSTRCPU =NULL; ManagementClass mycpu=NewManagementClass ("Win32_Processor"); Managementobjectcollection mycpuconnection=mycpu.getinstances (); foreach(ManagementObject MyObjectinchmycpuconnection) {STRCPU= myobject.properties["Processorid"].                Value.tostring ();  Break; }            returnstrcpu; }                /// <summary>        ///Generate machine code/// </summary>        /// <returns></returns>         Public stringGetmnum () {stringStrnum = getcpu () + Getdiskvolumeserialnumber ();//get 24-bit CPU and hard drive serial number            stringStrmnum = strnum.substring (0, -);//Remove the first 24 characters from the generated string as machine code            returnStrmnum; }         Public int[] Intcode =New int[127];//Store Key         Public int[] intnumber =New int[ -];//ASCII value of the stored machine code         Public Char[] CharCode =New Char[ -];//Storage Machine code word         Public voidSetintcode ()//assigning a number less than 10 to an array        {             for(inti =1; i < intcode.length; i++) {Intcode[i]= i%9; }        }                /// <summary>        ///Generate registration Code/// </summary>        /// <returns></returns>         Public stringGetrnum () {setintcode ();//initializing a 127-bit array            stringMnum = This. Getmnum ();//Get Registration Code             for(inti =1; i < charcode.length; i++)//storing machine code in an array{Charcode[i]= Convert.tochar (mnum.substring (i-1,1)); }             for(intj =1; J < Intnumber.length; J + +)//The ASCII value of the character is stored in an integer group. {Intnumber[j]= Intcode[convert.toint32 (Charcode[j]) +Convert.ToInt32 (Charcode[j]); }            stringStrasciiname ="";//used to store registration codes             for(intj =1; J < Intnumber.length; J + +)            {                if(Intnumber[j] >= -&& Intnumber[j] <= $)//determines whether the ASCII value of a character is between 0-9{strasciiname+=Convert.tochar (Intnumber[j]).                ToString (); }                Else if(Intnumber[j] >= $&& Intnumber[j] <= -)//determines whether the ASCII value of a character is a-Z{strasciiname+=Convert.tochar (Intnumber[j]).                ToString (); }                Else if(Intnumber[j] >= the&& Intnumber[j] <=122)//determines whether the ASCII value of a character is a-Z{strasciiname+=Convert.tochar (Intnumber[j]).                ToString (); }                Else//determine the ASCII value of the character is not in the above range                {                    if(Intnumber[j] >122)//determines whether the ASCII value of a character is greater than Z{strasciiname+ = Convert.tochar (Intnumber[j]-Ten).                    ToString (); }                    Else{strasciiname+ = Convert.tochar (Intnumber[j]-9).                    ToString (); }                }            }            returnStrasciiname;//Return Registration Code        }    }

C # Read machine code _CPU serial Number _ Generate registration code class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.