Unregister Add-In for single application

Add-in Express™ Support Service
That's what is more important than anything else

Unregister Add-In for single application
 
Tobias Böhm




Posts: 73
Joined: 2009-07-06
Hello,

maybe my question is somewhat similar to the one asked here http://www.add-in-express.com/forum/read.php?FID=5&TID=8406. I have a add-in that I might want to use in Word, Excel and PowerPoint. During installation I present the user with 3 checkboxes where she can chose in which of the three applications the add-in should be loaded. I don't just want to soft-disable the addin by for example hiding the UI but I would like to disable the addin - it shouldn't even appear in the COM-Addins-List.

What I've tried is creating a installer-class and setting the value LoadBehavior of the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\{Application}\Addins\{AddinName} to 0 if the user didn't select that application.
Unfortunately I get a "Cannot write to the registry key." when I try to do this programmatically although it workt manually with REGEDIT.EXE

Do you have an idea how I can unload the addin for a certain Office-Application?

Thanks,
Tobi
Posted 19 Nov, 2010 02:43:18 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Tobias,

You are on the right avenue. It looks like you don't have sufficient privileges to modify the HKLM hive. How and when do you try to modify the specified windows registry entry? What OS do you use? Do you use the MSI installer?
.NET, Extended MAPI, Windows Phone & RT
Posted 19 Nov, 2010 04:43:52 Top
Tobias Böhm




Posts: 73
Joined: 2009-07-06
I tried several different "times". First in AddinModule_AddinInitialize and also in InstallerClass_AfterInstall.

The code I use both times is

        public static void SetAddinEnabled(MsftApp app, bool enabled)
        {
            string baseRegistryPath = @"SOFTWAREMicrosoftOffice" + app + @"AddinsAddinName.AddinModule";

            RegistryKey key = Registry.LocalMachine.OpenSubKey(baseRegistryPath);

            if (key != null)
            {
                key.SetValue("LoadBehavior", enabled ? 3 : 0);
            }
        }


The OS is XP and yes, I use the MSI installer.
Any idea?
Posted 19 Nov, 2010 05:29:01 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Tobias,

1. Did you try to debug? You can use the System.Diagnostics.Debug.WriteLine method to print the debug statements.
2. Please try to use a regular .exe instead of the Installer class.
.NET, Extended MAPI, Windows Phone & RT
Posted 19 Nov, 2010 05:53:00 Top
Tobias Böhm




Posts: 73
Joined: 2009-07-06
I debugged it. It just throws an exception "Cannot write to the registry key." when calling SetValue on the key. I changed the line to

                key.SetValue("LoadBehavior", enabled ? 3 : 0, RegistryValueKind.DWord);

but that didn't work either.

Installing with the exe doesn't work as well.
Posted 19 Nov, 2010 09:50:55 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Tobias,

I have just developed a sample add-in project with my own custom action. I used the following code in the exe:


using(Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftOfficeExcelAddinsMyAddin6.AddinModule", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.SetValue))
{
    if (key != null)
    {
        key.SetValue("LoadBehavior", "0", Microsoft.Win32.RegistryValueKind.DWord);
    }
}


Does it work for you?
.NET, Extended MAPI, Windows Phone & RT
Posted 19 Nov, 2010 12:25:18 Top
Tobias Böhm




Posts: 73
Joined: 2009-07-06
That worked. From the installer class as well as from inside AddInInitialize.
Thank you very much!

Tobi
Posted 20 Nov, 2010 09:08:32 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
You are welcome, Tobias! :D
.NET, Extended MAPI, Windows Phone & RT
Posted 20 Nov, 2010 09:18:28 Top