Показать сообщение отдельно
  #2  
Старый 30.10.2011, 00:13
Asmoday74 Asmoday74 вне форума
Прохожий
 
Регистрация: 12.10.2010
Адрес: Челябинск
Сообщения: 22
Версия Delphi: XE2
Репутация: 893
По умолчанию

Почитал справку от мелкософта нашел следующее:
When you call the RegOpenKeyEx function, the system checks the requested access rights against the key's security descriptor. If the user does not have the correct access to the registry key, the open operation fails. If an administrator needs access to the key, the solution is to enable the SE_TAKE_OWNERSHIP_NAME privilege and open the registry key with WRITE_OWNER access. For more information, see Enabling and Disabling Privileges.

Пробую открыть нужный раздел с правами на смену владельца, все проходит удачно.
Код:
      
r := RegOpenKeyEx(AKey, PWideChar(APatch), 1,WRITE_OWNER, Key);
Однако права владельца остаются прежними.

Функцию для установки SE_TAKE_OWNERSHIP_NAME использую такую:
Код:
function SetPrivilege(privilegeName: string; enable: boolean): boolean;
var
  tpPrev, tp: TTokenPrivileges;
  token: THandle;
  dwRetLen: DWord;
begin
  result := False;
  try
    OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
      token); // ïполучаем маркер безопасности процесс- токен
    tp.PrivilegeCount := 1;
    if LookupPrivilegeValue(nil, pchar(privilegeName), tp.Privileges[0].LUID)
    then // получаем идентификатор привилегии - LUID
    begin
      if enable then
        tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
        // устанавливаем атрибуты привилегии
      else
        tp.Privileges[0].Attributes := 0;
      dwRetLen := 0;
      result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev), tpPrev,
        dwRetLen); // включаем или отключаем привилегию
    end;
  finally
    try
      CloseHandle(token);
    except
    end;
  end;
end;
Ответить с цитированием