0
votes

I'm trying to fetch some data on the Office Click-To-Run currently installed.

I've read these posts : Can't Read Registry Key or OpenSubKey() returns null for a registry key that I can see in regedit.exe
I'm on Windows 10 64bit. My application is an Outlook add-in, so I can't change the target platform (32/64bit), it's the Host that determine if I'm running in 32bit or 64bit. So I've to handle both cases.

So I've this (test) code :

using (var hklmTest64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
    var test = hklmTest64.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration\AudienceData");
    if (test == null)
    {
        using (var hklmTest32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
        {
            test = hklmTest32.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration\AudienceData");
        }
    }
}

So I first fetch the registry key using the 64bit view, then if null I retry using the 32bit view.

Problem: test is always NULL.
Of course the key exists and I can see it using regedit:

Registry Key visible with regedit

Of course I first tried simple code that until now always worked for me, but doesn't work to fetch this key:

test = Registry.LocalMachine.GetValue(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration\AudienceData");
test = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration", "AudienceData", null);

And more strange thing, it's that I had exactly the same problem for fetching the windows build number. This code was not working :

var wBuild = Registry.LocalMachine.GetValue(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ReleaseId");

But this one works perfectly for windows build (not for outlook key):

var wBuild = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", null);

Any idea how to fetch this registry key ?

UPDATE 1

See the post C# get Office ClickToRun Registry Key returns null But reading the post, my code using RegistryView.RegistryXX should work...

UPDATE 2

I've reprod the problem using LinqPad, so this is not due to the Outlook host / add-in. I tried to reprod in a .NET Fiddle but indeed the code is not allowed to access the registry :)

I can get the correct values using P/Invoke like explained in this article. So for me it's clearly a 32/64bit (wow6432node) problem.

2

2 Answers

0
votes

you dont need

RegistryKey.OpenBaseKey

just use Registry.GetValue(keyName, valueName, defualt value)

this is working example

string InstallPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\" + path, "ActivationCode", null);

0
votes

I can get the correct values using P/Invoke like explained in this article. So for me it's clearly a 32/64bit (wow6432node) problem.