Home > C# > C# Starting Application on Windows Startup

C# Starting Application on Windows Startup

There will be situations where we require to automatically load application on Windows start up. Most commonly used ways are

  1. Placing application shortcut on “Startup” folder
  2. Environment.GetFolderPath(Environment.SpecialFolder.Startup)
    will give the Path of start up folder, once you have this
    do a File.Copy of your application shortcut
    
  3. Making entries in Registry
  4. //This registers this application to run for current user
    //If you want to have this start for all users then change
    //CurrentUser with LocalMachine
    //Registry.LocalMachine.OpenSubKey(...
    private void RegisterStartupApplication()
    {
        RegistryKey regKey = Registry.CurrentUser.OpenSubKey
                ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        regKey.SetValue("MyApplicationsName", Application.ExecutablePath);    
    }
    
    private void UnRegisterStartupApplication()
    {
        RegistryKey regKey = Registry.CurrentUser.OpenSubKey
                ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        registryKey.DeleteValue("MyApplicationsName");
    }
    
Advertisements
Categories: C#
  1. AK
    April 17, 2012 at 7:44 AM

    These two are more commonly used approaches. But they have a problem with them.

    1. Many cases users may not want to keep it in startup folder, then what should be done.
    2. Win 7 is somewhat quirky. During reboots, it has a tendency to revert the registry settings sometimes. In that case, if you set the application as a shell, it may not work. As the registry itself will be reverted.

    Have you tried writing a windows service which can be passed a list of apps to start as soon as the system reboots ?. That approach may work.

    • A.m.a.L Hashim
      April 17, 2012 at 10:33 AM

      Creating a windows service to tackle requirement is the best approach. I haven’t tried that yet, but I don’t see any blocker for following that path. Thanks

  2. Patrick
    October 30, 2013 at 6:10 PM

    @Amal there is a huge blocker for stating applications from a service starting from Vista: A service may not start processes who try to show a user interface in the user’s desktop session. So for example you couldn’t start Word that way. Google for Interactive Service Detection. That problem is what got me to this page while findings a way around my problem 🙂

    • A.m.a.L Hashim
      October 30, 2013 at 6:15 PM

      Thanks for the inputs Patrick.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: