none
How to disable COM add-ins programmatically RRS feed

  • Question

  • Hi all,

    I'm developing Word Add-In (Application level), in my application I would like to disable/enable other third-party Word Add-In at run-time.

    I'm using COMAddIns to access other Add-In as bellow

     foreach (COMAddIn addin in app.Application.COMAddIns)
                {
                    string badAddin="AddIn need to disable";
                    if (addin.Description.ToLower().Contains(badAddin.ToLower()))
                    {
                        System.Diagnostics.Debug.WriteLine("**** DEBUG detect bad AddIn ****");
                        System.Diagnostics.Debug.WriteLine(addin.Description);
                        if (addin.Connect)
                        {
                            // Set disable AddIn
                            addin.Connect = false;
                            
                        }
                    }
                }

    When running I got error "this add-in is installed for all users on this computer and can only be connected or disconnected by an administrator"

    So could you please help let me know there is any way to enable/disable other Add-In whitout required administrator?

    Thanks

    Johnny

     
    Thursday, September 4, 2014 11:49 AM

Answers

  • Hi Johnny

    I don't have a solution for you, but I do have some background information about why things are the way they are...

    Originally, VSTO was specifically designed to NOT support installing in the HKLM and Microsoft wanted to disable that completely for all Office Add-ins. There were lots and lots of complaints because developers (and users) were accustomed to being able to install once on a machine for all users (HKLM hive). So, reluctantly, the policy was dropped and support for HKLM installation was allowed to continue.

    Since the problem and behavior you're seeing is "by design" you may need to "simply" inform your user that "bad add-ins" are installed on the machine and give instructions on how to make the necessary changes. Or perhaps provide a separate application the user can run that closes Word, makes the necessary changes, then restarts Word.

    Of course, if this is a corporate environment it's best to work with IT to solve such problems, especially since IT can use Group Policies to handle a most problems of this nature...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Johnny-Le Wednesday, November 5, 2014 4:06 AM
    Friday, September 12, 2014 7:14 PM
    Moderator

All replies

  • Addins installed for all users are listed in HKLM rather than HKCU for the current user's addins.

    You need to be a local admin or a power user to be able to modify HKLM.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, September 4, 2014 2:26 PM
  • Hi Dmitry,

    As I know if set value in HKCU is the same as HKLM, when AddIn startup it will prefer to HKCU first.

    But when I tried to add registry is the same both HKLM and HKCU, seem it not work. Do you have any suggestion? Because my application would be used for normal user not required Administrator.

    Thanks

    Johnny

    Thursday, September 4, 2014 4:06 PM
  • Not exactly so as Dmitry wrote.

    Of course, for a per-machine add-in, you can set the Connect property if your application is run with administrative permissions. But on a system with UAC enabled, in addition to having administrative permissions, the application process must be elevated.

    You can disable the add-in manually in Outlook, even a per-machine add-in. It means that you can add a HKCU entry to get it done. If I look at the registry, the value of 'LoadBehavior' of the Addin  under HKEY_CURRENT_USER has changed. But the value of 'LoadBehavior' under HKEY_LOCAL_MACHINE has not changed.  This is expected behavior - normal user can't disable the Addin for all users.

    Be aware, in that case the add-in will be disabled for the current user only.

    Thursday, September 4, 2014 4:41 PM
  • Hi Eugene Astafiev,

    Thank you for your advice, as mention above I would like to do this job by programmatically not manually.

    I also tried to set AddIn registry "LoadBehavior" in HKEY_LOCAL_MACHINE value=2  and set "LoadBehavior" in HKEY_CURRENT_USER value=3, then run in code again when call 

    addin.Connect = false;

    The error is the same.

    If we change HKEY_CURRENT_USER by programmatically can any way to refresh Word Application without restart to update registry change.

    Many thanks

    Johnny


    • Edited by Johnny-Le Friday, September 5, 2014 3:43 AM
    Friday, September 5, 2014 2:50 AM
  • Johnny,

    What Outlook version do you use?

    Friday, September 5, 2014 1:13 PM
  • Hi,

    I'm using Word AddIn for MS Office 2010 & 2013, not Outlook

    Best regards

    Johnny

    Saturday, September 6, 2014 12:22 AM
  • Hello Johnny,

    You need to restart the host application to apply the changes. Or run the host application with admin privileges elevated. Thus, you will be able to set the HKLM hive values and set the Connect property.

    Tuesday, September 9, 2014 11:54 AM
  • Hi Eugene Astafiev,

    Thank you, so do we have any Method to restart host application by programmatically, not manual.

    Seem method "Application.Restart" does not support in Office Add-In. It just available in Win form System.Windows.Forms.Application.Restart()

    Best regards

    Johnny



    • Edited by Johnny-Le Friday, September 12, 2014 2:51 AM
    Friday, September 12, 2014 2:36 AM
  • There is no method for restarting. But you are free to use the Quit or Close method of the Application class. Then you can start the host application using the Process.Run method specifying the path to the executable file. As you may see you need to use any external utility for restarting the host.
    Friday, September 12, 2014 4:35 AM
  • Hi Eugene Astafiev,

    Thanks for your response. Seem it's bad user experience.

    As I seen there is method "Application.COMAddIns.Update()" allow to update COMAddIns content store in Windows Registry but seem it not work. I'm not sure is any way to refresh Registry for COMAddIn by programmatically.

    Best regards

    Johnny

    Friday, September 12, 2014 8:59 AM
  • Hi Johnny

    I don't have a solution for you, but I do have some background information about why things are the way they are...

    Originally, VSTO was specifically designed to NOT support installing in the HKLM and Microsoft wanted to disable that completely for all Office Add-ins. There were lots and lots of complaints because developers (and users) were accustomed to being able to install once on a machine for all users (HKLM hive). So, reluctantly, the policy was dropped and support for HKLM installation was allowed to continue.

    Since the problem and behavior you're seeing is "by design" you may need to "simply" inform your user that "bad add-ins" are installed on the machine and give instructions on how to make the necessary changes. Or perhaps provide a separate application the user can run that closes Word, makes the necessary changes, then restarts Word.

    Of course, if this is a corporate environment it's best to work with IT to solve such problems, especially since IT can use Group Policies to handle a most problems of this nature...


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Johnny-Le Wednesday, November 5, 2014 4:06 AM
    Friday, September 12, 2014 7:14 PM
    Moderator
  • Hi Jonny,

    The COMAddins class doesn't provide any Update related properties. COM add-ins are not designed for updating on the fly.

    Friday, September 12, 2014 7:22 PM