Use the C ++ Builder setting program to use time

zhaozj2021-02-11  199

Use C Builder Settings Time August 9, 2001 ◆ Zheng Yongfan Currently, many applications have functions in certain limited conditions, using this feature to effectively limit the use of illegal users, while also make legal On the basis of fully understanding software excellent disadvantages, users decide whether to buy. In this paper, the method of implementing this function is to protect the method. The use of protection methods is based on the protection of genuine software, which effectively expands the scope of software using software, and provides users with a pleasant choice. Protection Method This article introduces four protection methods implemented by C Builder: Use the number of days used by the registry restriction program, such as the limitations used for 30 days; use the number of times used by the registry restriction program, such as 45 times, the limit is used. Date, for example, the deadline is August 31, 2001; the time to limit the time of each use, for example, 50 minutes. These protection methods can be used alone or in several simultaneous use of integrated protection. Programming Idea 1. Method 1 and Method 2 During the ONCREATE event of the program main form, define the registry Tregistry class object pointer REG: Tregistry * reg = new Tregistry; Rootkey is registered with its property rootkey, such as: REG- > Rootkey = hkey_users; // You can select a custom primary key under the root key as needed, for example: reg-> OpenKey (". Default // myprogram // records", false) If the primary button does not exist ( That is, when you run this program for the first time, you need to create the primary key using the createkey () method, open it, write sub-keys and key values ​​as follows (see Figure 1): // "count" key value record this program REG REG REG REG REG -> WriteInteger ("count", 1); // "Flag" key value records this program uses whether there is expired record REG-> WriteInteger ("flag", 0); // "first" key value record for the first time The date of the program REG-> WriteDate ("first", Date ()); // "Last" key value record last Run the date of this program REG-> WriteDate ("Last", DATE ()); Figure 1 The "first" key value reads the date of the first run program, and then compares the current date of the system, it is determined whether or not the number of days of the specified days is determined whether the running program is running, thereby implementing the number of days of use. By obtaining the number of times used for the reading of the "Count" key, it is determined whether or not the number of times is more than the specified number of times to determine whether the operation of the program is limited. In addition, by reading the "FLAG" key value, it can be understood whether the program has an expired record, its value is 1 indicating that the program use has expired; read the "Last" key value can get the date of the last use of this program. If the judgment does not exceed the specified life, "count" and "Last" key values: // Use 1 REG-> WriteInteger ("count", reg-> readinteger ("count") 1); // Reconnect the current date REG-> WriteDate ("Last", Date ()); 2. Method 3 Determine if the current date exceeds a predetermined deadline during the main form of the main form, decide whether to terminate the program .

3. Method 4 Take a time component that detects the time of this program run during its ONTIMER event (from the program start to the current) to exceed the preset time, thereby deciding whether to terminate the operation of the program. Specific implementation 1. Restrict whether the number of days (such as 30 days) is added during the oncreate event of the main form for more than 30 days, if yes, the termination program runs and records the "FLAG" key value of 1. The current system date is obtained by the VCL library function Date (). The main code is as follows: // Defines the date type object TDATE FIRSTDATE, CURRENTDATE; / / Get the first run program date firstdate = reg-> readdate ("first"); // Get the first run program date currentdate = Date (); if (CurrentDate .Val-firstdate.val> 30) {Application-> MessageBox ("This program has been used for more than 30 days! / N will be closed ...", "Results", MB_OK); REG-> WriteInteger ("flag", 1); // Terminate the program to run Application-> Terminate ();} 2. Limiting the number of uses (such as 45) During the online server's oncreate event, the use of the code judgment program is more than 45 times, if so, terminate The program runs and records the "Flag" key value of 1. The main code is as follows: if (REG-> Readinteger ("count")> 45) {Application-> MessageBox ("This program has exceeded 45 times! / N Program is about to close ...", "Result", MB_OK) Reg-> WriteInteger ("Flag", 1); Application-> Terminate ();} 3. Setting the deadline (such as the deadline is Aug 2, 2001) This method does not need to modify the registry, in the main window The following code can be added during the onCreate event process: // Define the date-type variable (object) TDATE EndDate, currentdate; // Set the date separator DateSeparetor = '-'; // Setting the date expression format shortdateformat = "YYYY / mm / dd "; currentdate = DATE (); // Date conversion enddate = stratodate (" 2001-08-31 "); if (currentdate.val> enddate.val) {Application-> MessageBox (" has exceeded the deadline, this program It is no longer available! / N will turn off the program ... "," Result ", MB_OK); file: // reg-> WriteInteger (" flag ", 1); Application-> Terminate ();} 4. Limit each time Time to use (such as 50 minutes) This method does not need to modify the registry, during the TTIMER component's ONTIMER event, you can detect whether the system current time and the program startup time exceeds 50 minutes.

转载请注明原文地址:https://www.9cbs.com/read-3831.html

New Post(0)