Strike
Problem gelöst.
Ursache war ein falsch gesetztes Flag bei den SecurityInformations. Der Fehler lag genau in der Routine MakeControlBits, und dieser Fehler ist auch in meiner C++-Vorlage.
Jetzt sieht die Routine wie folgt aus:
Delphi-Quellcode:
procedure MakeControlBits;
begin
aclPresent := False;
aclDefault := False;
SDRevision := 0;
psd := 0;
if not (GetSecurityDescriptorControl(pSecurityDescriptor, psd, SDRevision)) then
DoError(GetLastError);
if ((SecurityInformation and DACL_SECURITY_INFORMATION) = DACL_SECURITY_INFORMATION) then
begin
if ((psd and SE_DACL_PROTECTED) = SE_DACL_PROTECTED) then
begin
SecurityInformation := SecurityInformation or PROTECTED_DACL_SECURITY_INFORMATION;
if not (SetSecurityDescriptorControl(NewSecurityDescriptor, SE_DACL_PROTECTED, SE_DACL_PROTECTED)) then
DoError(GetLastError);
end
else
begin
if ((psd and SE_DACL_AUTO_INHERIT_REQ) = SE_DACL_AUTO_INHERIT_REQ) then
begin
SecurityInformation := SecurityInformation or UNPROTECTED_DACL_SECURITY_INFORMATION;
if not (SetSecurityDescriptorControl(NewSecurityDescriptor, SE_DACL_AUTO_INHERIT_REQ, SE_DACL_AUTO_INHERIT_REQ)) then
DoError(GetLastError);
end;
end;
end;
if ((SecurityInformation and SACL_SECURITY_INFORMATION) = SACL_SECURITY_INFORMATION) then
begin
if ((psd and SE_SACL_PROTECTED) = SE_SACL_PROTECTED) then
begin
SecurityInformation := SecurityInformation or PROTECTED_SACL_SECURITY_INFORMATION;
if not (SetSecurityDescriptorControl(NewSecurityDescriptor, SE_SACL_PROTECTED, SE_SACL_PROTECTED)) then
DoError(GetLastError);
end
else
begin
if ((psd and SE_SACL_AUTO_INHERIT_REQ) = SE_SACL_AUTO_INHERIT_REQ) then
begin
SecurityInformation := SecurityInformation or UNPROTECTED_SACL_SECURITY_INFORMATION;
if not (SetSecurityDescriptorControl(NewSecurityDescriptor, SE_SACL_AUTO_INHERIT_REQ, SE_SACL_AUTO_INHERIT_REQ)) then
DoError(GetLastError);
end;
end;
end;
end;
Zur Optimierung hab ich NewSI noch rausgeschmissen und dafür SecurityInformation vor dem Aufruf
noch korregiert:
Delphi-Quellcode:
SecurityInformation := SecurityInformation and not (SI_OWNER_RECURSE or SI_RESET_DACL_TREE or SI_RESET_SACL_TREE);
dErr := TreeResetNamedSecurityInfoW(pwidechar(ffilename),
SE_FILE_OBJECT,
SecurityInformation,
NewOwner,
NewGroup,
NewDACL,
NewSACL,
True,
@DoTreeProgress,
ProgressInvokeEveryObject,
SELF);
Jetzt funktioniert das ganze. Sogar die Callback-Routine wird aufgerufen.
Danke an alle die hier mitgeholfen haben.
Thanks to all they helped here