Home > OS >  Get the SID
Get the SID

Time:11-21

Find an instance, use ConvertSidToStringSid this function, the reference API documentation and the header files and lib, or tip the identifier is not found, good strange,

CodePudding user response:

 

//win32_GetuserSID. CPP: defines the entry point of the console application,
//

# include "stdafx. H"
# include & lt; SDDL. H>
# include & lt; Windows. H>
# include & lt; LMACCESS. H>
# include & lt; LMERR. H>
# include & lt; LMAPIBUF. H>
# include & lt; Ntsecapi. H>
# include & lt; stdlib.h>
# include & lt; Atlconv. H>
# pragma comment (lib, "Netapi32. Lib")
# pragma comment (lib, "Advapi32. Lib")


Int _tmain (int arg c, _TCHAR * argv [])
{
USES_CONVERSION;
USER_INFO_0 * pUserInfo=NULL;
DWORD totalentries=0;
DWORD entriesread=0;
DWORD prefmaxlen=MAX_PREFERRED_LENGTH;
DWORD ret=NetUserEnum (
NULL,
0,
0,
(LPBYTE *) & amp; PUserInfo,
Prefmaxlen,
& Entriesread,
& Totalentries,
NULL
);//get the user name information structure array
for(int i=0; i {
DWORD need1=0;
DWORD need2=0;
SID_NAME_USE snu.
//LPSTR SSID=(snu LPSTR);
_tprintf (TEXT (" UserName: % s \ n "), (pUserInfo + I) - & gt; Usri0_name);//enumerated all print host user name
The LookupAccountName (
NULL,
W2A ((pUserInfo + I) - & gt; Usri0_name),
NULL, & amp; Need1,
NULL, & amp; Need2,
NULL
);
LPBYTE pSid=(LPBYTE) calloc (need1, sizeof (BYTE));
LPWSTR pNoUser=(LPWSTR) calloc (need2, sizeof (TCHAR));
LPSTR LNoUser=(LPSTR pNoUser);
The LookupAccountName (
NULL,
W2A ((pUserInfo + I) - & gt; Usri0_name),
PSid, & amp; Need1,
LNoUser, & amp; Need2,//I have to try to find the two can't save, even though I didn't use them
& Snu//I have to try to find the two can't save, even though I didn't use his
);
LPTSTR lpszSID=NULL;
ConvertSidToStringSid ((PSID) PSID, & amp; LpszSID);
_tprintf (TEXT (" \ n \ tSID is % s "), lpszSID);
LocalFree (lpszSID);
Free (pSid);
Free (pNoUser);
}
NetApiBufferFree (pUserInfo);//release the memory space system application
getchar();
return 0;
}
  • Related