How do I programmatically check create file permission for folder?
Modify file permission? Delete file permission?
GetNamedSecurityInfo
returns that I can write into C:\Program Files
but UAC says Access Denied (5)
How can I effective determine access permissions?
My code:
function GetAccessRights(const FileName: String; ObjectType: SE_OBJECT_TYPE;
var Access: Cardinal): Cardinal;
var
SecDesc: PSECURITY_DESCRIPTOR;
pDacl: PACL;
Trusteee: TRUSTEE_;
begin
result := GetNamedSecurityInfo(PChar(FileName), ObjectType,
DACL_SECURITY_INFORMATION, nil, nil, @pDacl, nil, SecDesc);
if ERROR_SUCCESS = result then
begin
// the pDacl may be NULL if the object has unrestricted access
if pDacl <> nil then
begin
with Trusteee do
begin
pMultipleTrustee := nil;
MultipleTrusteeOperation := NO_MULTIPLE_TRUSTEE;
TrusteeForm := TRUSTEE_IS_NAME;
TrusteeType := TRUSTEE_IS_UNKNOWN;
ptstrName := 'CURRENT_USER';
end;
result := GetEffectiveRightsFromAcl(pDacl^, Trusteee, Access);
end
else
begin
Access := $FFFFFFFF;
result := ERROR_SUCCESS;
end;
if SecDesc <> nil then
LocalFree(Cardinal(SecDesc));
end;
end;