function File_FLR_Owner(const FName: string;
var Domain, OwnerName: string): Boolean;
var
OSID: PSID;
DW, DW2: DWORD;
ODefault: BOOL;
OName, DName: PCHAR;
OType: SID_NAME_USE;
PSD: PSecurityDescriptor;
procedure frei;
begin
FreeMem(DName);
FreeMem(OName);
FreeMem(PSD);
end;
begin
Result := False;
DW := 1024;
GetMem(PSD, DW);
GetMem(OName, DW);
GetMem(DName, DW);
try
if not GetFileSecurity(PChar(FName),
OWNER_SECURITY_INFORMATION,
PSD, DW, DW2) then begin
frei;
exit;
end;
if not GetSecurityDescriptorOwner(PSD,
OSID, ODefault) then begin
frei;
exit;
end;
if not LookupAccountSID(nil, OSID, OName,
DW, DName, DW2, OType) then begin
frei;
exit;
end;
Domain := DName;
OwnerName := OName;
except
frei;
exit;
end;
Result := True;
frei;
end;
// Beispielaufruf
procedure TForm1.Button3Click(Sender: TObject);
var
Domain, OwnerName: string;
begin
if File_FLR_Owner('C:\TEMP', Domain, OwnerName) then
ShowMessage(Domain + ' / ' + OwnerName) else
ShowMessage('Eigner konnte nicht ermittelt werden.');
end;