HRESULT CRegisterExtension::RegisterAppAsLocalServer()

in Docs-ContextMenuSample/ExplorerCommandVerb/RegisterExtension.cpp [73:104]


HRESULT CRegisterExtension::RegisterAppAsLocalServer(PCWSTR pszFriendlyName, PCWSTR pszCmdLine) const
{
    HRESULT hr = _EnsureModule();
    if (SUCCEEDED(hr))
    {
        WCHAR szCmdLine[MAX_PATH + 20];
        if (pszCmdLine)
        {
            StringCchPrintf(szCmdLine, ARRAYSIZE(szCmdLine), L"%s %s", _szModule, pszCmdLine);
        }
        else
        {
            StringCchCopy(szCmdLine, ARRAYSIZE(szCmdLine), _szModule);
        }

        hr = RegSetKeyValuePrintf(_hkeyRoot, L"Software\\Classes\\CLSID\\%s\\LocalServer32", L"", szCmdLine, _szCLSID);
        if (SUCCEEDED(hr))
        {
            hr = RegSetKeyValuePrintf(_hkeyRoot, L"Software\\Classes\\CLSID\\%s", L"AppId", _szCLSID, _szCLSID);
            if (SUCCEEDED(hr))
            {
                hr = RegSetKeyValuePrintf(_hkeyRoot, L"Software\\Classes\\CLSID\\%s", L"", pszFriendlyName, _szCLSID);
                if (SUCCEEDED(hr))
                {
                    // hr = RegSetKeyValuePrintf(_hkeyRoot, L"Software\\Classes\\AppID\\%s", L"RunAs", L"Interactive User", _szCLSID);
                    hr = RegSetKeyValuePrintf(_hkeyRoot, L"Software\\Classes\\AppID\\%s", L"", pszFriendlyName, _szCLSID);
                }
            }
        }
    }
    return hr;
}