UnauthorizedAccessException在ComRegisterFunction访问在Win 7 64注册表时
-
19-09-2019 - |
题
我有一个[ComRegisterFunction],我使用以注册BHO Internet Explorer的扩展。期间在64位视窗注册7机,一个UnauthorizedAccessException 被抛出在调用subKey.SetValue( “NoExplorer”,1)。
在注册表似乎有BHO的位于@ \ HKLM \ SOFTWARE \ Wow6432Node \微软\的Windows \ CurrentVersion \ Explorer中\浏览器辅助对象,但是,我让他们相同的异常试图注册存在时。任何帮助,将不胜感激。
[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();
}
解决方案 2
了它。我不得不添加以下,使其工作。不知道为什么它在操作系统的其他版本的工作
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);
其他提示
您需要具有管理员权限运行。
不隶属于 StackOverflow