简体   繁体   中英

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.

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/

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.

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.

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.

要在每次Windows启动时运行,您应该将程序构建为Windows服务(或者可能来自服务)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM