Windows Installer has the smart feature to automatically decide whether to store registry values under HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE (using Root="HKMU" in WiX).
I need to write some complex registry keys during installation so I created a custom action for this. Depending on whether ALLUSERS is set or not HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE will be the location that is used by the custom action.
Unfortunately, I had to realize that even in an ALLUSERS installation the custom action does not have the required privilege to write to HKEY_LOCAL_MACHINE unless the installation is started as administrator. How do I get the custom action to write to HKEY_LOCAL_MACHINE but still keep the option of a per-user install?
Don’t use a custom action, you’ll lose all the other smart features of Windows Installer such as ugprades, rollbacks, uninstalls and so on.
Instead, put the registry values in their own component and put a condition on the component. If the condition evaluates to true the component and it’s associated registry resources will get installed.
Take a look at the Privileged property. It sounds like what you are looking for to do your evaluation.