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