Очень плохо ищешь видно:
http://delphi.xcjc.net/viewthread.php?tid=45527
http://stackoverflow.com/questio....ine-sid
http://www.delphikingdom.com/asp/answer.asp?IDAnswer=48705
Выпадает в первых страницах по запросу: LookupAccountName
Вот от меня рабочий вариант:
Код
function ConvertSidToStringSidA(Sid: PSID; var StringSid: PChar): Boolean; stdcall; external 'ADVAPI32.DLL' name 'ConvertSidToStringSidA';
function SidToString(Sid : PSID) : string;
var
Buffer: PChar;
begin
if ConvertSidToStringSidA(Sid, Buffer) then
Result:=string(Buffer)
else
Result:='';
end;
function GetUserSid(const MachineName, UserName: string): string;
var
Sid: PSID;
RefDomainName: PChar;
SidNameUse: SID_NAME_USE;
dwSidSize, dwDomainSize: DWORD;
begin
Result:='';
dwSidSize:=0;
dwDomainSize:=0;
if not LookupAccountNameA(PChar(MachineName), (PChar(UserName)), nil, dwSidSize, nil, dwDomainSize, SidNameUse) and (GetLastError() = ERROR_INSUFFICIENT_BUFFER) then
try
GetMem(Sid, dwSidSize);
GetMem(RefDomainName, dwDomainSize);
if LookupAccountNameA(PChar(MachineName), (PChar(UserName)), Sid, dwSidSize, RefDomainName, dwDomainSize, SidNameUse) then
Result:=SidToString(Sid);
finally
FreeMem(Sid, dwSidSize);
FreeMem(RefDomainName, dwDomainSize);
end;
end;