如何以编程方式检查文件夹的创建文件权限?修改文件权限?删除文件权限?
GetNamedSecurityInfo
返回我可以写入C:\Program Files
但 UAC 说Access Denied (5)
如何有效地确定访问权限?
我的代码:
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;