Question: 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:

1. Turning off the [UAC](http://en.wikipedia.org/wiki/User_Account_Control) (user account control) will solve the problem.
2. If I can run this console by double clicking it, it will work fine even if UAC is on.

Answer: 
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`](http://msdn.microsoft.com/en-us/library/z9f66s0a.aspx):

> 
> If the specified subkey cannot be found, then null is returned.
> 
> 
> 

(And, note the exceptions listed above there):

> 
> [`SecurityException`](http://msdn.microsoft.com/en-us/library/system.security.securityexception.aspx) 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)
Look for the registry key of the same path under HKLM, not HKCU hive. It will exist only if AutoCAD has been installed "for all users" as opposed to "for the current user", the former is however quite likely.

If AutoCAD is installed just for a particular user and you are installing something else under the same user, inspect the `msidbCustomActionTypeNoImpersonate` flag of the custom action. The default value is false which should work for you, but if you have changed that flag to true, you would have the issue already described in a sister answer by Damien\_The\_Unbeliever.

If AutoCAD is installed just for a particular user and you are installing something else under a *different* user, such as the administrator, then watch out for logical gaps somewhere in your requirements. The HKCU hive is not one system-wide hive, but its content is different for every logged in user.
There may be several parallel AutoCAD installations with different registry content and you need to be clear on what you really want to do with each of them; or reach your ultimate goal by some different approach.