C # Implementation of software starting from the principle and code

Source: Internet
Author: User

1, the software self-starting principle

The principle of software self-starting to chat from the Windows registry, under the Windows operating system, there are mainly 2 folders and 8 key key entry control program's self-launch, this part of the detailed introduction can be see blog http://www.cnblogs.com/fukajg/ Archive/2012/08/10/2631250.html. This program is implemented through the "Run" key value, the Run key is the most common from the Start program place. It is located in [Hkey_current_user\softvvare\microsoft\windows\currentversion\run] and [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft \windows\ CurrentVersion\Run]. Where the "Run" key value under the [HKEY_CURRENT_USER] root key is run immediately after the "Run" key value under [HKEY_LOCAL_MACHINE], but the two key values are loaded before the Startup folder.

2. Introduction to C # related classes and methods

The Application.executablepath property can get the path to the executable file that launches the application, including the name of the executable file; the Registry.localmachine field contains the configuration data for the local computer, which reads Windows registry base key HKEY_LOCAL_MACHINE; The Registrykey.createsubkey method creates a new subkey or opens an existing subkey for write access; RegistryKey.SetValue sets the specified name/value pair; The Registrykey.deletevalue method (String, Boolean) is the specified value that is removed from this item.

In 3 programming practice, the CheckBox control of the CheckedChanged event is set, in the Setup boot, the start of the software JK information written "Run" key value; Cancel boot, remove the software JK Information "Run" key value in the value.

3. C # Programming implementation

 private void Checkbox1_checkedchanged (object sender, EventArgs e) {if (checkbox1.checked)                  Set boot from startup {MessageBox.Show ("Set boot from boot, need to modify registry", "Prompt");                string path = Application.executablepath;                RegistryKey rk = registry.localmachine; RegistryKey RK2 = rk.                CreateSubKey (@ "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); Rk2.  SetValue ("Jc", Path); Note that JC is the software name RK2 for the self-starter software.                Close (); Rk.            Close ();                  } else//Cancel boot from boot {MessageBox.Show ("Cancel boot from boot, need to modify registry", "hint");                string path = Application.executablepath;                RegistryKey rk = registry.localmachine; RegistryKey RK2 = rk.                CreateSubKey (@ "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); Rk2.                DeleteValue ("Jc", false); Rk2.                Close (); Rk.            Close (); }          }

C # Implementation of software start-up principle and code

Related Article

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.