0

我有一个 [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();

}
4

2 回答 2

0

弄清楚了。我必须添加以下内容才能使其正常工作。不知道为什么它在其他版本的操作系统中工作

RegistrySecurity rs = new RegistrySecurity();

rs.AddAccessRule(new RegistryAccessRule(user,
            RegistryRights.FullControl,
            InheritanceFlags.ObjectInherit,
            PropagationFlags.InheritOnly,
            AccessControlType.Allow));

RegistryKey subKey = registryKey.OpenSubKey(guid) ??    registryKey.CreateSubKey(guid, RegistryKeyPermissionCheck.Default, rs);
于 2010-03-12T20:29:06.363 回答
0

您需要以管理权限运行。

于 2010-03-12T19:35:44.943 回答