28.6.11

Run application on Windows Startup

Hey,

In this post i'm gonna show you how to run an application on Windows Startup by adding the application to the registry in the right place.

First of all add this using:
using Microsoft.Win32;

So we can accesss the Registry of the computer.
Define a RegistryKey:

// The path to the key where Windows looks for startup applications
RegistryKey rkApp=Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true);

You can change the CurrentUser to LocalMachine if you want your application to run on startup for all users.

Create the registry key and close the registry key handler:

rkApp.SetValue("notepad", @"C:\WINDOWS\system32\notepad.exe"); // Make notepad run on startup                 
rkApp.Close(); //Close the RegistryKey handler
Now notepad will always run when you turn on your PC :P


Nice registry locations can be found here: Registry Autostart Locations

Have fun tweaking the registry :)