First, the principle
Programs that require a boot-up need to write their startup program's path to the folder specified in the registry.
Ii. means of realization
Method 1: Configure when you build the installer;
Method 2: Dynamically Configure the program while it is running.
Third, configure when you build the installer
1. Right-click the Setup editor and from the View menu, select Registry. Open the key "HKEY_CURRENT_USER" → "software" in turn, such as:
2. Right click on "Software" key → "New (N)" → "Key (K)" To create "Microsoft" key.
3, such as Step 2 way to create the "Windows" key → "currentversion" key → "Run" key.
4. Right-click Run and create a new string value. Name the key on the right (which cannot be duplicate in the registry), and specify its value in the property, as shown in the following:
Note: [TARGETDIR] represents the installation path in the program. Iv. dynamic configuration at program run time
When the program is running, it is implemented by invoking the following method to start the boot. You need to reference the namespace Microsoft.Win32.
/// <summary> ///Modifying a program's key values in the registry/// </summary> /// <param name= "Flag" >1: Boot up</param> Private voidStartUp (stringflag) { stringPath=Application.startuppath; stringKeyName = path. Substring (path. LastIndexOf ("\\") +1); Microsoft.Win32.RegistryKey Rkey= Microsoft.Win32.Registry.CurrentUser.OpenSubKey ("Software\\microsoft\\windows\\currentversion\\run",true); if(Flag. Equals ("1")) { if(Rkey = =NULL) {Rkey= Microsoft.Win32.Registry.CurrentUser.CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run"); } rkey.setvalue (KeyName, Path+@"\peisdoctorhz.exe"); } Else { if(Rkey! =NULL) {Rkey.deletevalue (KeyName,false); } } }
Note: The program's startup item is set to HKEY_CURRENT_USER. If you want to change to HKEY_LOCAL_MACHINE, simply change the CurrentUser to LocalMachine, i.e.
Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey ("software\\microsoft\\windows\\ Currentversion\\run");
WinForm Application Boot Boot setup method