Bonjour a tous.

Je bloque depuis ce midi sur une tache simple, et malgres mes recherches et nombreux essais, je n'avance absolutment pas.

Je veux via mon programme créer une sous clé dans HKEY_LOCAL_MACHINE\SOFTWARE

Des que j'appelle la fonction CreateSubKey, une exception UnauthorizedAccessException est levée.

Pourtant :
  • Je suis sous XP SP2
  • Je suis logé en administrateur
  • dans regedit, je n'ai pas de probleme de droit pour créer cette sous clé
  • J'ai récupéré des codes d'exemples, tous donne le meme résultat
  • j'ai vérifié dans regedit les autorisations, rien d'anormal à priori
  • j'ai tenté de forcer les droits via le code, mais la aussi ca leve la meme exception dans ce cas.


voici un résumé de mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
 
namespace TestRegEdit
{
    class Program
    {
        static void Main(string[] args)
        {
            RegistryKey keyIdProc = Registry.LocalMachine;
 
            keyIdProc = keyIdProc.OpenSubKey("SOFTWARE");
            if (keyIdProc.OpenSubKey("rsListOpen") == null)
            {
                keyIdProc.CreateSubKey("rsListOpen"); //=> Levée de l'exception
            }                        
        }
    }
}
voici egalement ma tentative de changemen de droit (dans ce cas, c'est l'appel de SetAccessControl qui leve l'exception :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
[...]
if (keyIdProc.OpenSubKey("rsListOpen") == null)
            {
                string user = Environment.UserDomainName + "\\" + Environment.UserName;
                RegistrySecurity secu = keyIdProc.GetAccessControl();
 
                secu.AddAccessRule(new RegistryAccessRule(user,
                     RegistryRights.ReadKey | RegistryRights.Delete | RegistryRights.CreateSubKey,
                     InheritanceFlags.None,
                     PropagationFlags.None,
                     AccessControlType.Allow));
 
                keyIdProc.SetAccessControl(secu); //=> Levée de l'exception
                keyIdProc.CreateSubKey("rsListOpen");
            }             
[...]


Derniere info qui pourrait etre parlante pour un expérimenté en la matiere, voici la liste des accessrules retournée par 'secu' lorsque je l'initialise en debut de code.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Current access rules:
 
testNotificon2.vshost.exe Information: 0 :         User: CREATEUR PROPRIETAIRE
testNotificon2.vshost.exe Information: 0 :         Type: Allow
testNotificon2.vshost.exe Information: 0 :       Rights: FullControl
testNotificon2.vshost.exe Information: 0 :  Inheritance: ContainerInherit
testNotificon2.vshost.exe Information: 0 :  Propagation: InheritOnly
testNotificon2.vshost.exe Information: 0 :    Inherited? False
 
testNotificon2.vshost.exe Information: 0 :         User: AUTORITE NT\SYSTEM
testNotificon2.vshost.exe Information: 0 :         Type: Allow
testNotificon2.vshost.exe Information: 0 :       Rights: FullControl
testNotificon2.vshost.exe Information: 0 :  Inheritance: ContainerInherit
testNotificon2.vshost.exe Information: 0 :  Propagation: None
testNotificon2.vshost.exe Information: 0 :    Inherited? False
 
testNotificon2.vshost.exe Information: 0 :         User: BUILTIN\Administrateurs
testNotificon2.vshost.exe Information: 0 :         Type: Allow
testNotificon2.vshost.exe Information: 0 :       Rights: FullControl
testNotificon2.vshost.exe Information: 0 :  Inheritance: ContainerInherit
testNotificon2.vshost.exe Information: 0 :  Propagation: None
testNotificon2.vshost.exe Information: 0 :    Inherited? False
 
testNotificon2.vshost.exe Information: 0 :         User: BUILTIN\Utilisateurs
testNotificon2.vshost.exe Information: 0 :         Type: Allow
testNotificon2.vshost.exe Information: 0 :       Rights: ReadKey
testNotificon2.vshost.exe Information: 0 :  Inheritance: ContainerInherit
testNotificon2.vshost.exe Information: 0 :  Propagation: None
testNotificon2.vshost.exe Information: 0 :    Inherited? False
 
testNotificon2.vshost.exe Information: 0 :         User: BUILTIN\Utilisateurs avec pouvoir
testNotificon2.vshost.exe Information: 0 :         Type: Allow
testNotificon2.vshost.exe Information: 0 :       Rights: ReadKey
testNotificon2.vshost.exe Information: 0 :  Inheritance: ContainerInherit
testNotificon2.vshost.exe Information: 0 :  Propagation: None
testNotificon2.vshost.exe Information: 0 :    Inherited? False
 
testNotificon2.vshost.exe Information: 0 :         User: NEWONE\Administrateur
testNotificon2.vshost.exe Information: 0 :         Type: Allow
testNotificon2.vshost.exe Information: 0 :       Rights: FullControl
testNotificon2.vshost.exe Information: 0 :  Inheritance: ContainerInherit
testNotificon2.vshost.exe Information: 0 :  Propagation: None
testNotificon2.vshost.exe Information: 0 :    Inherited? False
Connaissez vous ce probleme svp?
Je fini par m'y perdre vraiment là. Merci d'avance