Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

Function to Get the Local System Administrator Name

1.00/5 (1 vote)
8 Apr 2009CPOL 24.3K  
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)