本地机器SID

本地机器SID

问题描述:


我想使用VC ++对连接到域的计算机的本地SID进行抽象.请问有什么方法可以帮助我.

请尽快使用.

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.

扫描HKEY_LOCAL_MACHINE SECURITY \ SAM \ Domains \ Account注册表项.
使用Win32 :: LookupAccountName获取用户SID,最后使用Win32 :: Security :: SID以字符串格式获取.

请注意,安全性"配置单元已锁定.
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.


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;