主要流程如下:
1、獲取所有用戶
2、調(diào)用api獲取用戶相關(guān)信息
bool GetUserInfo(WCHAR* username)
{//用戶信息
LPUSER_INFO_2 pBuf = NULL;
LPUSER_INFO_2 pBuf2 = NULL;
LPUSER_INFO_4 pBuf4 = NULL;
//獲取用戶信息
if (NetUserGetInfo(NULL, username, 4, (LPBYTE*)&pBuf4) == NERR_Success ||
NetUserGetInfo(NULL, username, 2, (LPBYTE*)&pBuf2) == NERR_Success) {if (pBuf4 != NULL)
pBuf = (LPUSER_INFO_2)pBuf4;
else
pBuf = pBuf2;
if (pBuf == NULL) { return FALSE;
}
if (pBuf != NULL)
NetApiBufferFree(pBuf);
}
return TRUE;
}
bool GetUserGroup(WCHAR* username)
{LPLOCALGROUP_USERS_INFO_0 plgus0 = NULL;
LPLOCALGROUP_USERS_INFO_0 plgus1 = NULL;
LPGROUP_USERS_INFO_0 pgus0 = NULL;
LPGROUP_USERS_INFO_0 pgus1 = NULL;
DWORD group_entriesread = 0;
DWORD group_totalentries = 0;
//獲取用戶組信息
if (NetUserGetLocalGroups(NULL, username, 0, LG_INCLUDE_INDIRECT, (LPBYTE*)&plgus0, MAX_PREFERRED_LENGTH, &group_entriesread, &group_totalentries) == NERR_Success)
{if ((plgus1 = plgus0) != NULL)
{ for (int j = 0; j< (int)group_entriesread; j++)
{ //用戶組信息
plgus1++;
}
NetApiBufferFree(plgus0);
}
}
// 獲取全局組成員
pgus0 = NULL;
if (NetUserGetGroups(NULL, username, 0, (LPBYTE*)&pgus0, MAX_PREFERRED_LENGTH, &group_entriesread, &group_totalentries) == NERR_Success)
{if ((pgus1 = pgus0) != NULL)
{ for (int j = 0; j< (int)group_entriesread; j++)
{ //用戶組信息
pgus1++;
}
NetApiBufferFree(pgus0);
}
}
return TRUE;
}
int user_enum()
{LPUSER_INFO_0 pBuf = NULL;
LPUSER_INFO_0 pTmpBuf;
DWORD dwLevel = 0;
LPTSTR pszServerName = NULL;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD i = 0;
CHAR szUserUtf8[260] = {0 };
CHAR szUtf8[512] = {0 };
DWORD len = 0;
NET_API_STATUS nStatus;
int arrayIndex1 = 1;
//獲取所有用戶信息
nStatus = NetUserEnum((LPCWSTR)pszServerName,
dwLevel,
FILTER_NORMAL_ACCOUNT,
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle
);
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{if ((pTmpBuf = pBuf) != NULL)
{ for (i = 0; (i< dwEntriesRead); i++)
{ assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{fprintf(stderr, "An access violation has occurred\n");
break;
}
WideToUtf8_L(pTmpBuf->usri0_name, szUserUtf8, 260);
if (match != NULL)
{if (wildcardcmp(match, szUserUtf8) == 0)
{pTmpBuf++;
dwTotalCount++;
continue;
}
}
UserInfo* info = (UserInfo*)malloc(sizeof(UserInfo));
memset(info, 0, sizeof(UserInfo));
pTmpBuf++;
}
}
}
if (pBuf != NULL) {NetApiBufferFree(pBuf);
pBuf = NULL;
}
return 1;
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧