none
Creating an elevated COM object with context = CLSCTX_INPROC_SERVER RRS feed

  • Question

  • Hi,

    I am trying to create an elevated in-process COM object to do some work in environments with UAC enabled.  I am experiencing problems and would like to know if I am doing anything wrong.  (Please forgive my inexperience with COM) 

    Problem:

    Trying to create an elevated COM object with the CoCreateInstanceAdmin api with the class context set to CLSCTX_INPROC_SERVER
    returns the error code: "0x80080017 The class is not configured to support Elevated activation"


    Background:

    The class I am running, myClass, is configured to run in process.  As a test, calling CoCreateInstance() with the class context set as CLSCTX_LOCAL_SERVER returns E_NOINTERFACE, as expected; calling with CLSCTX_INPROC_SERVER results in success.

    In trying to configure this class to run with elevation, I followed the instructions in the COM Elevation Moniker article:
    http://msdn.microsoft.com/en-us/library/ms679687(VS.85).aspx

    I followed these steps:
    1)  Add elevation to my class in registry
    HKEY_LOCAL_MACHINE\Software\Classes\CLSID
        {CLSID_MyClass}
            Elevation
                Enabled = 1

    2)  Add display string to my class in registry
    HKEY_LOCAL_MACHINE\Software\Classes\CLSID
        {CLSID_MyClass}
            LocalizedString = @pathToMyComDLL,-myStringResourceNum

    3)  Add DllSurrogate entry to the AppId reg entry for MyComDLL which contains MyClass  (Not covered in article but seems to be necessary)
    HKEY_LOCAL_MACHINE\Software\Classes\AppID
        {AppID_MyComDLL}
            DllSurrogate = <empty string>

    After following steps #1 - 3
    and executing the following steps, I execute the following code (taken verbatim from the previous article )

    HRESULT CoCreateInstanceAsAdmin( HWND hwnd, REFCLSID rclsid, REFIID riid, __out void** ppv )
    {
        BIND_OPTS3 bo;
        WCHAR  wszCLSID[50];
        WCHAR  wszMonikerName[300];
    
        StringFromGUID2( rclsid, wszCLSID, sizeof( wszCLSID ) / sizeof( wszCLSID[0] ) ); 
        HRESULT hr = StringCchPrintf( wszMonikerName, 
    sizeof( wszMonikerName ) / sizeof( wszMonikerName[0] ), L"Elevation:Administrator!new:%s",
    wszCLSID ); if ( FAILED( hr ) ) return hr; memset( &bo, 0, sizeof( bo ) ); bo.cbStruct = sizeof( bo ); bo.hwnd = hwnd; bo.dwClassContext = CLSCTX_LOCAL_SERVER; return CoGetObject( wszMonikerName, &bo, riid, ppv ); }




    The code returns E_NOINTERFACE. 

    Note that if step #1 is not performed, the code returns
    "0x80080017 The class is not configured to support Elevated activation"


    An error code of E_NOINTERFACE leads me to believe that the setup in steps #1-3 are correct, because at this point the return value matches that of just calling CoCreateInstance() with CLSCTX_LOCAL_SERVER.

    However calling the previous block of code with the following line changed:
    bo.dwClassContext  = CLSCTX_INPROC_SERVER;
    

    results in a return value of
    "0x80080017 The class is not configured to support Elevated activation"

    which is the same return value as if I had not configured the class for elevation at all (not performed steps #1-3)

    Can anyone help with this?  It seems to me like the configuration I've done above is not correct in this case.

    Thanks!
    Wednesday, July 1, 2009 9:40 PM

All replies

  • Let me ask a simpler question:

    Is it possible to create in process COM objects using the elevation moniker?  

    (i.e. COM objects created with context CLSCTX_INPROC_SERVER as opposed to CLSCTX_LOCAL_SERVER)
    Thursday, July 2, 2009 5:51 PM
  • Hi – I think my information can help you.

    I think you should check out our UAC samples at: http://cfx.codeplex.com we have for unmanaged code to like C/C++ Win32.

    I hope this information was helpful…

    Have a nice day…

    Best regards,
    Fisnik


    Coder24.com
    Friday, August 14, 2009 11:34 AM
  • Elevation only happens on a per-process basis, when the process is being launched only.  You won't be able to create in-process, elevated, COM objects using the elevation moniker in a non-elevated process.
    Friday, August 28, 2009 11:51 PM
  • Hello BigManStan:

    How is the situation on your side?
    Is this thread solved or NOT?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik


    Coder24.com
    Friday, October 30, 2009 11:45 AM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Sunday, December 27, 2009 10:35 AM
  • Hi BigManStan:

    Is this thread solved or NOT?
    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Saturday, January 2, 2010 2:18 PM