In fact, there are many ready-made software on the Internet. They can help you do some of the time control of shared software, such as 30 days, trial 100 times. Software written to Taiwanese now needs a trial version, because it is traditional, I want to do it online existing software << Phantom Encryption System >>, but the machine is killed in the next operation, I am newly installed with traditional 2000. Later, I thought I wrote it myself. The other party asked for 90 days, 150 times. I also want to use time synchronization methods (I have been implemented before), but considering some problems, think about there is not much necessary, anyway, this is not an important thing, it will give up. My idea is like this. When installing the software, get the system time, encrypt (I use DES), write to the registry, write into the INI file (both hands ready, strengthen security). Both files and registry are written to the same data, and if they are different, the software cannot run, and the write entry includes the installation time, the number of uses, and the usage time. Software runtime check time, file, and registry are written, if there is a problem, do not let reuse, and delete some data of the INI file and the registry (not all deleted to prevent it from installing again) . The application method is not safe, just to cope with general requirements, if high security is required, use other methods.
The following code simply demonstrates the processing of each part:
First, write encrypted data at installation:
(Encryption here uses controls)
Des-> GenerateKey ("NEOWARTON 20030731"); TDATETIME * D = New TdateTime (Date ()); Ansistring Times, Date, FileName ;; Char Dir [256];
Times = "0"; date = datetimetostr (* d);
Times = des-> EncryptString (Times); Date = des-> encryptString (date); // install = des-> encryptstring (date); ansistring s = times date; outputdebugstring (s.c_str ());
Filename = "// mysoft.ini"; getSystemDirectory (Dir, SizeOf (Dir)); filename = DIR FileName;
IF (fileExists (filename)) {Application-> Terminate (); // if the ini file is alread exists exit;} else {tinifile * ini = new tinifile (filename); Ini-> WritestRing ("setup", "Times ", Times); INI-> Writestring (" setup "," date ", date); ini-> Writestring (" setup "," install ", date)
Delete ini;
// Write Register
Tregistry * reg = new Tregistry (); reg-> rootkey = HKEY_LOCAL_MACHINE; if (REG-> Keyexists ("// Software // Microsoft // Windows // CurrentVersion // Mysoft)) Application-> Terminate (); / / if the key exists, terminate reg-> Openkey ("// Software // Microsoft // Windows // CurrentVersion //Mysoft", true); REG-> Writestring ("Warning", "Dot Modify these Items! Otherwise, Your System Will Not Run! NEOWARTON2003XIAN "); REG-> Writestring (" Times ", Times); REG-> WritestRing (" Date ", Date); Reg-> WritString (" Install ", Date); REG-> CloseKey (); delete reg;}
Second, add the following code in Install Shield when installing:
Lauchapp (SupportDir ^ "Test.exe", "") // TEST is omitted for the EXE file of the above code
Third, when the application starts:
BOOL RT; TFORM1 * FM1 = New TFORM1 (NULL); // Trial version pop-up window, click on the trial return judgment result fm1-> showModal (); rt = fm1-> try_time; // has explende FM1; IF ( {MessageBox (null, "¥'' õ ¹ ¥ §'£ ¹¹ ¡¡£ £ £ ¹ ¡¡¥ ¸ª ¹ © ¨»» ¸ A/2ðáê¶r ¥ ¿|ª ª © i / N / n http://www.xxxxx.com "," ¯ «2 þ ¥ D33 ¥ ô ¨¤õ ¤õ¤õ¤õ", MB_OK MB_ICONITIONS; Application-> Terminate (); // ã3¬à3 ¥ îμ { §Ç return 0;}
Fourth, the user clicks the trial button, returns whether the expired BOOL value:
// read the encrypted ini file in the system directory to read the time and date //iff flynote exist, return false, if the time and date wrong return false;
// read data and then time from the register, Where the data is also encrypted
Char Dir [256]; Ansistring FileName = "// mysoft.ini"; GetSystemDirectory (Dir, Sizeof (Dir));
// the ini fils is in the system directory filename = dir filename; if (! fileexists (filename)) {Application-> MessageBox ("§ªo ¨t2¹¹¹ ¥» ¥ ó¶i|¤¤f «DªK × ï¡¡W ¸ ¤ £ £ à|a ¨ï ¥ ¡¡/ n / n "," ¯ «2 þ ¥ d //4 ¤õ/4¤õ¤õ¤õ", MB_ICONERROR); hwnd h; h = findwindow (null, "DNAALARM") ;: SendMessage (H, WM_Close, 0); OutputdebugString ("Go Here"); this-> try_time = true; close (); return;} tinifile * ini = new tinifile (filename); Ansistring Times, DateTime, InstallDay;
Times = INI-> ReadString ("Setup", "Times", ""); DateTime = Ini-> ReadString ("Setup", "Date", ""); InstallDay = INI-> ReadString ("setup", " Install "," "); getthepara ();
Ansistring TT = TIMES_REG "| DateTime_reg " | DateTime_reg; Ansistring TTT = Times "| DateTime " | InstallDay;
IF ((TIMES_REG! = Times) || (DateTime_reg! = DATIME) || (InstallDay! = DATETIME_REG)) {this-> try_time = true;} else // ------------- ----------------------- {
Des-> GenerateKey ("NEOWARTON 20030731"); Times = des-> DecryptString (Times); DateTime = des-> DecryptString (datetime); installDay = des-> decryptstring (installday);
Times_reg = des-> DecryptString; DateTime_reg = des-> DecryptString (DateTime_reg); installDay_reg = des-> DecryptString (InstallDay_reg);
TT = TIMES_REG "| DATETIME_REG " | DATETIME_REG; TTT = Times "| DateTime " | InstallDay; // |R2å|êà '«| ¤ ¤¤'á Int T = STRTOINT (TIMES); TDATETIME * DT = New Tdate (Date ()); tdatetime * s = new tdate (strtodate); tdatetime * install = new tdate (strtodate (installday));
INT TMP = * DT- * S; INT TMP2 = * DT- * INSTALL; // INT TMP3 = * S- * DT;
IF ((TMP> = - 1) && (TMP <= 90) && (TMP2> = - 1) && (TMP2 <= 90) && (T <150)) {ANSISTRING TIMES_TMP = DES-> EncryptString (Intedoint (TIMES) 1)); Ansistring DateTime_TMP = des-> EncryptString (DateTimetostr (* DT)); INI-> Writestring ("Setup", "Times", Times_TMP); INI-> Writestring ("setup", "Date ", datetime_tmp); putthepara (times_tmp, datetime_tmp); this-> try_time = false;} else {// write wrong time; AnsiString times_tmp = DES-> encryptString (IntToStr (StrToInt (times) 200)); AnsiString datetime_tmp = Des-> EncryptString (* DT 3000)); INI-> WritestRing ("Setup", "Times", Times_TMP); INI-> Writestring ("setup", "Date", DateTime_TMP); Putthepara (Times_TMP, DateTime_TMP); this-> try_time = true;}}
Delete ini;
THIS-> Close ();
Five, INI files:
[setup] Times = INAK6XCTEVW = DATE = XOQVDLA R 2XTL4ZM567CQ == Install = KAP2X5LVCWAXTL4ZM567CQ == (Data has been encrypted) .....
6. The content of the registry is basically the same as the INI file content!
The above code is just a preliminary, if you want to use, you need detailed modification. Because it is a traditional version, some comments are displayed as garbled, I have deleted the comment, the string in the message box is also garbled, you can change it! Please forgive! (Note, this article is just a simple method to meet the simple requirements of some friends, the code just achieve function, there are many problems, I am going to change, there is a good way to come out!) Welcome everyone to prompt good method.