Getting group of a user

Posted on 1999-06-28
Medium Priority
Last Modified: 2013-11-20
Environment WinNT service pack4,
I'd like to find out to what group the currently logged on
user belongs to, I can get the name with GetUserName, but theres nothing like GetGroupName there are functions like
LookupAccountName with lots of parameters. So i do not know how
Question by:mruff

Accepted Solution

Jedi earned 100 total points
ID: 1308156
The NetUserGetGroups function retrieves a list of global groups to which a specified user belongs.

Use netapi32.lib


Author Comment

ID: 1308157
Thanx but I still have pblms:

DWORD prefmaxlen;
DWORD entriesread;
DWORD totalentries;
GROUP_USERS_INFO_0* pusergroups;
char username[100];
int buffersize = sizeof(username);

GetUserName(username, (LPDWORD) &buffersize);
//get the users group
NET_API_STATUS result = NetUserGetGroups(NULL, (LPWSTR)username,      0,
                                                                     (unsigned char**)&pusergroups,       
                                                        &totalentries );
I always get error : NERR_UserNotFound altough i have the name of the current
logged on user (myself) in username

Expert Comment

ID: 1308158
The NETAPI functions use UNICODE-strings. Try GetUserNameW instead of GetUserName(A).

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question