Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / C++
Tip/Trick

Function to Get the Local System Administrator Name

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
8 Apr 2009CPOL 24K   1   6
Function to get the local system administrator name

A Codeproject poster asked this question. He was already aware of the NetLocalGroupGetMembers function which can list users in any groups in the system. He wasn't quite sure how to use it and there wasn't any sample code on the internet. So I wrote a sample and posted on CodeProject and here is the copy of it.

C++
LPLOCALGROUP_MEMBERS_INFO_1  pstMembersInfo = 0;
DWORD entriesread = 0;
DWORD totalentries = 0;
if( 0 != NetLocalGroupGetMembers( NULL, _T("Administrators"), 1, (LPBYTE*)
                                  &pstMembersInfo,MAX_PREFERRED_LENGTH,
                                  &entriesread, &totalentries, 0 ))
{
      AfxMessageBox( _T("NetLocalGroupGetMembers failed !"));
      return ;
}
for( DWORD dwIdx =0; dwIdx  < entriesread; dwIdx ++ )
{
     AfxMessageBox( pstMembersInfo[dwIdx].lgrmi1_name );
}
NetApiBufferFree( pstMembersInfo );

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
General[My vote of 1] Dear Naveen Pin
Ahmad Mahmoud [candseeme]6-Mar-10 20:31
Ahmad Mahmoud [candseeme]6-Mar-10 20:31 
GeneralRe: [My vote of 1] Dear Naveen Pin
Naveen7-Mar-10 6:08
Naveen7-Mar-10 6:08 
GeneralHere is a better problem... Pin
Bill SerGio, The Infomercial King6-Jul-09 4:54
Bill SerGio, The Infomercial King6-Jul-09 4:54 
GeneralRe: Here is a better problem... Pin
Naveen6-Jul-09 18:07
Naveen6-Jul-09 18:07 
GeneralGroup names are localized Pin
CowboyDan17-Apr-09 2:46
CowboyDan17-Apr-09 2:46 
GeneralRe: Group names are localized Pin
Naveen17-Apr-09 2:54
Naveen17-Apr-09 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.