An example of using the motherboard serial number for registration is as follows.
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 Running Times
fcompany: string; // company name
femail: string; // contact your email
protected
procedure setserial; // obtain the master's serial number
procedure getkey; // read the serial number from the user serial number file
function gettimes: integer; // number of times the Program is read from the file
function checkkey: Boolean; // function for checking whether the serial number and password match
Public
constructor create;
function execute: Boolean; // method of running the object
published
property company: String read fcompany write fcompany;
property maxtimes: integer read fmaxtimes write fmaxtimes;
property Email: string read femail write femail;
end;
Implementation
// Tregobj.
Constructor tregobj. Create;
Begin
Inherited;
End;
Function tregobj. gettimes: integer;
Const
// The file used to store the running times. developers can customize or use the registry to store the running times.
// This name is used to confuse the hacker. Do not use the same name as the dynamic link library of the system before use.
TMP = 'ispnet. dll ';
VaR
Ch: Char;
Dir: array [0 .. 255] of char;
FN: string;
I: integer;
List: tstrings;
Begin
// Obtain the directory of the Windows System
Getsystemdirectory (@ Dir, 255 );
For I: = 0 to 255 do
Begin
If ord (dir [I]) = 0 then
Break;
FN: = FN + dir [I];
End;
FN: = FN + '\' + TMP;
Try
List: = tstringlist. Create;
If not fileexists (FN) then
Ch: = CHR (1)
Else
Begin
List. loadfromfile (FN );
Ch: = List. Text [1];
Ch: = CHR (ord (CH) + 1 );
End;
List. Text: = CH;
// Storage running times
List. savetofile (FN );
Result: = ord (CH );
Finally
List. Free;
End;
End;
Procedure tregobj. setserial;
Begin
// Obtain the serial number of the motherboard
Fserial: = string (pchar (PTR ($ fec71 )));
End;
// Obtain the 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;
Function tregobj. checkkey: Boolean;
Begin
// Developers can modify the settings based on their own needs. This is for the sake of simplicity.
Result: = fkey = fserial;
End;
Function tregobj. Execute: Boolean;
VaR
MSG: string;
T: integer;
Begin
T: = gettimes;
Getkey;
Setserial;
If fkey <> fserial then
Begin
MSG: = 'You are running this program' + inttostr (t) + '(maximum times:' + inttostr (fmaxtimes) + ')! ';
Application. MessageBox (pchar (MSG), 'user information', mb_ OK + mb_iconwarning );
MSG: = 'Welcome to use '+ company +'. If you are satisfied, please register or purchase genuine software! ';
Application. MessageBox (pchar (MSG), 'recommend', mb_ OK + mb_iconinformation );
If T> fmaxtimes then
Begin
If application. MessageBox ('register? ', 'Registration', mb_yesno + mb_iconquestion) = id_yes then
Begin
MSG: = 'your registration number is: '+ fserial +' + CHR (13) + CHR (10) +
'Please email the above serial number to the following mailbox: '+ femail;
Application. MessageBox (pchar (MSG), 'Software registration', mb_ OK + mb_iconinformation );
End;
Application. Terminate;
End;
End;
End;
End.
After writing the control, let's see how to use the control:
Procedure tform1.formcreate (Sender: tobject );
VaR
Aobj: tregobj;
Begin
Try
Aobj: = tregobj. Create;
Aobj. maxtimes: = 30;
Aobj. Company: = 'savagers ';
Aobj. Email: = 'huangjacky @ 163.com ';
Aobj. Execute;
Finally
Aobj. Free;
End;
End;
That's easy.
Now, the introduction is complete,ArticleI first saw it on the monopoly and tested it myself.
The original author is unknown, but we still want to thank him.