While creating a windows application, one of the challenges is to make the application run during the Startup menu ie. the application should run as soon as the computer turns on.
In such cases you will have to give a CheckBox in the settings panel of the App that you have created and the CheckBox would say “Run MyApp when Computer Turns On” or something of similar fashion.
There are three methods to do this and they are as follows in the Order of Prefence by developer’s and programmer’s
Three options, in order of preferrence:
1. Add it to the current user’s Startup folder. This requires the least permissions for your app to run, and gives the user the most control and feedback of what’s going on. The down-side is that it’s a little more difficult determining whether to show the checkbox already checked next time they view that screen in your program.
2. Add it to the HKey_Current_User\Software\Microsoft\Windows\CurrentVersion\Run registry key. The only problem here is that it requires write access to the registry, which isn’t always available.
3. Set it up as a windows service. Only do this if you really mean it, and you know for sure you want to run this program for all users on the computer.
Here I will provide solution to the 2nd method
The following is the chunk of code:
public void SetStartup(bool blRealTimeScanOn)
RegistryKey rk = Registry.CurrentUser.OpenSubKey
Based on the value of ‘blRealTimeScanOn’ your .exe file will be either added or removed from the Startup.
Hope this code was useful.