HKEY_CLASSES_ROOT - ошибка 5 - ERROR_ACCESS_DENIED
От: пффф  
Дата: 06.05.24 21:57
Оценка:
Привет!

По идее, пользователю же можно туда писать-читать?

Создаю ключ в реестре так:
  regCreateKeyHelper
inline
HKEY regCreateKeyHelper(HKEY hKeyRoot, const std::wstring &path, REGSAM samDesired)
{
    if (isWindows32OnWindows64())
    {
        samDesired |= KEY_WOW64_64KEY;
    }
    
    HKEY hKeyRes = 0;
    DWORD dwDisposition = 0;

    LSTATUS status = RegCreateKeyExW( hKeyRoot
                                    , path.c_str()
                                    , 0 // reserved
                                    , 0 // lpClass - The user-defined class type of this key. This parameter may be ignored. This parameter can be NULL.
                                    , REG_OPTION_NON_VOLATILE // default, 0
                                    , samDesired
                                    , 0 // lpSecurityAttributes
                                    , &hKeyRes
                                    , &dwDisposition
                                    );
    if (status!=ERROR_SUCCESS)
    {
        return 0;
    }

    return hKeyRes;
}


Задаю переменную:
  registerShellExtentionHandlerApplication
inline
bool registerShellExtentionHandlerApplication(const std::wstring &appNameId, const std::wstring &shellVerb, const std::wstring &appCommand)
{

    // Компьютер\HKEY_CLASSES_ROOT\gg_app
    //     shell
    //       open
    //         command
    //           default value: "gg.exe" "%1"
    //  
    // HKEY_CLASSES_ROOT\.gg
    //     default value gg_app
    //  
    // The nameless key is the default one - https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.registry.setvalue?view=net-8.0&redirectedfrom=MSDN#overloads

    std::wstring regPath = appNameId;
    regPath.append(L"\\shell");
    regPath.append(L"\\");
    regPath.append(shellVerb);
    regPath.append(L"\\command");

    HKEY hKey = regCreateKeyHelper(HKEY_CLASSES_ROOT, regPath, KEY_READ|KEY_WRITE); // !!! Тут возвращает 0

    if (!hKey)
        return false;

    bool res = regSetValue(hKey, L"" /* varName */ , appCommand);

    RegCloseKey(hKey);

    return res;
}


Использую:
    bool regRes = registerShellExtentionHandlerApplication(L"gg-app", L"open", L"gg %1");


Правда, ломается до установки, на этапе regCreateKeyHelper

Что не так делаю?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.