Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to automate NT Groups/Users management
Message
 
 
À
14/05/2001 14:14:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00506963
Message ID:
00507027
Vues:
13
Fernando,
There are several problems here.

1. Buf is supposed to be a pointer to a structure not a pointer to a string. You can download Ed Rauh's CLSHEAP class to help with this.
2. Servername and Groupname are supposed to NULL terminated UNICODE strings. You need to use STRCONV() to convert them.

I modified your code to run in my test environment. Change the names as you see fit.
set procedure to clsheap additive
oheap = createobject("Heap")

Declare Integer NetLocalGroupAddMembers  ;
         In NetApi32 String  ServerName, ;
                     String  GroupName , ;
                     Integer Level     , ;
                     String  @Buf       , ;
                     Integer TotalEntries

cServerName   = strconv(strconv("\\TCPPT23",1),5)+chr(0)              && Name of my Win NT 4 server
cGroupName    = strconv(strconv("Administrators",1),5)+chr(0)              && Name of the group
nLevel        = 3
nTotalEntries = 1
cBuf = NumtoDWORD(oHeap.AllocString(strconv(strconv("TCPPT23\TUser",1),5)+chr(0))) && DomainName\AccountName
* oheap.AllocString returns the memory address of where the string was stored
* NumtoDWORD returns a string representation of the address of the pointer

nResult = NetLocalGroupAddMembers (cServerName  , ;
                                    cGroupName   , ;
                                    nLevel       , ;
                                    @cBuf         , ;
                                    nTotalEntries)

MessageBox (Str (nResult))
HTH.


>Hi,
>
>I'm trying to automate Groups/Users management in a program. To do it I'm using NetLocalGroupAddMembers to add users to a group and NetLocalGroupDelMembers to remove users from a group.
>
>At MSDN one can read:
>
>The NetLocalGroupAddMembers function adds membership of one or more existing user accounts or global group accounts to an existing local group. The function does not change the membership status of users or global groups that are currently members of the local group.
>
>The NetLocalGroupDelMembers function removes one or more members from an existing local group. Local group members can be users or global groups.
>
>The code I wrote is not working, and any help will be highly apreciated!
>
>Below is the code I'm testing:
>
>*To add a member to a group ===============================
>
> Declare Integer NetLocalGroupAddMembers  ;
>                                          ;
>         In NetApi32 String  @ServerName, ;
>                     String  @GroupName , ;
>                     Integer @Level     , ;
>                     String  @Buf       , ;
>                     Integer @TotalEntries
>
> cServerName   = "\\MU005873"              && Name of my Win NT 4 server
> cGroupName    = "GrupoTeste"              && Name of the group
> nLevel        = 3
> cBuf          = "\\MU005873\UsuarioTeste" && DomainName\AccountName
> nTotalEntries = 1
>
> nResult = NetLocalGroupAddMembers (cServerName  , ;
>                                    cGroupName   , ;
>                                    nLevel       , ;
>                                    cBuf         , ;
>                                    nTotalEntries)
>
> MessageBox (Str (nResult))
>
>*To remove a member a from a group ========================
>
> Declare Integer NetLocalGroupDelMembers  ;
>                                          ;
>         In NetApi32 String  @ServerName, ;
>                     String  @GroupName , ;
>                     Integer @Level     , ;
>                     String  @Buf       , ;
>                     Integer @TotalEntries
>
> cServerName   = "\\MU005873"
> cGroupName    = "GrupoTeste"
> nLevel        = 3
> cBuf          = "\\MU005873\UsuarioTeste"
> nTotalEntries = 1
>
> nResult = NetLocalGroupDelMembers (cServerName  , ;
>                                    cGroupName   , ;
>                                    nLevel       , ;
>                                    cBuf         , ;
>                                    nTotalEntries)
>
> MessageBox (Str (nResult))
>
> Clear DLLs
>
>*==========================================================
>
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform