Read registry key from IEModule

Add-in Express™ Support Service
That's what is more important than anything else

Read registry key from IEModule
 
SanthoshKumar TV


Guest


Hi Team,

How can I read registry key from IEModule?

The following code returns null value

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\InternetPlugin");
if (key != null)
{
var value = key.GetValue("VersionNumber");
return value.ToString();
}
else
{
return null;
}

Regards,
Santhosh
Posted 17 Nov, 2011 04:07:56 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hi Santhosh,

As far as I understand, you've got a problem related to Protected mode; it prevents your addin from accessing some registry and file system locations. To deal with this, you need to check http://www.add-in-express.com/creating-addins-blog/2009/06/12/internet-explorer-protected-mode-api/.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Nov, 2011 05:11:04 Top
Joacim Andersson


Guest


Hi Andrei,

I'm on the same team as Santhosh. The protected mode API gives us the ability to get write access to the HKCU registry hive but I can't find anything about reading from the HKLM. The blog post you linked to only covers writing to the file system.

How can you read a registry value that exists in HKLM?
Posted 17 Nov, 2011 05:49:50 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Joacim,

I don't have any problems reading from HKLM. Please test the code below:

using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework", false))
{
if (key != null)
{
string value = (string)key.GetValue("InstallRoot", string.Empty);
MessageBox.Show(value);
}
else
{
MessageBox.Show("Null");
}
}
Posted 17 Nov, 2011 07:29:33 Top
Joacim Andersson


Guest


I've found the issue. Both the program that creates the key value in the Registry as well as the add-in is set to be compiled as AnyCPU. The problem then occurs on a 64-bit computer when you run the add-in in the 32-bit version of IE.

Since I want our add-in to be able to run in both the 64-bit and the 32-bit version we will leave that as AnyCPU while I changed the other program to be compiled for x86. That way the registry key will always be written to the WOW6432Node under HKLM on a 64-bit computer. All we then had to do is to test if our add-in runs in the 64-bit or 32-bit environment and read from the correct key.

var path = (IntPtr.Size == 8 ) ? "Software\\WOW6432Node\\InternetPlugin" : "Software\\InternetPlugin";
using (var key = Registry.LocalMachine.OpenSubKey(path, false))
{
//...
}
Posted 17 Nov, 2011 07:59:24 Top
SanthoshKumar TV


Guest


Thank you Joacim! Works now!
Posted 17 Nov, 2011 09:36:49 Top