Форум: "WinAPI";
Текущий архив: 2003.08.25;
Скачать: [xml.tar.bz2];
ВнизДоступ к папкам в Win2000 Найти похожие ветки
← →
VD (2003-06-22 19:25) [0]Как программно открыть общий доступ к созданной дирректории под правами администратора, необходимо, чтобы и под юзером эта дирректория была полностью доступна (запись и создание файлов)
← →
Ученик (2003-06-22 19:29) [1]function FileSetAccess(const FileName, UserName: string; dwAccess : DWord) : Boolean;
var
dwSize, dwError : DWord;
bDaclPresent : Bool;
bDaclDefaulted : Bool;
ea : EXPLICIT_ACCESS;
OldAcl : PACL;
NewAcl : PACL;
psd : PSECURITY_DESCRIPTOR;
sd : SECURITY_DESCRIPTOR;
begin
Result := False; psd := nil; NewAcl := nil;
if not GetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION, Pointer(1),
0, dwSize) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then try
psd := HeapAlloc(GetProcessHeap, 8, dwSize);
if psd <> nil then begin
BuildExplicitAccessWithName(@ea, PChar(UserName), dwAccess,
SET_ACCESS, SUB_CONTAINERS_AND_OBJECTS_INHERIT{NO_INHERITANCE});
Result := GetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION,
psd, dwSize, dwSize) and
GetSecurityDescriptorDacl(psd, bDaclPresent, OldAcl, bDaclDefaulted) and
(SetEntriesInAcl(1, @ea, OldAcl, NewAcl) = ERROR_SUCCESS) and
InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION) and
SetSecurityDescriptorDacl(@sd, True, NewAcl, False) and
SetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION, @sd);
end
finally
dwError := GetLastError;
if NewAcl <> nil then
LocalFree(HLocal(NewAcl));
if psd <> nil then
HeapFree(GetProcessHeap, 0, psd);
( dwError) function FileSetAccess(const FileName, UserName: string; dwAccess : DWord) : Boolean;
var
dwSize, dwError : DWord;
bDaclPresent : Bool;
bDaclDefaulted : Bool;
ea : EXPLICIT_ACCESS;
OldAcl : PACL;
NewAcl : PACL;
psd : PSECURITY_DESCRIPTOR;
sd : SECURITY_DESCRIPTOR;
begin
Result := False; psd := nil; NewAcl := nil;
if not GetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION, Pointer(1),
0, dwSize) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then try
psd := HeapAlloc(GetProcessHeap, 8, dwSize);
if psd <> nil then begin
BuildExplicitAccessWithName(@ea, PChar(UserName), dwAccess,
SET_ACCESS, SUB_CONTAINERS_AND_OBJECTS_INHERIT{NO_INHERITANCE});
Result := GetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION,
psd, dwSize, dwSize) and
GetSecurityDescriptorDacl(psd, bDaclPresent, OldAcl, bDaclDefaulted) and
(SetEntriesInAcl(1, @ea, OldAcl, NewAcl) = ERROR_SUCCESS) and
InitializeSecurityDescriptor(@sd, SECURITY_DESCRIPTOR_REVISION) and
SetSecurityDescriptorDacl(@sd, True, NewAcl, False) and
SetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION, @sd);
end
finally
dwError := GetLastError;
if NewAcl <> nil then
LocalFree(HLocal(NewAcl));
if psd <> nil then
HeapFree(GetProcessHeap, 0, psd);
SetLastError(dwError)
end
end;
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2003.08.25;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.008 c