Domanda

Ho un [ComRegisterFunction] che sto usando per registrare l'estensione di Internet Explorer BHO. Durante la registrazione su Windows a 64 bit 7 macchine, un UnauthorizedAccessException è gettato sulla chiamata a subKey.SetValue ( "NoExplorer", 1).

Il Registro di sistema sembra avere situato @ \ HKLM \ SOFTWARE di BHO \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Explorer \ Browser Helper Objects, tuttavia, ottengo loro stessa eccezione quando si cerca di registrare lì. Qualsiasi aiuto sarebbe apprezzato.

[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();

}
È stato utile?

Soluzione 2

capito. Ho dovuto aggiungere la seguente per farlo funzionare. Non so perché ha funzionato in altre versioni del sistema operativo

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);

Altri suggerimenti

È necessario eseguire con i privilegi amministrativi.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top