UnauthorizedAccessException в ComRegisterFunction при доступе к реестру в Win 7 64
-
19-09-2019 - |
Вопрос
У меня есть [ComRegisterFunction], который я использую для регистрации расширения BHO Internet Explorer.Во время регистрации на 64-битных машинах Windows 7 unauperizedAccessException вызывает призыв к Subkey.SetValue («noExplorer», 1).
Похоже, что в реестре есть 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();
}
Решение 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