none
Register .NET Assembly as COM Server (UAC enabled) RRS feed

  • Question

  • Hello,

    when I try to register a C# .NET assembly in Visual Studio 2008 as a COM Server, registration fails because of missing privileges. Error message is:

    error MSB3216: Cannot register assembly "myassembly.dll" - access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\Record' is denied.


    This occurs on Windows 7 and Windows Vista. (Members of the development team do not have administrator privileges.)
    Is there something like AtlSetPerUserRegistration in .NET.
    Tuesday, October 27, 2009 12:24 PM

Answers

  • Hello

    Regsvr32, Regasm, and the registration method used by Visual Studio do not give the choice to register COM per-user because they have no per-user or per-system context, so they have to be elevated to register the component.

    A possible workaround is to add a MSI setup project. An MSI setup can choose per-user or per-system because there is infrastructure that supports it at install time and gives the installing user a choice.

    1. uncheck the Register for COM interop option.
    2. add a setup project (Other Project Types / Setup and Deployment / Setup Project)
    3. Right-click the Setup project, select Add / Project Output / Primary output of your COM project.
    4. Select Primary output of your COM project in the Solution Explorer, and display its properties. Set the Register property to be vsdrpCOM.
    5. By default, the setup project always gives the UAC dialog, even though you install it per user. To turn off UAC compilance, you need to use Orca, a tool provided by Windows SDK.
    6. After you install and launch Orca, open the resulting msi file.
    7. In the View menu, select Summary Information, and check the UAC Compilant option.
    8. Save and close Orca
    9. Run the setup project. Change the installation folder from the default C:\Program Files\... to a folder that is not restricted by UAC.

    Please let me know whether this works for you.

    Another option:

    1. still uncheck the Register for COM interop option.
    2. instead of using a msi setup project, use a .reg file to register COM component to per-user profile. You can prepare a .REG file with all needed regsitry keys for the COM component. Next, import regsitry by using the REG.exe tool:

    reg.exe import <your reg file>


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, October 28, 2009 8:19 AM
    Moderator

All replies

  • Hello

    Regsvr32, Regasm, and the registration method used by Visual Studio do not give the choice to register COM per-user because they have no per-user or per-system context, so they have to be elevated to register the component.

    A possible workaround is to add a MSI setup project. An MSI setup can choose per-user or per-system because there is infrastructure that supports it at install time and gives the installing user a choice.

    1. uncheck the Register for COM interop option.
    2. add a setup project (Other Project Types / Setup and Deployment / Setup Project)
    3. Right-click the Setup project, select Add / Project Output / Primary output of your COM project.
    4. Select Primary output of your COM project in the Solution Explorer, and display its properties. Set the Register property to be vsdrpCOM.
    5. By default, the setup project always gives the UAC dialog, even though you install it per user. To turn off UAC compilance, you need to use Orca, a tool provided by Windows SDK.
    6. After you install and launch Orca, open the resulting msi file.
    7. In the View menu, select Summary Information, and check the UAC Compilant option.
    8. Save and close Orca
    9. Run the setup project. Change the installation folder from the default C:\Program Files\... to a folder that is not restricted by UAC.

    Please let me know whether this works for you.

    Another option:

    1. still uncheck the Register for COM interop option.
    2. instead of using a msi setup project, use a .reg file to register COM component to per-user profile. You can prepare a .REG file with all needed regsitry keys for the COM component. Next, import regsitry by using the REG.exe tool:

    reg.exe import <your reg file>


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, October 28, 2009 8:19 AM
    Moderator
  • Thanks alot!

    I will use the second option because it is easier for developers to register a COM component with a .reg in a pre-build step.

    Regards
    Thomas

    Wednesday, October 28, 2009 9:23 AM
  • You are welcome! :)
    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, October 28, 2009 9:25 AM
    Moderator