Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to abstract Local SID of a machine connected to domain .I'm using VC++ .Can any please help me any method to retrieve.

Please rely soon.
Posted

Scan HKEY_LOCAL_MACHINE SECURITY\SAM\Domains\Account registry key.
Use Win32::LookupAccountName to get User SID's and finally use Win32::Security::SID to get in string format.

Note that the SECURITY Hive is locked.
 
Share this answer
 
C++
DWORD SIDLength = 0;
	DWORD RefDomainNameLength = 0;
	SID_NAME_USE SIDNameUse;
	::LookupAccountName(NULL, _T("MYCOMPUTERNAME\\"), NULL, &SIDLength, NULL, &RefDomainNameLength, &SIDNameUse);
	PSID psid = (PSID)new BYTE[SIDLength];
	LPTSTR domain = new TCHAR[RefDomainNameLength];
	::LookupAccountName(NULL, _T("MYCOMPUTERNAME\\"), psid, &SIDLength, domain, &RefDomainNameLength, &SIDNameUse);
 
	//... use the SID (psid) here ...
 
	// ** Test **
	LPTSTR StringSid;
	::ConvertSidToStringSid(psid, &StringSid);
	::LocalFree(StringSid);
	// ** End Test **
 
	delete[] domain;
	delete[] (BYTE*)psid;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900