65.9K
CodeProject is changing. Read more.
Home

Function to Get the Local System Administrator Name

Apr 8, 2009

CPOL
viewsIcon

24379

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.

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 );