views:

377

answers:

5

How do I force a windows application, with a setup project being added to it, to install so that it will start everytime someone logs into windows?

Edit: I'm aware of the registry settings, but specifically, I am looking for a solution which will allow for the installer to set the registry values.

A: 

You can add a shortcut to your winforms program in the Startup Folder. The setup project's File System is where you need to look.

Aaron Daniels
+5  A: 

Open your registry and find the key

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run].

For each program you want to start automatically create a new string value using a descriptive name, and set the value of the string to the program executable.

For example, to automatically start Notepad, add a new entry of

"Notepad"="c:\windows\notepad.exe".

Remove a startup application If you're trying to remove a program and can not find it in the StartUp folder (usually C:\WINDOWS\Start Menu\Programs\StartUp), then it may be launching from one of the registry keys below. To remove it, delete the value associated with the program you want to remove.

[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce]
[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows]

Source: http://www.pctools.com/guides/registry/detail/109/

Chris Ballance
+1  A: 

Technically you can't make a WinForms app start when "windows is started"; however, you can start it when someone logs into Windows. To perform that you do one of the three:

  1. Place a shortcut in the current user's startup folder.
  2. Place a shortcut in the the "All Users" startup folder.
  3. Write a registry key to HKLM/Software/Microsoft/Windows/CurrentVersion/Run

Update: as Chris points out I missed the HKCU path.

csharptest.net
right, so how do I configure the installer to support this?
andrewWinn
Easy way is to create an installer util class, see http://msdn.microsoft.com/en-us/library/system.configuration.install.installer.aspx
csharptest.net
+1  A: 

If you really need your application to start when Windows is started as opposed to when someone logs in you need to create it as service and on install set the service to "Automatic".

There are many places on the web that will give you information about this:

are the first three I found, but do some research and find the resource that works for you.

UPDATE

I see from the updated question that the requirement is for the program to run when someone logs in so this answer is (to a certain degree) redundant. However, I will leave it here in case someone wants to go the service root.

ChrisF
+1  A: 

To run everytime Windows starts you should build your program as a Windows Service (or perhaps lauch it from a Service).

Jay Riggs