Reputation: 1137
I want to get users of a group using NetGroupGetUsers
function.
DWORD dwError = 0;
NET_API_STATUS nStatus;
LPDWORD entriesread=0;
LPDWORD totalentries=0;
LPBYTE *buff;
nStatus=NetGroupGetUsers(NULL,L"Users",0,buff,MAX_PREFERRED_LENGTH,
entriesread,totalentries,NULL);
When i use this i get this error;
xC0000005: Access violation reading location 0xffffffffffffffff.
And how can i read buff when it works? And also i tried this;
GROUP_USERS_INFO_0 *buff;
nStatus=NetGroupGetUsers(NULL,L"Users",0,(LPBYTE*)&buff,MAX_PREFERRED_LENGTH,
entriesread,totalentries,NULL);
but same error occurred.
EDIT: nStatus value is NERR_GroupNotFound
i think the reason of the access violation is trying to read buff which isn't actually set.
EDIT 2: i used this function NetLocalGroupGetMembers
. now it gives success but the buff->grui0_name
is meaningless. there is a user named "ali" but the value of the buff->grui0_name
is just "d". WHAT AM I DOING WRONG?
The Last Code;
LPCWSTR TargetGroup = L"group1";
DWORD dwError = 0;
NET_API_STATUS stat;
GROUP_USERS_INFO_0 *buff;
LPDWORD entriesread=new DWORD;
LPDWORD totalentries=new DWORD;
stat=NetGroupGetUsers(NULL,TargetGroup,0,(LPBYTE *)&buff,MAX_PREFERRED_LENGTH,
entriesread,totalentries,NULL);
for EDIT 2;
stat=NetLocalGroupGetMembers(NULL,TargetGroup,0,(LPBYTE *)&buff,
MAX_PREFERRED_LENGTH,entriesread,totalentries,NULL);
Please help...
Upvotes: 0
Views: 2660
Reputation: 789
Here is the version without new:
LPCWSTR TargetGroup = L"group1";
NET_API_STATUS stat;
LOCALGROUP_MEMBERS_INFO_1 *buff;
DWORD entriesread;
DWORD totalentries;
stat = NetLocalGroupGetMembers(NULL,TargetGroup,1,(LPBYTE *)&buff,
MAX_PREFERRED_LENGTH,&entriesread,&totalentries,NULL);
wprintf(buff->lgrmi1_name);
Upvotes: 1
Reputation: 1137
LPCWSTR TargetGroup = L"group1";
NET_API_STATUS stat;
LOCALGROUP_MEMBERS_INFO_1 *buff;
LPDWORD entriesread=new DWORD;
LPDWORD totalentries=new DWORD;
stat=NetLocalGroupGetMembers(NULL,TargetGroup,1,(LPBYTE *)&buff,
MAX_PREFERRED_LENGTH,entriesread,totalentries,NULL);
wprintf(buff->lgrmi1_name);
This code is working great now. Thanks to everybody.
Upvotes: 0
Reputation: 45172
You haven't allocated any memory for buff
. You should be writing
GROUP_USERS_INFO_0 *buff;
... NetGroupGetUsers(..., (LPBYTE*)&buff, ...);
otherwise you're telling NetGroupGetUsers to write the results to a garbage location. Note that the bufptr
parameter is documented as [out]
. That means that it is the caller's responsibility to specify where the result should go. There's more to calling a function than just getting the types to match.
I'm surprised you didn't get an "use of initialized variable" warning from the compiler.
Upvotes: 1