views:

76

answers:

2

I've been investigating "how should a modern windows c++ application register its file types" with Windows (see http://stackoverflow.com/questions/2828637/c-how-do-i-correctly-register-and-unregister-file-type-associations-for-our-ap).

And having combed through the various MSDN articles on the subject, the summary appears to be as follows:

  1. The installer (elevated) should register the global ProgID HKLM\Software\Classes\my-app.my-doc[.version] (e.g. HKLM\Software\Classes\TextPad.text)
  2. The installer also configures default associations for its document types (e.g. .myext) and points this to the aforementioned global ProgID in HKLM.
    NOTE: a user interface should be provided here to allow the user to either accept all default associations, or to customize which associations should be set.
  3. The application, running standard (unelevated), should provide a UI for allowing the current user to set their personal associations as is available in the installer, except that these associations are stored in HKCU\Software\Classes (per user, not per machine).
  4. The UN-installer is then responsible for deleting all registered ProgIDs (but should leave the actual file associations alone, as Windows is smart enough to handle associations pointing to missing ProgIDs, and this is the specified desired behavior by MSDN).

So that schema sounds reasonable to me, except when I consider #4: How does an uninstaller, running elevated for a given user account, delete any per-user ProgIDs created in step #3 for other users?

As I understand things, even in elevated mode, an uninstaller cannot go into another user's registry hive and delete items? Or can it? Does it have to load each given user hive first? What are the rules here?

Thanks for any insight you might have to offer!

EDIT: See below for the solution (My question was founded in confusion)

+1  A: 

As far as I know, settings in other user accounts are usually just left there. This is not limited to file type associations.

It would be nearly impossible to delete the settings from all user accounts, because some might be roaming profiles on a domain that is not currently connected, or that the local administrator has no access to.

Thomas
If you want to be *really* nice, replace the app executable by a "per-user-uninstaller". When run - eg. by a user trying to use your now-removed app - they'll clean up the users settings.
MSalters
How would you make that happen? If during install, I can modify the current user's registry, and install the uninstaller // but I cannot setup an uninstaller for other user accounts at that time, anymore than a single uninstaller can modify other user accounts at the tail end, no?
Mordachai
@MSalters: That would leave you with a dangling uninstaller that would never be removed.
Thomas
@Mordachai : You don't need to "setup" the uninstaller. Assume that foo.exe can open .foo files. This is a per-user setting. So, when you uninstall the Foo app, you remove the original foo.exe and rename your uninstaller to foo.exe. @Thomas. Yes. A single dangling exe on disk is preferable to multipe dangling registry entries. For instance, it will never create user errors. Leaving a dangling `.foo` extension in the registry will.
MSalters
@MSalters - Clever idea. I realized, just rereading the comments this morning... there's no need. My question is rooted in confusion. If per-user only overrides the file associations (i.e. .foo maps to what), but does NOT create new ProgIDs, then there is nothing to clean up from the per-user settings at all. So my question is moot.
Mordachai
A: 

I just realized: What MS wants us to do is to have per-user override the file mapping itself - i.e. .foo -> what? NOT create any progIDs, which should only be created by the installer, which are deleted by their uninstaller, so no "dangling ProgIDs" - only "dangling file mappings" which map to a missing ProgID, which MS explicitly states is OK.

Before install: HKCR\.txt -> HKCR\txtfile (global)

After install: HKCR\.txt -> HKCR\MyEditor.text.1 (global)

A user decides they want to map .txt files to TextPad instead: HKCU\Software\Classes\.txt -> HKCR\TextPad.txt (this user only, globally still .txt->MyEditor.text.1)

After uninstall: HKCR\.txt x-> HKCR\MyEditor.text.1 (global, but the key HKCR\MyEditor.txt.1 has been deleted)

And the one user who overrode their value is still okay because wherever their individual copy of .txt points is either valid or not, either way, Microsoft handles it.

I hope that helps others...

Mordachai