Saturday, December 20, 2008

Function to get the local system Administrator Name

A codeproject poster asked this question. He was already aware of the NetLocalGroupGetMembers function with which, was can the list of users in any groups in the system. How were he wasn't quite sure how to use it and there wasn't any sample code in the internet. So I wrote a sample and posted in codeproject and here is the copy of it.
DWORD entriesread = 0;
DWORD totalentries = 0;
if( 0 != NetLocalGroupGetMembers( NULL, _T("Administrators"), 1, (LPBYTE*)
&entriesread, &totalentries, 0 ))
AfxMessageBox( _T("NetLocalGroupGetMembers failed !"));
return ;
for( DWORD dwIdx =0; dwIdx < entriesread; dwIdx ++ )
AfxMessageBox( pstMembersInfo[dwIdx].lgrmi1_name );
NetApiBufferFree( pstMembersInfo );