我有一个 [ComRegisterFunction] 用于注册 BHO Internet Explorer 扩展。在 64 位 Windows 7 计算机上注册期间,在调用 subKey.SetValue("NoExplorer", 1) 时会引发 UnauthorizedAccessException。
注册表似乎有 BHO 位于 @\HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer\Browser Helper Objects,但是,我在尝试在那里注册时遇到了同样的异常。任何帮助,将不胜感激。
[ComRegisterFunction]
public static void RegisterBho(Type type) {
string BhoKeyName= "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BhoKeyName, true) ??
Registry.LocalMachine.CreateSubKey(BhoKeyName);
if(registryKey == null) throw new ApplicationException("Unable to register Bho");
registryKey.Flush();
string guid = type.GUID.ToString("B");
RegistryKey subKey = registryKey.OpenSubKey(guid) ?? registryKey.CreateSubKey(guid);
if (subKey == null) throw new ApplicationException("Unable to register Bho");
subKey.SetValue("NoExplorer", 1);
registryKey.Close();
subKey.Close();
}