Sunday 20 December 2015

Run application on windows startup in C#

Small line of code can make our application auto run after windows startup.

using Microsoft.Win32;

void setasStartup(bool res)
        {
            RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            if (res == true)
            {
                registryKey.SetValue("URL_watcher", Application.ExecutablePath);
            }
            else
            {
                registryKey.DeleteValue("URL_watcher");
            }
        }