After some msdn searhing, I came up with the following to determine the
effective access rights on a file:
function CheckAccessRights(const UserName, Filename: string): ACCESS_MASK;
var
DACL: PACL;
SecDesc: PSECURITY_DESCRIPTOR;
User: TRUSTEE;
ActualUser: string;
begin
DACL := nil;
SecDesc := nil;
Win32Check(GetNamedSecurityInfo(PChar(FileName), SE_FILE_OBJECT,
DACL_SECURITY_INFORMATION,
nil, nil, @DACL, nil, SecDesc) = ERROR_SUCCESS);
try
if Assigned(DACL) then
begin
FillChar(User, SizeOf(User), 0);
User.MultipleTrusteeOperation := NO_MULTIPLE_TRUSTEE;
User.TrusteeForm := TRUSTEE_IS_NAME;
User.TrusteeType := TRUSTEE_IS_USER;
if Length(UserName) > 0 then
ActualUser := PChar(UserName)
else
ActualUser := PChar(LoggedOnUser);
User.ptstrName := PChar(ActualUser);
Win32Check(GetEffectiveRightsFromAcl(DACL^, User, Result) =
ERROR_SUCCESS);
end
else
Result := 0;
finally
Win32Check(LocalFree(Cardinal(SecDesc)) = 0);
end;
end;
The call to GetEffectiveRightsFromAcl(DACL^, User, Result) results in an
exception "System Error. Code: 998. Invalid access to memory location".
What's going wrong here?
Peter Laman
Senior Software Engineer
Lance ICT Group
Roermond, the Netherlands
http://www.lance-safety.com
-
"Nobody ever died of hard work", they say. But why take the risk? (Ronald
Reagan)
----
----
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk