Tag Archives: registry
Start application at Windows startup with C#
The following snippet will allow you to add your application in the registry so it will launch when Windows start. Alternative you can use Environment.SpecialFolder.Startup
to place a shortcut of your application in the startup folder which will have the same effect.
Note that this snippet will add an entry in HKEY_CURRENT_USER
which means the program will only launch at startup for the user that is currently logged in when you run the code. If you want your program to run at startup for all users you will need to use HKEY_LOCAL_MACHINE
instead but keep in mind that you will require administration rights in order to do that.
Register program to start with Windows:
1 2 3 4 5 6 7 | public static void AddApplicationToStartup() { using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { key.SetValue("My Program", "\"" + Application.ExecutablePath + "\""); } } |
Stop program from starting with Windows:
1 2 3 4 5 6 7 | public static void RemoveApplicationFromStartup() { using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { key.DeleteValue("My Program", false); } } |