2012-02-22 64 views
2

我需要從BHO中讀取/寫入Windows註冊表中的一些信息。在Windows Vista/7上,我在HKEY_CURRENT_USER \ Software \ AppDataLow \ Software下創建一個新密鑰。這工作正常,即使在保護模式。Windows XP:在哪裏寫入註冊表從IE?

但是,它不適用於XP。我試圖將註冊表更改爲HKEY_CURRENT_USER \ Software \ Classes \ Software或HKEY_CURRENT_USER \ Software,但沒有運氣。

在BHO上使用Windows XP的正確註冊表鍵是什麼?

IEGetWriteableHKCU不能在Windows XP中存在的,這是第一次在Windows Vista

+0

我懷疑你需要IE6在這裏不會造成麻煩。直到Vista才能添加低權限路徑。 – 2012-02-23 00:27:58

+0

在XP下,你有沒有嘗試過像HKCU \ Software \ YourExtension之類的東西?用戶管理員是? – 2012-02-28 07:43:32

+0

爲什麼不寫在HKEY_LOCAL_MACHINE下? – MEYWD 2012-02-28 16:09:48

回答

3

IE 7,8,9,(桌面),其中限制了 「保護模式」 10個運行製表符註冊表寫入特殊的「可寫入」部分。您需要向IE請求一個指向它的指針。

(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(); 

參見:

關於保護模式http://www.codeproject.com/Articles/18866/A-Developer-s-Survival-Guide-to-IE-Protected-Mode

關於增強保護模式http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx