Get the name of the owner of the specified file or folder.
1 2 3 4 5 6 7 |
var path, name: string; begin path:= 'C:\Program Files'; name:= getFileDirOwner(path); ShowMessage(name); end; |
Options
path - path to file or folder
Result
Owner name or empty string if unsuccessful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
function getFileDirOwner (path: string): string; var SecDescr: PSecurityDescriptor; SizeNeeded, SizeNeeded2: DWORD; OwnerSID: PSID; OwnerDefault: BOOL; OwnerName, DomainName: PChar; OwnerType: SID_NAME_USE; begin Result:= ''; GetMem(SecDescr, 1024); GetMem(OwnerName, 1024); GetMem(DomainName, 1024); if GetFileSecurity(PChar(path), OWNER_SECURITY_INFORMATION, SecDescr, 1024, SizeNeeded) then if GetSecurityDescriptorOwner(SecDescr, OwnerSID, OwnerDefault) then SizeNeeded:= 1024; SizeNeeded2:= 1024; if LookupAccountSID(nil, OwnerSID, OwnerName, SizeNeeded, DomainName, SizeNeeded2, OwnerType) then begin Result:= OwnerName; FreeMem(SecDescr); FreeMem(OwnerName); FreeMem(DomainName); end; end; |