Implementation of. NET (C #) Simple software registration function

Source: Internet
Author: User
Tags ini interface md5 net string static class

Main idea: Get the CPU serial number of the machine, get machine code. The registration code is obtained by MD5 operation of the machine code. Write the registration code into the registry or system directory.
1. At the entrance of the program (WinForm) detect the existence of the registration file, if it does not exist
Prompts the user to register file corruption or the user is not registered, if the registration file exists, read the contents of the file, to determine whether the registration code is correct.
The file operation is done by referencing the using System.IO in the file where the entry function of the program is located.

 
 
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Windows.Forms;
  4. Using System.IO;
  5. Namespace Loginwindowtest
  6. {
  7. Static Class Program
  8. {
  9. <summary>
  10. The main entry point for the application.
  11. </summary>
  12. [STAThread]
  13. static void Main ()
  14. {
  15. String sysfolder = system.environment.systemdirectory;//Get system installation directory such as: C:\Windows\System32
  16. Reg RG=NEW Reg ()//There are several functions in this class (get the CPU serial number, MD5 the string, etc.)
  17. Application.enablevisualstyles ();
  18. Application.setcompatibletextrenderingdefault (FALSE);
  19. if (! File.exists (sysfolder + "file://sixi.ini/"))
  20. {
  21. If the registration file does not exist. Registration failed
  22. Create a registration file
  23. File.create (sysfolder + "file://sixi.ini/");
  24. MessageBox.Show ("Please Register!") ");
  25. Application.Run (New RegForm ());//Enter the registration interface.
  26. }
  27. Else
  28. {//If the registration file exists, read the file content to compare with the password
  29. byte[] Arry=new byte [32];
  30. String str = "";
  31. FileInfo fi = new FileInfo (sysfolder + "file://sixi.ini/");
  32. FileStream fs = fi. OpenRead ();
  33. int I=fs. Read (Arry, 0, 32);
  34. Fs. Close ();
  35. str = System.Text.Encoding.ASCII.GetString (Arry);
  36. if (str = RG.GETMD5 (RG). Getcpuid ()). Trim ())//If the string in the registration file is the same as the registration code that was MD5, the registration is successful
  37. {
  38. MessageBox.Show ("Software has been successfully registered!") ");
  39. Application.Run (New MainForm ());//Enter Software main interface
  40. }
  41. Else
  42. {
  43. MessageBox.Show ("Please register the software!") ");
  44. Application.Run (New RegForm ());//Enter the registration interface.
  45. }
  46. }
  47. }
  48. }
  49. }



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.