int _tmain(int argc, TCHAR *argv[]) { DWORD ReturnedEntryCount = 0; DWORD Index = 0; DWORD Result = 0; LPVOID SortedBuffer = NULL; DWORD i; _tprintf(TEXT("Enumerate Users v1.0.0\nJacob Hammack\nhttp://www.hammackj.com\n\n")); do { Result = NetQueryDisplayInformation(NULL, 1, Index, 1000, MAX_PREFERRED_LENGTH, &ReturnedEntryCount, &SortedBuffer); if((Result == ERROR_SUCCESS) || (Result == ERROR_MORE_DATA)) { PNET_DISPLAY_USER CurrentUser = (PNET_DISPLAY_USER) SortedBuffer; for(i = 0; i < ReturnedEntryCount; ++i, ++CurrentUser) { _tprintf(TEXT("Name: %s, Comment: %s, User ID: %u\n"), CurrentUser->usri1_name, CurrentUser->usri1_comment, CurrentUser->usri1_user_id); _tprintf(TEXT("Attributes:\n")); if(CurrentUser->usri1_flags & UF_ACCOUNTDISABLE) { _tprintf(TEXT("\tAccount is Disabled\n")); } if(CurrentUser->usri1_flags & UF_HOMEDIR_REQUIRED) { _tprintf(TEXT("\tAccount Needs a Home directory\n")); } if(CurrentUser->usri1_flags & UF_LOCKOUT) { _tprintf(TEXT("\tAccount Locked out\n")); } if(CurrentUser->usri1_flags & UF_PASSWD_NOTREQD) { _tprintf(TEXT("\tAccount does not require a password\n")); } if(CurrentUser->usri1_flags & UF_PASSWD_CANT_CHANGE) { _tprintf(TEXT("\tAccount cannot change the password\n")); } if(CurrentUser->usri1_flags & UF_DONT_EXPIRE_PASSWD) { _tprintf(TEXT("\tAccount Password never expires\n")); } if(CurrentUser->usri1_flags & UF_SMARTCARD_REQUIRED) { _tprintf(TEXT("\tAccount requires Smartcard\n")); } _tprintf(TEXT("\n")); } Index += i; NetApiBufferFree(SortedBuffer); } else { _tprintf(TEXT("Error: %u"), Result); } } while (Result == ERROR_MORE_DATA); return 0; }
bool GetComputer(UserManager *panel,bool selection) { bool res=false; if(selection) { /* 000000000011111111112222222222333333333344444444 012345678901234567890123456789012345678901234567 00 00 01 ÉÍÍÍÍÍÍÍÍÍÍÍ Select Computer ÍÍÍÍÍÍÍÍÍÍÍÍ» 01 02 º Computer: º 02 03 º ZG ³º 03 04 º (empty for local system) º 04 05 ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ 05 06 06 000000000011111111112222222222333333333344444444 012345678901234567890123456789012345678901234567 */ static const TCHAR *ComputerHistoryName=_T("UserManager\\Computer"); FarDialogItem DialogItems[]= { /*0*/ {DI_DOUBLEBOX,3,1,44,5,{0},NULL, NULL,0, GetMsg(mSelCompTitle), 0,0,{0,0}}, /*1*/ {DI_TEXT, 5,2, 0,0,{0},NULL, NULL,0, GetMsg(mSelCompLabel), 0,0,{0,0}}, /*2*/ {DI_EDIT, 5,3,42,0,{0},ComputerHistoryName,NULL,DIF_HISTORY|DIF_FOCUS,_T(""), 0,0,{0,0}}, /*3*/ {DI_TEXT, 5,4, 0,0,{0},NULL, NULL,0, GetMsg(mSelCompFootnote),0,0,{0,0}}, }; DialogItems[2].Data=panel->computer_ptr; CFarDialog dialog; int DlgCode=dialog.Execute(MainGuid,GetComputerGuid,-1,-1,48,7,NULL,DialogItems,ArraySize(DialogItems),0,0,ComputerDialogProc,0); if(DlgCode!=-1) { if(dialog.Str(2)[0]) { TCHAR tmp[512]; if(_tcsncmp(dialog.Str(2),_T("\\\\"),2)) { _tcscpy(tmp,_T("\\\\")); _tcscat(tmp,dialog.Str(2)); } else { _tcscpy(tmp,dialog.Str(2)); } HANDLE hSScr=Info.SaveScreen(0,0,-1,-1); const TCHAR *MsgItems[]={_T(""),GetMsg(mOtherConnect)}; Info.Message(&MainGuid,&MessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),0); wchar_t temp_computer_name[MAX_PATH]; _tcscpy(temp_computer_name,tmp); DWORD count; PVOID buffer; if(NetQueryDisplayInformation(temp_computer_name,2,0,1,MAX_PREFERRED_LENGTH,&count,&buffer)==NERR_Success) { NetApiBufferFree(buffer); wcscpy(panel->computer,temp_computer_name); panel->computer_ptr=panel->computer; res=true; } else ShowCustomError(mOtherNetNotFound); Info.RestoreScreen(hSScr); } else { wcscpy(panel->computer,L""); panel->computer_ptr=NULL; res=true; } } } else { wcscpy(panel->computer,L""); panel->computer_ptr=NULL; res=true; } return res; }
bool CWfpNET::NET_Machines_Users_Groups(DWORD level) { NET_DISPLAY_USER *ndu = NULL; NET_DISPLAY_MACHINE *ndm = NULL; NET_DISPLAY_GROUP *ndg = NULL; NET_API_STATUS nStatus = NULL; DWORD read = 0, Index = 0, i = 0; void *pBuf; CString tmp; do { pBuf = NULL; nStatus = NetQueryDisplayInformation(node.szComputerW, level, Index, 100, MAX_PREFERRED_LENGTH, &read, &pBuf); if (nStatus != ERROR_MORE_DATA && nStatus != ERROR_SUCCESS) { ErrorHandler("NetQueryDisplayInformation", nStatus); return false; } switch (level) { case ENUM_USERS: // users { for(i = 0, ndu = (NET_DISPLAY_USER *)pBuf; i < read; ++ i, ++ ndu ) { tmp.Format(_T("%S [%u] \"%S\" - %S"), ndu->usri1_name, ndu->usri1_user_id ,ndu->usri1_full_name, ndu->usri1_comment); Users.Add(tmp); if(options.optionsid) Users.Add(SID_get(ndu->usri1_name)); if(ndu->usri1_flags & UF_SCRIPT) Users.Add("- The logon script executed. This value must be set for LAN Manager 2.0 or Windows NT."); if (ndu->usri1_flags & UF_ACCOUNTDISABLE) Users.Add("- The user's account is disabled."); if (ndu->usri1_flags & UF_HOMEDIR_REQUIRED) Users.Add("- The home directory is required. Windows NT/2000 ignores this value."); if (ndu->usri1_flags & UF_PASSWD_NOTREQD) Users.Add("- No password is required."); if (ndu->usri1_flags & UF_PASSWD_CANT_CHANGE ) Users.Add("- The user cannot change the password."); if (ndu->usri1_flags & UF_LOCKOUT) Users.Add("- The Account is currently locked out."); if (ndu->usri1_flags & UF_DONT_EXPIRE_PASSWD) Users.Add("\t- Password does not expire."); #if _WIN32_WINNT > 0x0500 if (ndu->usri1_flags & UF_TRUSTED_FOR_DELEGATION) Users.Add("- The account is enabled for delegation."); if (ndu->usri1_flags & UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED) Users.Add("- The user's password is stored under reversible encryption in the Active Directory."); if (ndu->usri1_flags & UF_NOT_DELEGATED) Users.Add("- Marks the account as \"sensitive\"; other users cannot act as delegates of this user account."); if (ndu->usri1_flags & UF_SMARTCARD_REQUIRED) Users.Add("- Requires the user to log on to the user account with a smart card."); if (ndu->usri1_flags & UF_USE_DES_KEY_ONLY) Users.Add("- Restrict this principal to use only Data Encryption Standard (DES) encryption types for keys."); if (ndu->usri1_flags & UF_DONT_REQUIRE_PREAUTH) Users.Add("- This account does not require Kerberos preauthentication for logon."); if (ndu->usri1_flags & UF_PASSWORD_EXPIRED) Users.Add("- The user's password has expired."); #endif } tmp.Format("%d\n",read); // take the last element's next_index if (read > 0) Index = ((NET_DISPLAY_USER *)pBuf)[read - 1].usri1_next_index; break; } case ENUM_MACHINES: // machines for (i = 0, ndm = (NET_DISPLAY_MACHINE *) pBuf; i < read; ++ i, ++ ndm ) { // m_output.Format(_T("\t%S %S\n"),ndm->usri2_name, ndm->usri2_flags ); } // take the last element's next_index if (read > 0) Index = ((NET_DISPLAY_MACHINE *)pBuf)[read - 1].usri2_next_index; break; case ENUM_GROUPS: // groups { //m_output.operator +=(_T("Global Groups:\n")); for (i = 0, ndg = (NET_DISPLAY_GROUP *) pBuf; i < read; ++ i, ++ ndg ) { tmp.Format(_T("\t%S \"%S\" [%u]\n"),ndg->grpi3_name,ndg->grpi3_comment,ndg->grpi3_group_id); Groups.Add(tmp); if(options.optionsid) Groups.Add(SID_get(ndg->grpi3_name)); GroupMembers_get(ndg->grpi3_name); } // take the last element's next_index if (read > 0) Index = ((NET_DISPLAY_GROUP *)pBuf)[read - 1].grpi3_next_index; break; } } if (pBuf != NULL) NetApiBufferFree(pBuf); } while (nStatus == ERROR_MORE_DATA); return true; }
void CSettingsPage::OnCbnDropdownRunasuser() { DWORD count; NET_DISPLAY_USER *userlist; if(m_cbRunAsUser.GetCount()<3) { CString cur; CWaitCursor wait; m_cbRunAsUser.GetWindowText(cur); m_cbRunAsUser.ResetContent(); m_cbRunAsUser.AddString(_T("(client user)")); NetQueryDisplayInformation(NULL,1,0,4096,MAX_PREFERRED_LENGTH,&count,(PVOID*)&userlist); for(size_t n=0; n<count; n++) { if((userlist[n].usri1_flags&(UF_ACCOUNTDISABLE|UF_NORMAL_ACCOUNT|UF_NOT_DELEGATED)) != (UF_NORMAL_ACCOUNT)) continue; /* USER_INFO_1 *ui1; if(!NetUserGetInfo(mw_pdc,userlist[n].usri1_name, 1, (LPBYTE*)&ui1)) { if(ui1->usri1_priv == USER_PRIV_ADMIN) { NetApiBufferFree(ui1); continue; } NetApiBufferFree(ui1); } */ CString str; str.Format(_T("%s\\%s"),mw_computer,userlist[n].usri1_name); m_cbRunAsUser.AddString(str); } NetApiBufferFree(userlist); if(mw_domain[0]) { NetQueryDisplayInformation(mw_pdc,1,0,4096,MAX_PREFERRED_LENGTH,&count,(PVOID*)&userlist); for(size_t n=0; n<count; n++) { if((userlist[n].usri1_flags&(UF_ACCOUNTDISABLE|UF_NORMAL_ACCOUNT|UF_NOT_DELEGATED)) != (UF_NORMAL_ACCOUNT)) continue; /* USER_INFO_1 *ui1; if(!NetUserGetInfo(mw_pdc,userlist[n].usri1_name, 1, (LPBYTE*)&ui1)) { if(ui1->usri1_priv == USER_PRIV_ADMIN) { NetApiBufferFree(ui1); continue; } NetApiBufferFree(ui1); } */ CString str; str.Format(_T("%s\\%s"),mw_domain,userlist[n].usri1_name); m_cbRunAsUser.AddString(str); } NetApiBufferFree(userlist); } m_cbRunAsUser.SetCurSel(m_cbRunAsUser.FindStringExact(-1,cur)); } }