#80 registring a win32com server with non admin privilges only

closed-out-of-date
nobody
None
5
2010-08-30
2007-10-02
Robert Langmeier
No

I produced this patch to be able to register and use a COM server with insufficient privileges.

A little explanation:
- As a non admin user, you cannot write HKEY_CLASSES_ROOT, but you can register a COM server into HKEY_CURRENT_USER
- HKEY_CLASSES_ROOT is a consolidated view of HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER (see MSDN)
- The client can always read the registry keys in HKEY_CLASSES_ROOT

It would be great if it can be integrated in a future build. Some check has to be done for parts i'm not using. Registring and unregistring "Standard" servers is correct and functionning.

Discussion

  • patched file

     
    Attachments
  • Logged In: YES
    user_id=75471
    Originator: YES

    just corrected a bug in _get_classe_hkey and modified RegisterServer
    File Added: register-patch.py

     
  • modified patch

     
    Attachments
  • Mark Hammond
    Mark Hammond
    2008-05-05

    Logged In: YES
    user_id=14198
    Originator: NO

    Note that _get_classe_hkey() can probably go - just checking if you can open the key with KEY_ALL_ACCESS should work. Note too that the CVS version of register.py takes a different approach - it attempts to elevate and retry. This means we would probably need to add a new cmdline option to specify which behaviour you desire. Finally, it would be great if you can send me a "diff" which compares the old and new files (use "diff -u") - otherwise it is very hard to determine what changes you made.

    Thanks

     
  • Mark Hammond
    Mark Hammond
    2008-07-04

    Logged In: YES
    user_id=14198
    Originator: NO

    FWIW, VS 2008 appears to use "regsvr32 /s /i:user dllname.dll" when you select the "register per user" option in their IDE UI (I can't recall the exact spelling of the UI option). It's undocumented best I can tell, but I stumbled across how IronPython checks for this, and it worked!

    The code a C++ DLL needs to support this in MSVS is below (from Tamarin): it makes sense that we do the same to support this functionality?

    STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
    {
    HRESULT hr = E_FAIL;
    // MSVC will call "regsvr32 /i:user" if "per-user registration" is set as a
    // linker option - so handle that here (its also handle for anyone else to
    // be able to manually install just for themselves.)
    static const wchar_t szUserSwitch[] = L"user";
    if (pszCmdLine != NULL)
    {
    if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
    {
    AtlSetPerUserRegistration(true);
    // But ATL still barfs if you try and register a COM category, so
    // just arrange to not do that.
    _AtlComModule.m_ppAutoObjMapFirst = _AtlComModule.m_ppAutoObjMapLast;
    }
    }
    if (bInstall)
    {
    hr = DllRegisterServer();
    ...

     
  • Mark Hammond
    Mark Hammond
    2010-08-30

    we can now register either way I believe.

     
  • Mark Hammond
    Mark Hammond
    2010-08-30

    • status: open --> closed-out-of-date