Вниз
Скачать: CL | DM;

Доступ к папкам в 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 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.012 c
1-81754
Vulko
2003-08-09 03:12
2003.08.25
Почему компилятору не нравится эта строка?


14-81951
Затейник - некрофил (НАСТОЯЩИЙ)
2003-08-06 19:32
2003.08.25
Стоит ли регистрироваться?


14-81914
Карелин Артем
2003-08-07 14:08
2003.08.25
А я на работе сейчас пиво пью.


1-81619
DoNotKnow
2003-08-12 23:39
2003.08.25
Активация приложения


1-81626
Itsme
2003-08-12 15:24
2003.08.25
ошибка RPC-сервера




   Наверх