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