Windows > Windows Forms Forums > ClickOnce and Setup & Deployment Projects > Using "elevated" COM and reg-free COM together
Ask a questionAsk a question
 

AnswerUsing "elevated" COM and reg-free COM together

  • Thursday, November 05, 2009 6:35 PMRoy in Acworth Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have learned how to create and use a registered elevated COM object.  I have learned how to use reg-free COM via Click-Once.  The question is, is there any way to indicate that the reg-free COM object should be elevated?

    I own the COM object code and the calling program code, so I can make any code changes required to make this work.

    Thanks
    Thanks Roy

Answers

  • Friday, November 13, 2009 5:25 AMAland LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Roy,

    Sorry for not getting the key problem. I have analyzed the issue again, these are some concepts for preparation:
    1. Out-of process COM server does not support reg-free. The document below shows the detail:
    http://msdn.microsoft.com/en-us/magazine/cc188708.aspx.

    2. Not every component is a candidate for use under Reg-Free COM. Now that out-of-process COM does not support reg-free, you must use an in-process COM server. In-proc COM runs in the space of its host process. If you want the COM being elevated, the host process must also be elevated.

    1.    COM elevation moniker does not support the requirement of reg-free COM, since it requires out-of-proc COM or DLL COM server registered into COM+.

    So I can provide two solutions:

    1.    Elevate your host process. You can mark your host app as “requireAdministrator”. In this way, it will always be run as admin. I have already provide the method in my last reply.

    2.    If you do not expect the host process to always run as admin, make an additional exe that is responsible for loading and calling reg-free COM. Your host process still run as ordinary user. Your host process ShellExecute(“runas”) that additional exe, and perform IPC with it to issue COM calls.

    Let me know if this helps or not.
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.

All Replies

  • Tuesday, November 10, 2009 9:43 AMAland LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Roy,

    l  To create an elevated COM object, we can use The COM Elevation Moniker. The basic idea is creating a elevation moniker, which is a string like below:
              Elevation:Administrator!new:{guid}
    Then we can take this string as a parameter in the CoGetObject method to initialize the com component.

    The document below shows the details about how to create an elevated COM object using elevation moniker. Please pay more attention on the CoCreateInstanceAsAdmin method.
    http://msdn.microsoft.com/en-us/library/ms679687(VS.85).aspx

    l  To elevate an application, you can follow the document below to modify the menifest:
    http://msdn.microsoft.com/en-us/library/bb756929.aspx
    If the project is in VB or C#, the method would be simpler. For example, the manifest can be like below:

    1.    In VB, we can click the View UAC Settings button on the Application tab of the project properties and directly modify the menifest content, then rebuild.

    2.    In C#, we can add a menifest file to the project and modify its content, then rebuild. The manifest file template name is Application Manifest File.

    Let me know if this helps or not.
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
  • Friday, November 13, 2009 3:10 AMRoy in Acworth Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    No, your information does not help at all.

    As I stated, I know how to do what you just told me how to do.

    I have created and used several elevated managed COM objects.  They all require extra information in the registry that, from what I can determine, is to support the Elevation Moniker.

    What I need to understand is if there is a way to support the Elevation Moniker in a reg-free/isolated com environment.

    Thanks 
    Thanks Roy
  • Friday, November 13, 2009 5:25 AMAland LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Roy,

    Sorry for not getting the key problem. I have analyzed the issue again, these are some concepts for preparation:
    1. Out-of process COM server does not support reg-free. The document below shows the detail:
    http://msdn.microsoft.com/en-us/magazine/cc188708.aspx.

    2. Not every component is a candidate for use under Reg-Free COM. Now that out-of-process COM does not support reg-free, you must use an in-process COM server. In-proc COM runs in the space of its host process. If you want the COM being elevated, the host process must also be elevated.

    1.    COM elevation moniker does not support the requirement of reg-free COM, since it requires out-of-proc COM or DLL COM server registered into COM+.

    So I can provide two solutions:

    1.    Elevate your host process. You can mark your host app as “requireAdministrator”. In this way, it will always be run as admin. I have already provide the method in my last reply.

    2.    If you do not expect the host process to always run as admin, make an additional exe that is responsible for loading and calling reg-free COM. Your host process still run as ordinary user. Your host process ShellExecute(“runas”) that additional exe, and perform IPC with it to issue COM calls.

    Let me know if this helps or not.
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.