Method for realizing automatic operation of program under C ++ Builder3

zhaozj2021-02-08  257

---- Now there are many application software installations to implement boot automatic operation, which greatly makes it easy for users. I want to envy this feature at the beginning. Can you implement the program automatic run in the program we have written ourselves? The answer is of course affirmative. We can easily do this with C Builder3 from Borland.

---- C Builder3 is a new product launched by Borland in recent years and supports visual design. People who like to use BC3.1 use C Builder3 true light car ripe. Its breakpoint debugging and Watch feature assaided the excellent tradition of BC3.1, and the debugging procedure is very convenient. Many hotkeys are used along the BC3.1 program and it is easy to get started. No wonder it got a praise from many media in the test phase! With a good development tool, you have to cut the topic. First, let's see how the program implements automatic operation in Windows95,98 environments. According to relevant information, there are generally three methods:

---- 1, using the "Start" program item in the Start menu. Any process that dragged into the program item can be automatically run.

---- 2, using the RUN variable in the win.ini file. Edit Win.ini and assign a value for the RUN variable. Such as run = a program, you can make a program automatically run.

---- 3, using the registry. Implement the program automatic operation by modifying the relevant items in the registry.

---- Look, the first method is the easiest to implement. Since the so-called "start" program menu is actually a special file in a special directory. Its directory is generally under C: / Windows / Start Menu / Program. The directory of the "Start" program item is generally c: / windows / start menu / programs / boot. This program can implement the program automatic run as long as you copy your own copy to this directory. However, there is a problem here. If you have a special case, the directory of the "Start" program is not in the ideal directory? Automatic operation is obviously unable to implement. To solve this problem, we can use the registry to get the information. Under Registry HKEY_USERS / .DEFAULT / SOFTWARE / Microsoft / Windows / CurrentVersion / Explorer / Shell Folders, you can know the exact directory of the "Start" program item. For the operation of the registry, C Builder3 provides the Tregister class, which is very convenient to use. For specific introduction to the Tregister class, you can refer to the online help of C Builder3, which is not described here. The procedure is as follows:

Tregister * test;

Test = new tregister ();

TEST-> rootkey = hkey_users;

IF (Test-> Openkey (". default // Software // Microsoft / Windows // CurrentVersion // Explorer // Shell Folders", False))

Path = TEST-> ReadString ("startup"); // Get the "Start" program entry exact directory

DELETE TEST;

---- For the second method, the key is to read and write to Win.ini. Win.ini is initially configured for Windows to store it under the system directory. The system directory can be obtained by reading the SystemRoot worth in the registry hkey_local_machine / software / windows / currentversion. The program own storage path can be obtained using the Exename variable of the Application class in C Builder3. With the TiniFile class provided by C Builder3, we can easily operate the INI file very conveniently. The procedure is as follows: Tregister * test;

Tinifile * inIfile;

Test = new tregister ();

TEST-> rootkey = hkey_local_machine;

IF (Test-> OpenKey ("Software // Windows // CurrentVersion", False))

Path = TEST-> ReadString ("SystemRoot"); // Get a Windows System Directory

DELETE TEST;

Path = Path "//win.ini"; // Get the full path to Win.ini

InIfile = New TiniFile (PATH);

InIfile-> WriteString ("Windows", "Run", Application-> Exename);

// run = execution file name

DELETE INIFILE

---- For the third method, it is most concealed. If you don't understand the registry, you can't do it. All program items under the registry hkey_local_machine / software / microsoft / windows / currentversion / run can be automatically executed by Windows. Therefore, we can implement automatic execution functions by adding new program items. The procedure is as follows:

Tregister * test;

Test = new tregistry ();

TEST-> rootkey = hkey_local_machine;

IF (Test-> OpenKey ("Software // Microsoft / Windows // CurrentVersion // Run", FALSE))

TEST-> WritestRing ("My Program", Application-> Exename);

DELETE TEST;

---- How? Use the C Builder3 implementation program to automatically run enough. With the Tregister class of C Builder3, we can easily implement read and write to the registry, thereby completing a lot of powerful features. The use of TiniFile classes can easily implement read and write operations for the INI file, which is quite effective for saving your own programs. Use C Builder3 to play with C Builder3, it feels good!

Fang Zhihong Wang Wei (East China Institute of Electronic Engineering)

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

New Post(0)