I have a console program that read a registry key under HKCU:
OpenSubKey("Software\\Autodesk\\AutoCAD")
The program works very fine, but when I tried to use it as a Custom Action
in an install project, it returned a null
value.
Here are some suggestions:
If it's returning null
rather than throwing an exception, then it's not a permissions issue - it's that the key doesn't exist. OpenSubKey
:
If the specified subkey cannot be found, then null is returned.
(And, note the exceptions listed above there):
SecurityException
The user does not have the permissions required to read the registry key.
So, the likely issue is that your action is being invoked during the install sequence, when it's being run by the Windows Installer service - this service runs under the local system account, not under the logged in user's account.
Not knowing what you're trying to achieve with this key, I'm not sure what workaround to suggest. It may be that you can achieve your aims using standard built in facilities within the MSI system - or that you may want to defer this action until the first time you're program actually runs.
(What's possible inside the MSI may vary depending on what you're using to build it - if you're currently using a VS Setup project, you'll be quite limited)
this service runs under the local system account, not under the logged in user's account. I think this is the key solution, because I noticed if the user choose Run as administrator it will work fine I wonder why when windows ask about permission through the installation does't it work?