How to automatically launch a Windows app when a user logs into their computer

It took me a while to figure out the best way to automatically start a windows app when a user logs into their computer. There were a bunch of suggestions on StackOverflow, but the registry key approach worked best for me. Example source is on GitHub and walkthrough is below. Hope this saves you some time.

Jon

1. Create Windows app. Create Installer app using the Microsoft Visual Studio Installer Projects extension

2. Open up the build config manager and make sure the Installer project is building as well.

3. Right click on the Windows project. Add Item –> Installer class

4. In the Installer class override both the Commit and Uninstall methods. Replace “windows-startup-example-app” with the name of your app and change the exe name.

public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.SetValue("windows-startup-example-app", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\windows-startup-example-app.exe");
}
}
public override void Uninstall(System.Collections.IDictionary savedState)
{
base.Uninstall(savedState);
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.DeleteValue("windows-startup-example-app", false);
}
}

5. Right click on Installer project and view Custom Actions

6. Right click Commit and select Add Custom Action

7. Click Application Folder and Add the Primary Output

8. Repeat Steps 6 & 7 for Install and Uninstall. It should now look like this:

9. Open RegEdit and navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

10. Go back to VS and Right click on Install project and install app.

11. Go back to RegEdit and you should now see the app.

12. Log out of computer and log back in. You should now see the app automatically start up.