开发者

Outlook 2002 C# COM Add-In build with VS2008 does not start

开发者 https://www.devze.com 2023-01-19 01:04 出处:网络
I am facing a curious problem: I am trying to build a Add-In for Outlook 2002 with Visual Studi开发者_StackOverflow社区o 2008 using the shared add-in template.

I am facing a curious problem: I am trying to build a Add-In for Outlook 2002 with Visual Studi开发者_StackOverflow社区o 2008 using the shared add-in template. I want a simple hello world within the OnStartUpComplete method. That works pefectly on my development machine, but not at all on a clean machine with outlook 2002. I used the generated setup project to install the add in. Load behavior changed back from 3 to 2 after starting outlook, but there neither comes an exception nor any other error. What do I have to do to get the Add-In working on other than the dev machine?

Thanks a lot,

Michael


i believe your are a lockback policy victim. add a bypass key to registry, then it works. modern office versions or vsto creates the key while installation. the effect is: install a modern office too and the adddin now are also loaded in older office. please take a look

code snippet taken from NetOffice http://netoffice.codeplex.com

public static void RegisterFunction(Type type)
{
            try
            {
                // add codebase value
                Assembly thisAssembly = Assembly.GetAssembly(typeof(ExampleClassicAddin));
                RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\1.0.0.0");
                key.SetValue("CodeBase", thisAssembly.CodeBase);
                key.Close();

                key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32");
                key.SetValue("CodeBase", thisAssembly.CodeBase);
                key.Close();

                // add bypass key
                // http://support.microsoft.com/kb/948461
                key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}");
                string defaultValue = key.GetValue("") as string;
                if (null == defaultValue)
                    key.SetValue("", "Office .NET Framework Lockback Bypass Key");
                key.Close();

                // add addin key
                Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable");
                Registry.CurrentUser.CreateSubKey(_addinRegistryKey + _prodId);
                RegistryKey rk = Registry.CurrentUser.OpenSubKey(_addinRegistryKey + _prodId, true);
                rk.SetValue("LoadBehavior", Convert.ToInt32(3));
                rk.SetValue("FriendlyName", _addinName);
                rk.SetValue("Description", "NetOffice COMAddinExample with classic UI");
                rk.Close();
            }
            catch (Exception ex)
            {
                string details = string.Format("{1}{1}Details:{1}{1}{0}", ex.Message, Environment.NewLine);
                MessageBox.Show("An error occured." + details, "Register " + _addinName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消