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

Windows XP Discussion :

[XP home] Utilisateur plus dans aucun groupe


Sujet :

Windows XP

  1. #1
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut [XP home] Utilisateur plus dans aucun groupe
    Salut,

    Suite à un problème dans mon Windows XP Familial, J'ai un utilisateur qui n'apparait plus sur l'écran de login, ni dans les panneaux de config.
    Après un examen, j'ai vu qu'il existait toujours, mais n'était plus dans aucun groupe:
    * On peut "exécuter un en tant que" avce lui, mais en entrant son nom manuellement
    * Il n'apparait pas sur l'écran de login
    * Il n'apparait pas dans "comptes d'utilisateurs"
    * Il n'apparait pas dans "control userpasswords2"
    * Je pense qu'il apparaitrait dans "utilisateurs et groupes locaux", mais comme je suis sous XP home...
    * "documents de <username>" n'apparait plus dans le poste de travail
    * Il apparait quand on fait une recherche d'utilisateurs pour régler les droits

    Malheureusement, je n'ai donc aucun moyen disponible pour remettre l'utilisateur dans un groupe (admins, limités ou invités). Je me suis dit que je pourrais essayer de développer un outil pour le remettre dans le groupe, mais les seuls exemples que j'ai vus sur MSDN sont en dotnet (j'ai visual 6)...

    Quelqu'un connaitrait un programme qui pourrait me permettre de remettre l'utilisateur dans un groupe pour pouvoir à nouveau le configurer?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    C'est bon, j'ai fini par trouver un sample de code pas trop dur à utiliser pour remettre l'utilisateur dans un groupe:
    Example Code for Adding a Domain User or Group to a Local Group

    Une fois qu'on a la fonction, le reste se fait assez facilement:
    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
    #include <windows.h>
    #include <stdio.h>
    #include "AddUser.h"
    
    
    //Link to Active Directory Services Interfaces
    #pragma comment(lib, "ActiveDs.lib")
    #pragma comment(lib, "ADsIID.lib")
    
    
    /* Main function
       ------------- */
    int main()
    {
    HRESULT hr;
    
    hr = CoInitialize(NULL);
    if(FAILED(hr))
    	{
    	puts("erreur dans CoInitialize()");
    	return hr;
    	}
    
    hr = AddDomainUserToLocalGroup(
     L"MONORDI",          //Nom de l'ordinateur
     L"Administrateurs", //Nom du groupe
     L"MONORDI",          //Nom de l'ordinateur aussi
     L"Moi"              //Num d'utilisateur
     );
    
    if(FAILED(hr))
    	{
    	puts("erreur dans AddDomainUserToLocalGroup()");
    	return hr;
    	}
    CoUninitialize();
    return 0;
    }
    Et hop!, l'utilisateur sans groupe devient admin!
    Un peu de config des comptes d'utilisateurs suffit ensuite à en faire ce que l'on veut...

    Edit un an et demi après : La page a été déplacée ici :
    http://msdn2.microsoft.com/en-us/library/ms676309.aspx
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Futur Membre du Club
    Inscrit en
    Avril 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    Bonjour, j'ai le même problème...

    Mais je ne comprends pas comment il est possible d'utiliser les fonction proposées...

    Merci davance de votre aide

    Adeline

  4. #4
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    OK, explications:
    • Soit tu utilises le code que j'ai passé:
      1. Si tu n'as pas Visual C++, tu télécharges Visual C++ Express quelque part.
      2. Tu télécharges le Platform SDK qui va avec.
      3. Tu crées un nouveau projet Win32 console SANS headers précompilés.
      4. Tu fais un copier-coller massif de mon source dans le main.cpp
      5. Entre les pragmas comment et le main, tu fais un copier-coller de la fonction de la page MSDN dont j'ai donné le lien.
        • Si tu a pris la version Express, tu n'as pas ATL. Il faudra alors modifier la fonction pour faire sans (utiliser IAdsContainer*, IDispatch* et IAdsGroup* au lieu de CComPtr<>, ne pas oublier d'appeler leur fonction Release() à la fin).
      6. Tu modifies les sources pour faire correspondre les 3 noms (les 4 paramètres de AddDomainUserToLocalGroup()).
      7. Tu compiles le programme.
      8. Tu l'exécutes sur ton ordinateur (si tu as des problèmes de DLL, cherche un peu partout sur le forum) en tant qu'admin.
    • Ou bien, tu utilises le code VB à la place (en tant qu'admin aussi).
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  5. #5
    Futur Membre du Club
    Inscrit en
    Avril 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    Bonjour,

    J'ai quelques petits soucis en suivant votre procédure :

    #include <atlbase.h> et #include "AddUser.h" ne sont pas trouvés et en suipprimant les deux include j'ai :

    c:\...\utilisateurs\utilisateurs\utilisateurs.cpp(46) : error C2065: 'IAdsContainer'*: identificateur non déclaré

    Pour info mon utilisateur.cpp :
    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    // Utilisateurs.cpp*: définit le point d'entrée pour l'application console.
    //
    
    #include <windows.h>
    #include <stdio.h>
    #include "AddUser.h"
    
    
    //Link to Active Directory Services Interfaces
    #pragma comment(lib, "ActiveDs.lib")
    #pragma comment(lib, "ADsIID.lib")
    
    #include <stdio.h>
    #include <atlbase.h>
    #include <activeds.h>
    #include <ntldap.h>
    
    /*******************************************************************
    
        AddDomainUserToLocalGroup()
    
        Adds a user from a domain to a local group using the WinNT 
        provider.
    
        Parameters:
    
        pwszComputerName - Contains the name of the computer 
        that the group belongs to.
    
        pwszGroupName - Contains the name of the group to add a member 
        to. This group must exist on the target computer.
    
        pwszDomainName - Contains the name of domain that contains 
        the user to add to the group.
    
        pwszUserToAdd - Contains the name of the user in the domain 
        to add to the group.
    
    *******************************************************************/
    
    HRESULT AddDomainUserToLocalGroup(LPCWSTR pwszComputerName, 
                                      LPCWSTR pwszGroupName, 
                                      LPCWSTR pwszDomainName, 
                                      LPCWSTR pwszUserToAdd)
    {
        HRESULT hr = E_FAIL;
        IAdsContainer* spComputer;
    
        // Build the binding string.
        CComBSTR sbstrBindingString;
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszComputerName;
        sbstrBindingString += ",computer";
        
        // Bind to the computer that contains the group.
        hr = ADsOpenObject( sbstrBindingString,
                            NULL, 
                            NULL, 
                            ADS_SECURE_AUTHENTICATION,
                            IID_IADsContainer, 
                            (void**)&spComputer);
    
        if(FAILED(hr))
        {
            return hr;
        }
    
        // Bind to the group object.
        IDispatch* spDisp;
        hr = spComputer->GetObject(CComBSTR("group"), 
                                   CComBSTR(pwszGroupName), 
                                   &spDisp);
        if(FAILED(hr))
        {
            return hr;
        }
    
        IAdsGroup* spGroup;
        hr = spDisp->QueryInterface(IID_IADs, (LPVOID*)&spGroup);
        if(FAILED(hr))
        {
            return hr;
        }
        
        // Bind to the member to add.
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszDomainName;
        sbstrBindingString += "/";
        sbstrBindingString += pwszUserToAdd;
    
        hr = spGroup->Add(sbstrBindingString);
    
        return hr;
    }
    
    
    
    
    /* Main function
       ------------- */
    int main()
    {
    HRESULT hr;
    
    hr = CoInitialize(NULL);
    if(FAILED(hr))
    	{
    	puts("erreur dans CoInitialize()");
    	return hr;
    	}
    
    hr = AddDomainUserToLocalGroup(
     L"MONORDI",          //Nom de l'ordinateur
     L"Administrateurs", //Nom du groupe
     L"MONORDI",          //Nom de l'ordinateur aussi
     L"Moi"              //Num d'utilisateur
     );
    
    if(FAILED(hr))
    	{
    	puts("erreur dans AddDomainUserToLocalGroup()");
    	return hr;
    	}
    CoUninitialize();
    return 0;
    }
    Enfin, comment utiliser la fonction Release ?

    Merci de votre aide

  6. #6
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Alors:
    • Le AddUser.h, c'était un truc que j'avais mis dans le projet, je suppose qu'il incluait des headers nécessaires (je ne l'ai pas sous la main en ce moment).
    • Pour atlbase.h, en effet, la version Express de Visual ne contient pas ATL, c'est pour ça que j'ai dit qu'il ne faudrait pas utiliser les CComPtr<>.
    • L'interface IAdsContainer est déclarée dans <iads.h>
    • Pour les Release: Il faut appeler la méthode Release() de chaque interface une fois par interface, avant de quitter la fonction.
      Donc soit tu en mets avant chaque return, soit tu réarrange la fonction pour qu'il n'y ait plus qu'un seul return et tu mets les appels à Release() au bon endroit.
      Après avoir releasé une interface, je te conseille de mettre son pointeur à NULL.

    Code C++ avec release : 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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    HRESULT AddDomainUserToLocalGroup(LPCWSTR pwszComputerName, 
                                      LPCWSTR pwszGroupName, 
                                      LPCWSTR pwszDomainName, 
                                      LPCWSTR pwszUserToAdd)
    {
        HRESULT hr = E_FAIL;
        IAdsContainer* pComputer;
    
        // Build the binding string.
        CComBSTR sbstrBindingString;
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszComputerName;
        sbstrBindingString += ",computer";
        
        // Bind to the computer that contains the group.
        hr = ADsOpenObject( sbstrBindingString,
                            NULL, 
                            NULL, 
                            ADS_SECURE_AUTHENTICATION,
                            IID_IADsContainer, 
                            (void**)&pComputer);
    
        if(FAILED(hr))
        {
            return hr;
        }
    
        // Bind to the group object.
        IDispatch* pDisp;
        hr = spComputer->GetObject(CComBSTR("group"), 
                                   CComBSTR(pwszGroupName), 
                                   &pDisp);
        if(FAILED(hr))
        {
            pComputer->Release();
            return hr;
        }
    
        IAdsGroup* pGroup;
        hr = pDisp->QueryInterface(IID_IADs, (LPVOID*)&pGroup);
        if(FAILED(hr))
        {
            pComputer->Release();
            pDisp->Release();
            return hr;
        }
        
        // Bind to the member to add.
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszDomainName;
        sbstrBindingString += "/";
        sbstrBindingString += pwszUserToAdd;
    
        hr = pGroup->Add(sbstrBindingString);
    
        pComputer->Release();
        pDisp->Release();
        pGroup->Release();
        return hr;
    }
    PS: J'ai aussi viré le "s" des noms de variables, puisqu'il ne s'agit plus de pointeurs intelligents.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  7. #7
    Futur Membre du Club
    Inscrit en
    Avril 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    Bonjour,

    Malgré le rajout de iads.h j'ai toujours le même problème :

    utilisateurs.cpp(46) : error C2065: 'IAdsContainer'*: identificateur non déclaré
    utilisateurs.cpp(46) : error C2065: 'pComputer'*: identificateur non déclaré
    utilisateurs.cpp(49) : error C2065: 'CComBSTR'*: identificateur non déclaré

    Voici mon nouveau 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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    // Utilisateurs.cpp*: définit le point d'entrée pour l'application console.
    //
    
    #include <windows.h>
    #include <stdio.h>
    
    
    //Link to Active Directory Services Interfaces
    #pragma comment(lib, "ActiveDs.lib")
    #pragma comment(lib, "ADsIID.lib")
    
    #include <stdio.h>
    #include <iads.h>
    #include <activeds.h>
    #include <ntldap.h>
    
    /*******************************************************************
    
        AddDomainUserToLocalGroup()
    
        Adds a user from a domain to a local group using the WinNT 
        provider.
    
        Parameters:
    
        pwszComputerName - Contains the name of the computer 
        that the group belongs to.
    
        pwszGroupName - Contains the name of the group to add a member 
        to. This group must exist on the target computer.
    
        pwszDomainName - Contains the name of domain that contains 
        the user to add to the group.
    
        pwszUserToAdd - Contains the name of the user in the domain 
        to add to the group.
    
    *******************************************************************/
    
    HRESULT AddDomainUserToLocalGroup(LPCWSTR pwszComputerName, 
                                      LPCWSTR pwszGroupName, 
                                      LPCWSTR pwszDomainName, 
                                      LPCWSTR pwszUserToAdd)
    {
        HRESULT hr = E_FAIL;
        IAdsContainer* pComputer;
    
        // Build the binding string.
        CComBSTR sbstrBindingString;
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszComputerName;
        sbstrBindingString += ",computer";
        
        // Bind to the computer that contains the group.
        hr = ADsOpenObject( sbstrBindingString,
                            NULL, 
                            NULL, 
                            ADS_SECURE_AUTHENTICATION,
                            IID_IADsContainer, 
                            (void**)&pComputer);
    
        if(FAILED(hr))
        {
            return hr;
        }
    
        // Bind to the group object.
        IDispatch* pDisp;
        hr = spComputer->GetObject(CComBSTR("group"), 
                                   CComBSTR(pwszGroupName), 
                                   &pDisp);
        if(FAILED(hr))
        {
            pComputer->Release();
            return hr;
        }
    
        IAdsGroup* pGroup;
        hr = pDisp->QueryInterface(IID_IADs, (LPVOID*)&pGroup);
        if(FAILED(hr))
        {
            pComputer->Release();
            pDisp->Release();
            return hr;
        }
        
        // Bind to the member to add.
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszDomainName;
        sbstrBindingString += "/";
        sbstrBindingString += pwszUserToAdd;
    
        hr = pGroup->Add(sbstrBindingString);
    
        pComputer->Release();
        pDisp->Release();
        pGroup->Release();
        return hr;
    }
    
    
    
    
    /* Main function
       ------------- */
    int main()
    {
    HRESULT hr;
    
    hr = CoInitialize(NULL);
    if(FAILED(hr))
    	{
    	puts("erreur dans CoInitialize()");
    	return hr;
    	}
    
    hr = AddDomainUserToLocalGroup(
     L"MONORDI",          //Nom de l'ordinateur
     L"Administrateurs", //Nom du groupe
     L"MONORDI",          //Nom de l'ordinateur aussi
     L"Moi"              //Num d'utilisateur
     );
    
    if(FAILED(hr))
    	{
    	puts("erreur dans AddDomainUserToLocalGroup()");
    	return hr;
    	}
    CoUninitialize();
    return 0;
    }
    Et encore merci de votre aide !

    Adeline

  8. #8
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    CComBstr, c'est du ATL aussi, il faudra utiliser une BSTR simple à la place ou une _bstr_t du Compiler COM Support (#include <comdef.h>).

    Pour IAdsContainer, après examen, il y a effectivment une erreur: Le D est en fait en majuscule: IADsContainer.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  9. #9
    Futur Membre du Club
    Inscrit en
    Avril 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    Après quelques petites corections encore... ça marche ! Merci Beaucoup.

    Voici le code pour visual c++ express :
    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    // Utilisateurs.cpp*: définit le point d'entrée pour l'application console.
    //
    
    #include <windows.h>
    #include <stdio.h>
    
    
    //Link to Active Directory Services Interfaces
    #pragma comment(lib, "ActiveDs.lib")
    #pragma comment(lib, "ADsIID.lib")
    
    #include <stdio.h>
    #include <iads.h>
    #include <activeds.h>
    #include <ntldap.h>
    #include <comdef.h>
    
    /*******************************************************************
    
        AddDomainUserToLocalGroup()
    
        Adds a user from a domain to a local group using the WinNT 
        provider.
    
        Parameters:
    
        pwszComputerName - Contains the name of the computer 
        that the group belongs to.
    
        pwszGroupName - Contains the name of the group to add a member 
        to. This group must exist on the target computer.
    
        pwszDomainName - Contains the name of domain that contains 
        the user to add to the group.
    
        pwszUserToAdd - Contains the name of the user in the domain 
        to add to the group.
    
    *******************************************************************/
    
    HRESULT AddDomainUserToLocalGroup(LPCWSTR pwszComputerName, 
                                      LPCWSTR pwszGroupName, 
                                      LPCWSTR pwszDomainName, 
                                      LPCWSTR pwszUserToAdd)
    {
        HRESULT hr = E_FAIL;
        IADsContainer* pComputer;
    
        // Build the binding string.
        _bstr_t sbstrBindingString;
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszComputerName;
        sbstrBindingString += ",computer";
        
        // Bind to the computer that contains the group.
        hr = ADsOpenObject( sbstrBindingString,
                            NULL, 
                            NULL, 
                            ADS_SECURE_AUTHENTICATION,
                            IID_IADsContainer, 
                            (void**)&pComputer);
    
        if(FAILED(hr))
        {
            return hr;
        }
    
        // Bind to the group object.
        IDispatch* pDisp;
        hr = pComputer->GetObject(_bstr_t("group"), 
                                   _bstr_t(pwszGroupName), 
                                   &pDisp);
        if(FAILED(hr))
        {
            pComputer->Release();
            return hr;
        }
    
        IADsGroup* pGroup;
        hr = pDisp->QueryInterface(IID_IADs, (LPVOID*)&pGroup);
        if(FAILED(hr))
        {
            pComputer->Release();
            pDisp->Release();
            return hr;
        }
        
        // Bind to the member to add.
        sbstrBindingString = "WinNT://";
        sbstrBindingString += pwszDomainName;
        sbstrBindingString += "/";
        sbstrBindingString += pwszUserToAdd;
    
        hr = pGroup->Add(sbstrBindingString);
    
        pComputer->Release();
        pDisp->Release();
        pGroup->Release();
        return hr;
    }
    
    
    
    
    /* Main function
       ------------- */
    int main()
    {
    HRESULT hr;
    
    hr = CoInitialize(NULL);
    if(FAILED(hr))
    	{
    	puts("erreur dans CoInitialize()");
    	return hr;
    	}
    
    hr = AddDomainUserToLocalGroup(
     L"BUREAU_1",          //Nom de l'ordinateur
     L"Administrateurs", //Nom du groupe
     L"BUREAU_1",          //Nom de l'ordinateur aussi
     L"Conseillere"              //Num d'utilisateur
     );
    
    if(FAILED(hr))
    	{
    	puts("erreur dans AddDomainUserToLocalGroup()");
    	return hr;
    	}
    CoUninitialize();
    return 0;
    }
    Les modifications : _bstr_t car BSTR ne fonctionne pas (pb de conversion avec la chaine de caractère), IADsGroup (D aussi en majuscule) et un sp dans le nom d'un des pointeurs au lieu de s dans la déclaration.

    Merci encore de votre aide.

    Adeline

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

Discussions similaires

  1. ajouter utilisateur distants dans un groupe
    Par phoenix75 dans le forum VBScript
    Réponses: 0
    Dernier message: 13/11/2008, 12h45
  2. Réponses: 1
    Dernier message: 13/11/2007, 10h45
  3. Réponses: 1
    Dernier message: 24/07/2007, 12h02
  4. Réponses: 2
    Dernier message: 17/04/2007, 11h37
  5. Un utilisateur dans un groupe
    Par IdrilElendil dans le forum VBScript
    Réponses: 6
    Dernier message: 04/04/2007, 21h49

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