RegistryKey.GetValue returns no value in Installer

2019-09-12 00:37发布

问题:

If have a class that is called as part of an MSI installer package as CustomAction.

It tries to read values from the registry (try to find the local SQL-Server instances):

   RegistryKey sqlServer = Registry.LocalMachine.OpenSubKey( 
                         @"SOFTWARE\Microsoft\Microsoft SQL Server", false );

   string[] localInstances = (string[])sqlServer.GetValue( "InstalledInstances" );

As a stand-alone application this works fine, but it does not work if called from the installer (run as the same user). In the installer GetValue returns null.

Any ideas?

Edit: I ran the installer and the exe on the same machine as the same user. FrameWork is .Net 4 on a Windows 7 64bit machine

Thanks in advance

Mario