Sometimes, when we install a program, it will ask whether to enable the program to automatically start with the operating system. The virus self-start is no different from the general application, its implementation principle also starts from the Windows registry.
In fact, Windows automatically loads programs based on two folders and eight core registry subkeys. When Windows 2000/XP is started, it searches for self-starting programs from the following 10 addresses.
1. "Boot" folder-the most common self-Start Program folder. It is located in the "Documents and Settings → user → start → program" directory of the system partition. Here "user" refers to the username you actually log on to. If you log on as an administrator, it should be "Administrator ".
2. the "all users" self-Start Program Folder-this is another common self-Start Program folder, which is usually located in the "Documents and Settings> All Users>" start "menu> program" directory where the system disk is located. As mentioned above, the "Boot" folder runs the self-starting program of the login user, and the program in the "All users" folder starts automatically regardless of the owner.
The above two are the places where the user can easily find the self-starting program to load. In addition, there are several key values in the registry used to load the self-starting program.
3. "LOAD" key value-a deeply buried registry key value in [HKEY_CURRENT_USER/software/Microsoft/Windows NT/CurrentVersion/
Windows/load].
4. "userinit" key value -- it is in [HKEY_LOCAL_MACHINE/software/Microsoft
/Windows NT/CurrentVersion/Winlogon/userinit] is also used to load programs when the system starts. In general, the primary value is userinit.exe. Because the values of this subkey can be separated by commas (,), you can add other programs to the key value values.
5. "Explorer/Run" key value -- different from "LOAD" and "userinit, "Explorer/Run" exists in both the [HKEY_CURRENT_USER] and [HKEY_LOCAL_MACHINE] root keys. Its location in the two root keys is [HKEY_CURRENT_USER/
Software/Microsoft/Windows/CurrentVersion/
Policies/Explorer/run] and [HKEY_LOCAL_MACHINE
/Software/Microsoft/Windows/CurrentVersion/
Policies/Explorer/run].
6. "runservicesonce" subkey-it loads the service program before the user logs on and other registry auto-start keys load their respective programs. This sub-key also exists in [HKEY_CURRENT_USER/softvvare/mcrosoft
/Windows/CurrentVersion/runservicesonce] and [HKEY_LOCAL_MACHINE/software/Microsoft
/Windows/CurrentVersion/runservicesonce.
7. The "runservices" subkey is loaded immediately after runservicesonce and before the user logs on. Located in [HKEY_CURRENT_USER/software/Microsoft/
Windows/CurrentVersion/runservices] and [HKEY_LOCAL_MACHINE/software/Microsoft/
Windows/CurrentVersion/runservices.
8. "runonce/setup" subkey -- its default value determines the program loaded after the user logs on. Under the two root keys [HKEY_CURRENT_USER] and [HKEY_LOCAL_MACHINE. The locations are [HKEY_CURRENT_USER/software/Microsoft/
Windows/CurrentVersion/runonce/setup] and [HKEY_LOCAL_MACHINE/software/Microsoft/
Windows/CurrentVersion/runonce/setup].
9. "runonce" subkey-many self-start programs use runonce subkeys for automatic loading. This subkey is located in [HKEY_LOCAL_MACHINE/software/
Microsoft/Windows/CurrentVersion/runonce] and [hey_current_user/software/Microsoft/Windows/
CurrentVersion/runonce]. The "runonce" sub-key located under the [HKEY_LOCAL_MACHINE] Root Key loads the associated program after the user logs on and the run key value of other registries before loading the program. The "runonce" sub-key located under the [HKEY_CURRENT_USER] Root Key is loaded after the operating system completes other registry run sub-keys and programs in the self-starting folder. If your system is Windows XP, you can go to [HKEY_LOCAL_MACHINE/software/
This subkey is found in Microsoft/Windows/CurrentVersion/runonceex.
10. "Run" key value-so far, the run key value is the most common place for self-starting programs. Its location is in [HKEY_CURRENT_USER/softvvare
/Microsoft/Windows/CurrentVersion/run] and [HKEY_LOCAL_MACHINE/software/Microsoft/Windows/
CurrentVersion/run]. The "run" key value under the [HKEY_CURRENT_USER] Root Key is followed by the "run" key value under [HKEY_LOCAL_MACHINE], but both key values are loaded before the "Start" folder.
We can see from the above that when writing a program, if we want to enable it, we can start from the above 10 aspects, understand the principle, and implement it easily, I wrote a small program and still implemented it using C. The source code is for your reference.
// Createrun. cpp
# Include <windows. h>
# Include <stdio. h>
# Include <stdlib. h>
# Include <conio. h>
Int createrun (void)
{
Hkey;
Const char * pval = "hwhpapp.exe ";
If (regopenkeyex (HKEY_LOCAL_MACHINE,
"Software // Microsoft // windows // CurrentVersion // run ",
0, key_write, & hkey )! = Error_success)
Return-1;
If (regsetvalueex (hkey, "hwhpapp", 0, REG_SZ, (const unsigned char *) pval, strlen (pval) + 1)
! = Error_success)
{
Regclosekey (hkey );
Return-1;
}
Regclosekey (hkey );
Return 0;
}
Void main ()
{
If (createrun ()! = 0)
Printf ("can't create run! /N ");
Getch ();
}