andrewWinn
andrewWinn

Reputation: 1786

Forcing Winforms install to make application to start when windows starts

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.

Upvotes: 4

Views: 2539

Answers (5)

ChrisF
ChrisF

Reputation: 137108

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.

Upvotes: 2

Jay Riggs
Jay Riggs

Reputation: 53595

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

Upvotes: 1

csharptest.net
csharptest.net

Reputation: 64218

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.

Upvotes: 1

Chris Ballance
Chris Ballance

Reputation: 34337

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/

Upvotes: 7

Aaron Daniels
Aaron Daniels

Reputation: 9664

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.

Upvotes: 1

Related Questions