views:

190

answers:

3

I have an application that is installed per-machine (since it uses a service). One part of the application is a system tray application that allows the logged-in user to monitor the service operations. I'm trying to figure out how to best install this monitor application.

Each individual user should be allowed to configure whether or not he/she wants to run the monitor application at login. This means that the HKLM/Software/Microsoft/Windows/Run key is out - this only allows configuration for all users.

There is of course the corresponding HKCU-key, however if one simply installs to this key, it will only be for the user that installs the application.

The SO question http://stackoverflow.com/questions/882123/launch-app-on-startup-for-all-users-but-also-allow-per-user-setting-windows refers to the technique of simply having a user-configurable regkey or similar that is checked by the startup-application on to determine whether or not to run. But this means that the application has to start in order to check the value and I would prefer not to bloat the user's startup if I can avoid it. The benefit of this approach is that it is possible to remove the regkey on uninstall.

Another way to accomplish the installation part may be to use Active Setup to create the HKCU regkey on login, this is however undocumented and it seems to me that there is no easy way to uninstall the regkey if the application is uninstalled? I would assume that leaving registry values under the Run key for HKCU might create problems for users after uninstallation.

Is there a standard way to handle per-user startup applications using Windows Installer? Especially with regard to how to uninstall these later on?

A: 

A bit lowtech possibly, but can't you just add a shortcut to the user's startup folder (Start menu/Programs/Startup)?

ho1
How does this differ from using a HKCU registry key with regards to install and uninstall complexity?
villintehaspam
I'm not sure exactly what you mean, but adding shortcuts to the Startup folder I'd say is a fairly standard thing that should be easy enough to do in any setup creator I'd have thought and as far as I remember the last time I did it (years ago so could be wrong) I could set it up to handle the shortcut automatically.
ho1
I'm pretty sure that this will either require you to install for all users, or you could create an advertised shortcut (for all users) that in turn installs the per-user reg key or shortcut. The things that are installed per user will then to my understanding be left behind when the application is uninstalled (at least for any other user than the one performing the uninstall). Am I mistaken?
villintehaspam
Ah, I was thinking that the setup program would be run once per user who wanted to have the monitor (using a refcount to keep track of how many times a file had been *installed* so that the uninstall would work), but if I understand correctly you want to run the setup only once and that automatically install the monitor for all users but then the users can turn it off if they want?
ho1
Yes, precisely! The installer itself needs to be per-machine since it includes a service. Thank you for your input, even though the solution does not appear to be what I am after.
villintehaspam
Well, if you're willing to run the installer once per user, then it would just be that you needed to add a refcount during the installation and if the refcount exists and is over 0, then don't install the service again, and during uninstalls, you decrement the refcount but leave the service in place until the refcount goes down to 0. And the same thing with the actual files for the monitor, only the actual shortcut would be installed/uninstalled except for the first install/last uninstall.
ho1
A: 

I guess you would use the HKLM/Software/Microsoft/Windows/Run in this case. The feature to run the monitor application at startup or not really belongs to the monitor application and not the installer. At log-on the monitor application can detect if this is the first time that the monitor application has been run and present the user with an option to always run the monitor application on start up or not.

Shaji
A: 

Looks to me like you're close to answering your own question. I think you may just need to divide up the responsibility of configures whether to auto-run for each user... er, let me explain:

You can use either a self-healing component of HKCU Registry keys or ActiveSetup to ensure that every user gets the configuration.

If you use an HKCU Registry key, your MSI installer needs to have a component with it's "key file" as an HKCU entry--so thus the first time a new user launches the program, Windows Installer will do a self-heal to write those entries. One of those entries would be your HKCU/Software/Microsoft/Windows/Run value, but not the key value, because you want the users to be able to remove it and not have it come back every time they run the program! You would then want your program to have an option to remove the auto-run value.

If you use ActiveSetup (which I would recommend because it's simple and it "just works"), then you might find it easiest to make a simple app (or VBScript or such) which prompts the user if they want to have the monitor program auto-run. So your ActiveSetup would launch the prompt program/script, and the prompt program would create the HKCU/Software/Microsoft/Windows/Run value or, better yet, just a shortcut in the user's Start Menu\Programs\Startup directory.

ewall
Thank you for your answer, I really appreciate it. From these two alternatives, it sounds as if Active Setup is the way to go, although I am a bit hesitant to use undocumented features. But what about the uninstall scenario? How would I get rid of the reg keys again?
villintehaspam
Essentially, you don't really have an option to clean up HKEY_CURRENT_USER reg keys, and anything you tried to do would just add *more* stuff that you couldn't clean up.So, generally, the installer should be able to remove the HKEY_LOCAL_MACHINE keys and maybe the ones for the logged-on current user, but that's about it.
ewall
If I understand correctly, this basically means that one should never use a reg value in HKCU\Software\Microsoft\Windows\CurrentVersion\Run? Since there would be no way to remove such a key, that would mean that Windows would try to start this application even after it is uninstalled, most likely giving an error message to the user... Which sort of brings me back to square one... :)
villintehaspam
Well, if you do leave behind a Run/RunOnce value in HKCU, it doesn't cause an error... Windows just silently ignores it. (Of course, you are theoretically adding a few milliseconds to the login time, but that's not noticeable.)
ewall
It appears that there is no perfect solution. I've accepted your answer since it is the most informative one. Thank you!
villintehaspam