"API" netuserenum-get the system all account name

Source: Internet
Author: User

1 description

The Netuserenum function retrieves information about all user accounts on the server.

Function Prototypes:
NET_API_STATUS NetUserEnum(  _In_    LPCWSTR servername,  _In_    DWORD   level,  _In_    DWORD   filter,  _Out_   LPBYTE  *bufptr,  _In_    DWORD   prefmaxlen,  _Out_   LPDWORD entriesread,  _Out_   LPDWORD totalentries,  _Inout_ LPDWORD resume_handle);
Parameter description

servername [in]

A pointer to a constant string that specifies the DNS or NetBIOS name of the remote server on which to execute the function. If this parameter is NULL, the local computer is used.

Level[in]

Specifies the level of information for the data.

filter [in]

Specifies the value of the type of user account to include in the enumeration. A value of zero indicates that all normal users, trusted data, and machine account data should be included.

BufPtr [out]

A pointer to receive data.

Prefmaxlen [in]

Returns the preferred maximum length, in bytes, for the data. If Max_preferred_length is specified, the Netuserenum function allocates the amount of memory required for the data. If you specify another value in this parameter, you can limit the number of bytes returned by the function. If the buffer size is not large enough to hold all the entries, the function returns ERROR_MORE_DATA.

Entriesread [out]

A pointer to a value that receives the number of elements that are actually enumerated.

Totalentries [out]

A pointer to a value that receives the total number of entries that may have been enumerated from the current continuation location.

Resume_handle [in, out]

A pointer to a value that contains the recovery handle used to continue the search for an existing user.

return value

If the function succeeds, the return value is nerr_success.

2 Code
void Cmy20180203_mfc_ Get system all account name Dlg::onbnclickedgetalluser () {//TODO: Add control in this notification handler code updatedata (TRUE);    Lpuser_info_0 pBuf = NULL;    Lpuser_info_0 Ptmpbuf;    DWORD dwlevel = 0;    DWORD Dwprefmaxlen = max_preferred_length;    DWORD dwentriesread = 0;    DWORD dwtotalentries = 0;    DWORD dwresumehandle = 0;    DWORD i;    DWORD dwtotalcount = 0;    Net_api_status Nstatus;    LPTSTR pszservername = NULL; Do//begin does {nstatus = Netuserenum (NULL, Dwlevel, Filter_normal_account,//global use            RS (lpbyte*) &pbuf, Dwprefmaxlen, &dwentriesread, &dwtotalentries,        &dwresumehandle); If the call succeeds,//if ((Nstatus = = nerr_success) | |        (Nstatus = = Error_more_data))                {if (ptmpbuf = pBuf)! = NULL) {/////Loop through the entries. for (i = 0; (I < DwENtriesread);                    i++) {assert (Ptmpbuf! = NULL); if (ptmpbuf = = NULL) {m_username.                        Format (_t ("%s"), "an access violation have occurred\n");                    Break                    }////Print The name of the user account.                    TCHAR tcbuffer[1024] = {0};                    wsprintf (Tcbuffer, L "\t--%s\r\n", ptmpbuf->usri0_name);                    M_username + = Tcbuffer;                    ptmpbuf++;                dwtotalcount++;        }}}////Otherwise, print the system error.        else fprintf (stderr, "A system error has occurred:%d\n", nstatus);        Free the allocated buffer.            if (pBuf! = NULL) {netapibufferfree (PBUF);        PBuf = NULL; }}//Continue to call NetUserenum while//there is more entries. while (Nstatus = = ERROR_MORE_DATA); End do////Check again for allocated me                                        Mory.    if (pBuf! = NULL) NetApiBufferFree (PBUF);    Print the final count of users enumerated.        M_countnum.format (L "Total%d accounts are enumerated", dwtotalcount); UpdateData (FALSE);}
3 interface

4 references
    • The edit control in MFC implements line wrapping

http://blog.csdn.net/dearwind153/article/details/50241537

    • Netuserenum function

https://msdn.microsoft.com/en-us/library/windows/desktop/aa370652 (v=vs.85). aspx

"API" netuserenum-get the system all account name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.