IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Probleme ecriture base de registre (XP)


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2005
    Messages
    700
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2005
    Messages : 700
    Par défaut Probleme ecriture base de registre (XP)
    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

  2. #2
    Expert confirmé
    Avatar de smyley
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    6 270
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 6 270
    Par défaut
    Et si tu fais un truc genre
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Registry.LocalMachine.CreateSubKey("SOFTWARE\\rlBidule");
    ?

  3. #3
    Membre éclairé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2005
    Messages
    700
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2005
    Messages : 700
    Par défaut
    mouarf... j'ai testé sans y croire, et pourtant c'est bien ca
    Merci Smyley

    Par curiosité, quelqu'un a t'il une idée concernant l'exception sur l'appel de SetAccessControl ?

    MErci encore

  4. #4
    Expert confirmé
    Avatar de smyley
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    6 270
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 6 270
    Par défaut
    Je pense que ça doit tout bêtement être parce que tu ouvres la clef en lecture seule avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    keyIdProc.OpenSubKey("trucmuche");
    Essayes plutôt d'ouvrir tes clefs avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    keyIdProc.OpenSubKey("trucmuche", true);

  5. #5
    Membre éclairé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2005
    Messages
    700
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2005
    Messages : 700
    Par défaut
    JE viens de tester, en effet c'etait bien ca.

    Merci encore

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 02/07/2009, 22h55
  2. Probleme ecriture dans la base de registre
    Par Deton@tor dans le forum C++Builder
    Réponses: 8
    Dernier message: 30/04/2008, 15h03
  3. ecriture base de registre dans application service
    Par zoheir13 dans le forum Delphi
    Réponses: 1
    Dernier message: 16/05/2007, 17h42
  4. Obtenir les droits d'ecriture dans fichiers et base de registre
    Par Sunchaser dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 17/07/2006, 11h33
  5. Probleme acceder à ma base de registre
    Par matthieu5978 dans le forum MFC
    Réponses: 2
    Dernier message: 25/11/2005, 14h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo