UnauthorizedaccessException في ComregisterFunction عند الوصول إلى التسجيل على Win 7 64
-
19-09-2019 - |
سؤال
لدي [comregisterfunction] الذي أستخدمه لتسجيل ملحق BHO Internet Explorer. أثناء التسجيل في آلات Windows 7 64 بت، يتم إلقاء unauthorizedaccessExcepessException على المكالمة إلى subkey.setvalue ("noexplorer"، 1).
يبدو أن السجل يحتوي على bho's الواقعة @ hklm software wow6432node microsoft windows currentversion explorer explorer browsher browsher، إلا أن أحصل عليها نفس الاستثناء عند محاولة التسجيل هناك. سيكون موضع تقدير أي مساعدة.
[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