1

I need to read/write some information in the Windows registry from my BHO. On Windows Vista/7, I create a new key under HKEY_CURRENT_USER\Software\AppDataLow\Software. This works fine, even in protected mode.

However, it does not work on XP. I tried to change the registry to HKEY_CURRENT_USER\Software\Classes\Software or HKEY_CURRENT_USER\Software, no luck.

What is the right registry key to use on Windows XP from a BHO?

IEGetWriteableHKCU does not exist on Windows XP, it was first added in Windows Vista

Julien
  • 5,729
  • 4
  • 37
  • 60

2 Answers2

4

Before Vista you will have to use a different approach... during installation of the BHO you need to tell Windows/IE which key(s) you want to be writable from the BHO...

There is a whole API family to handle this (supported from WinXP SP2 and up according to MSDN):

Yahia
  • 69,653
  • 9
  • 115
  • 144
3

IE 7,8,9,(desktop)10 run tabs in "Protected Mode" which limits registry writes to special "writable" section. You need to ask IE for a pointer to it.

(C#)

// C# PInvoke declaration for needed IE method.
[DllImport("ieframe.dll")]
public static extern int IEGetWriteableHKCU(ref IntPtr phKey); 

// ...
        // somewhere inside other method:
        IntPtr phKey = new IntPtr();
        var answer = IEGetWriteableHKCU(ref phKey);
        RegistryKey writeable_registry = RegistryKey.FromHandle(
            new Microsoft.Win32.SafeHandles.SafeRegistryHandle(phKey, true)
        );
        RegistryKey registryKey = writeable_registry.OpenSubKey(RegistryPathString, true);
        if (registryKey == null) {
            registryKey = writeable_registry.CreateSubKey(RegistryPathString);
        }
        registryKey.SetValue("Mode", mode);
        writeable_registry.Close();

See:

About Protected Mode: http://www.codeproject.com/Articles/18866/A-Developer-s-Survival-Guide-to-IE-Protected-Mode

About Enhanced Protected Mode: http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx

ddotsenko
  • 4,926
  • 25
  • 24