The NeceMoon | Launching Your Application At Windows Startup Without Hacking The Registry

Launching Your Application At Windows Startup Without Hacking The Registry

by necemon 5. June 2011 01:15

In this post, I will show you two methods to configure your .NET applications so that they would launch as soon as Windows starts. These two methods do not require any change to the registry, hence you don't need to worry about cleaning up that database if the user uninstalls your application.


First method:

From the Windows Installer Deployment Project, follow these steps:

In the File System of the project, add a special folder called User's Startup Folder.

Then a shortcut of the project output is created in the Application Folder and renamed to give it a more meaningful name.

We cut (CRTL + X) the shortcut we just created and paste it (CRTL + V) in the User's Startup Folder.


Second method:

The other solution is to trigger an automatic start from within the code of the application. To do this, I created an activation function, and another one for deactivation.

N.B.: For this code to work, you will need to add a reference to the Windows Script Host Object Model assembly in your project.

The activation function can be written as follow:

public void EnableApplicationStartup()
    string shortcutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "MyShortcut.lnk");
    if (System.IO.File.Exists(shortcutPath)) return;
    WshShell wshShell = new WshShellClass();
    IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(shortcutPath);
    shortcut.TargetPath = Assembly.GetEntryAssembly().Location;
    shortcut.Description = "My first shortcut";

Here is the deactivation function:

public void DisableApplicationStartup()
    string shortcutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "MyShortcut.lnk");
    if (!System.IO.File.Exists(shortcutPath)) return;



[Translated from a contribution by Holty Sow]

Tags: , , ,

English | Technical


I am Necemon Yai. I am a Software Engineer and a Digital Artist. Let's keep in touch via Twitter, LinkedIn or Facebook.

Je suis Necemon Yai. Je suis un Ingénieur en Informatique et un Artiste Numérique. Restons en contact via Twitter, LinkedIn ou Facebook.