Delphi - an example of software registration

An example of using the motherboard serial number to register, and we want to help.
 
Unit RegObj;

Interface

Uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Forms;

Type
  TRegObj = Class
  Private
    FSerial: String; // motherboard serial number
    FKey: String; // password
    FMaxTimes: Integer; // maximum number of runs
    FCompany: String; // Company Name
    FEmail: String; // e-mail contact with the
  Protected
    procedure setSerial; // acquired sequence number of the main pull
    procedure GetKey; // read the serial number from the serial number of the user file
    Function GetTimes: Integer; // read the program from the file number of runs
    Function CheckKey: Boolean; // check serial number and password match function
  Public
    Constructor the Create;
    function the Execute: Boolean; // run object methods
  Published
    Property Company: String the Read FCompany the Write FCompany;
    Property MaxTimes: Integer the Read FMaxTimes the Write FMaxTimes;
    Property Email: String Read FEmail Write FEmail;
  End;

Implementation

// TRegObj.

Constructor TRegObj.Create;
Begin
  Inherited;
End;

TRegObj.GetTimes Function: Integer;
Const
file, developers // used to store the number of runs can customize or use the registry to store the number of runs
// since this name to confuse the attacker, and not before using the system dynamic-link library of the same name
  Tmp = 'ispnet.dll';
Var
  Ch: Char;
  Dir: Array [0..255] of Char;
  the Fn: String;
  the I: Integer;
  List: Tstrings;
the Begin
// get the Windows system directory of
  the GetSystemDirectory ( @Dir , 255);
  the For the I: = 0 the To 255 the Do
  the Begin
    the If Ord (the Dir [the I]) = 0 the Then
      Break;
    the Fn: = the Fn + the Dir [the I];
  End;
  the Fn: = the Fn + '\' + the Tmp;
  the Try
    List: TStringList.Create =;
    the If Not the FileExists (the Fn) the Then
      Ch: = Chr (. 1)
    Else
    the Begin
      List.LoadFromFile (the Fn);
      Ch: = List.Text [. 1];
      Ch: = Chr (Ord (Ch) +. 1);
    End;
    List.Text: Ch =;
// store the number of operations
    List.SaveToFile ( fn);
    the Result: = Ord (Ch);
  the Finally
    List.Free;
  End;
End;

TRegObj.SetSerial Procedure;
the Begin
// get motherboard serial number
  FSerial: = String (Pchar (Ptr ($ FEC71)));
End;

// get password

Procedure TRegObj.GetKey;
Const
  Sn= 'Key.dat';
Var
  List: TStrings;
  Fn, Path: String;
Begin
  Path := ExtractFilePath( Application.ExeName );
  Fn := Path+ Sn;
  If Not FileExists( Fn ) Then
  Begin
    FKey := '';
    Exit;
  End;
  Try
    List := TStringList.Create;
    List.LoadFromFile( Fn );
    FKey := List.Values[ 'Key' ];
  Finally
    List.Free;
  End;
End;

TRegObj.CheckKey Function: Boolean;
the Begin
// developers to modify according to their needs, in this case for simplicity
  the Result: = FKey = FSerial;
End;

TRegObj.Execute Function: Boolean;
Var
  Msg: String;
  T: Integer;
the Begin
  T: = the getTimes;
  the GetKey;
  setserial;
  the If of FKey <> FSerial the Then
  the Begin
    Msg: = 'This is your first' + IntToStr (T) + 'times run this program (maximum number of times: '+ IntToStr (FMaxTimes) + ')! ';
    Application.MessageBox (PChar (Msg),' user information ', MB_OK + MB_ICONWARNING);
    Msg: =' Welcome '+ Company +' software, if you feel satisfied, please register or buy legitimate software! ';
    Application.MessageBox (PChar (Msg),' recommended ', MB_OK + MB_ICONINFORMATION);
    the If T> FMaxTimes the Then
    the Begin
      the If Application.MessageBox (' whether registration ',' registration '?

        Msg: = 'Your registration number is: "' + FSerial + '"' + Chr (13) + Chr (10) +
          'above the serial number you will be sent the following mail via e-mail:' + Femail;
        Application.MessageBox (PChar (Msg), 'registration software', MB_OK MB_ICONINFORMATION +);
      End;
      Application.Terminate;
    End;
  End;
End;

End.

Controls written, look to use controls:

Procedure TForm1.FormCreate( Sender: TObject );
Var
  AObj: TRegObj;
Begin
  Try
    AObj := TRegObj.Create;
    AObj.MaxTimes := 30;
    AObj.Company := 'Savagers';
    AObj.Email := '[email protected]';
    AObj.Execute;
  Finally
    AObj.Free;
  End;
End;

It's that simple.
Well, the introduction is over, the article was first seen at the top of Monopoly that he tested normal.
The original author is unknown, but we still have to thank him.

Reproduced in: https: //my.oschina.net/cookblack/blog/621386

Guess you like

Origin blog.csdn.net/weixin_33704591/article/details/92046065