Search code examples
c#winformsinstallationregistry

Start application at when windows Starts


I have checked some other examples.

I am working on a WinForm. & now i am going to create its installer.

i want to start the software when windows starts & trying to use the following code.

RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());

But i am confused that where to put this code. i don't want this code executed every time when my application starts as it will executed once when the software is installed.

shall i put check on form_Load() if the regkey is absent, & if yes then add this value to the Run.

is it correct ? i don't want to give an option to the user & i want to start this application at the startup compulsorily.

Thanks.


Solution

  • You can create your customAction class for your installer like this: http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx#Y0

    Once you have this class, put your registry code in the commit section. Now, whenever your application will be installed, your application will be added to registry to run at startup.