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)
If you are using AutoCAD x64, you need to request x64 registry explicitly when your custom build exe/DLL is called from the setup (x86 by default).
So try to change it to the following:

```
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("Software\\Autodesk\\AutoCAD")

```