tags:

views:

100

answers:

2

I'm teaching someone better practices by refactoring a large project they worked on. One of the current functions of the application is the option to have the application start when Windows starts. Currently, the application accomplishes this using the Run registry key:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

I haven't had the need to implement this feature before, so I'm not sure if this is the "best" way to make an application run at startup. Is access to this registry key something that most users will have?

Would it be better instead to place a shortcut to the application in the folder indicated by Environment.GetFolderPath(SpecialFolder.Startup)? It seems that creation of shortcuts from .NET is kind of hacky, so I'm not certain this is better.

edit:

From current responses it's clear that I left out something important. The "start with windows" behavior is optional and part of the options dialog for the program. It's valid (though silly) for the user to toggle it several times while using the application.

+5  A: 

It all depends on the intention of the application. If the application is meant for power users, includes an easy way within the program to change that registry key, or is meant as an enterprise solution that shouldn't be removed, the registry key choice is a good one. If it is meant for average users, and has no easy way to change that setting, go with the Startup folder.

In your specific case, using a registry key is perfectly fine, thanks to being able to alter things easily.

Brisbe42
`msconfig` provides an admin interface for enabling/disabling programs that run at startup
wefwfwefwe
The option to enable or disable the behavior is prominently displayed in the application. I'm going to add this information to the original question because I hadn't realized it was important.Would you agree that the registry is an accepable solution so long as the user has the ability to configure it through the application?
OwenP
A: 

If your deployment is done through an MSI then there is a way to do it from the configuration of the deployment project through visual studio.

This of course ultimately places a shortcut to your application in the User's Startup Folder which you could do as well programatically in the case that you don't deploy using an MSI.

Konstantinos