procedure TForm1.Button1Click(Sender: TObject);
Function GetAccountBySID(ServerName: String; aSID: PSID; Var RefDomain: String; Var AccType: DWORD): String;
Var
nSize, dSize, pUse: DWORD;
aName, dName: PChar;
Begin
If Not IsValidSID(aSID) Then
Begin
Result := 'Erroneus SID!';
Exit;
End;
nSize := 0; dSize := 0;
If Not LookupAccountSid(PChar(ServerName), aSID, Nil, nSize, Nil, dSize, pUse) Then
Win32Check(GetLastError = ERROR_INSUFFICIENT_BUFFER);
aName := StrAlloc(nSize);
dName := StrAlloc(dSize);
Try
Win32Check(LookupAccountSid(PChar(ServerName), aSID, aName, nSize, dName, dSize, pUSE));
If @AccType <> Nil Then
AccType := Ord(pUse);
Result := aName;
RefDomain := dName;
Finally
StrDispose(aName);
StrDispose(dName);
End;
End;
Var
pSec: PSecurityDescriptor;
sdSize: DWORD;
sidOwner: PSID;
aDef: LongBool;
RefDomain: String;
accType: DWORD;
begin
pSec := Nil; sdSize := 0;
GetFileSecurity('c:\ntldr', OWNER_SECURITY_INFORMATION, pSec, 0, sdSize);
Win32Check(sdSize <> 0);
GetMem(pSec, sdSize);
Try
Win32Check(GetFileSecurity('c:\ntldr', OWNER_SECURITY_INFORMATION, pSec, sdSize, sdSize));
aDef := False;
Win32Check(GetSecurityDescriptorOwner(pSec, sidOwner, aDef));
If aDef Then Raise Exception.Create('Какой-то странный косяк с владельцем ;-)');
Application.MessageBox(PChar(GetAccountBySID('', sidOwner, refDomain, accType) + ' (' + refDomain + ')'), 'Вот такой вот юзверь или группа ;-)', mb_IconInformation);
Finally
FreeMem(pSec);
End;
end;
---
Не одна собака съедается, когда во всём этом начинаешь более-менее свободно ориентироваться
|