views:

1813

answers:

5

I am creating a program in c++, which I want to be able to have the option to have users let it auto start in windows. So when a user starts his computer, windows will auto start this program. I have read stuff about modifying the registry or putting it in the startup folder, but what would be the best "clean" way to do this?

+12  A: 

Startup folder is clean enough.

Gives the user the possibility to remove it if needed.

Gamecat
Be aware that if you do something like this, instead of running a service, that your app better be able to be run by more than one user at a time.
Eclipse
The OP didn't say it was a service, Josh. In fact, he specifically provided indications that it wasn't. You are right about supporting multiple users in different desktop sessions, though.
Ken White
Gamecat: Excellent response. Much better to do it properly in the Startup folder than mucking around in the registry. The Run entry in the registry is better used for system-type utilities, IMO. You get my vot. :-)
Ken White
Yeah, I really hate it when something starts automatically and I have to search the registry to keep it from running again. Some developers act as if they own your machine.
Gamecat
+3  A: 

Depending on whether you're executing an all-user or per-user install, put it in the Startup folder for All Users or the per-user Startup folder. The Startup folder you see in the menu is the merger of both, but non-admin users cannot remove the entries coming from the All-user part.

You actually don't have to do anything for this, though. Users can copy your normal shortcut to the Startup menu themselves. Hence, any program can be an auto-startup program. Doesn't need to be C++ at all.

MSalters
+4  A: 

There are many ways to autostart an application, but the easiest, most common and IMO best are:

  1. Put a shortcut in the autostart folder
  2. Add an autostart entry to the registry (Software\Microsoft\Windows\CurrentVersion\Run)

The end result is the same for both. I believe the registry way is executed earlier in the logon process than the startup way, but I am not certain. It does not make any difference for most cases anyway. I prefer the registry, but that is personal taste. You can create and delete the registry key or the shortcut programatically in your app.

With both options you can use either one setting for all users (All User startup folder, or under HKLM key in the registry) or user specific (user startup folder or under HKCR key).

In general it is better to use the per user options, because you can be certain to have writing privileges in those areas; and every user on the computer can have his/her own setting.

Treb
A: 

You can register it as a windows service.You can use "Qt Solutions" for easily making an application as windows service.

Qubeuc
A Windows service is not in any way the same as what the OP asked. Try to post answers that actually apply to the topic at hand.
Ken White
He can make a batch file to deploy application as a service or undeploy it.
Qubeuc