WinForm Application Boot Boot setup method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.