WindowsRegistry::registerFileAssociation() issues


I just gave WindowsRegistry::registerFileAssociation() a try and ran into a couple of issues. It was using HKEY_CLASSES_ROOT, which is typical for an installer, but an application on Windows 7 doesn’t normally have access rights there. So the key creations fail, but there is no real fail path back up to the caller and no UAC warning, etc. to the user.

So I changed it to “HKEY_CURRENT_USER\Software\Classes\”, which would registery associations just for the current user, which would generally make sense for an app.

Also, the command line was basically being stored as “fullpath-to-app %1”, but this means that the command line coming to the application is a little whacked if the file path has spaces, etc. in it. So I changed it to: fullpath-to-app “%1”. The revised function ended up as:

void WindowsRegistry::registerFileAssociation (const String& fileExtension,
                                               const String& symbolicDescription,
                                               const String& fullDescription,
                                               const File& targetExecutable,
                                               int iconResourceNumber)
    setValue ("HKEY_CURRENT_USER\\Software\\Classes\\" + fileExtension + "\\", symbolicDescription);

    const String key ("HKEY_CURRENT_USER\\Software\\Classes\\" + symbolicDescription);

    if (iconResourceNumber != 0)
        setValue (key + "\\DefaultIcon\\",
                  targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));

    setValue (key + "\\", fullDescription);
    setValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " \"%1\"");

This appears to work as expected.


Thanks! I’ll sort something out along those lines…


The bool switch for global/hive vs. current user only seems to work fine. Thanks!