2017-01-05 13 views
0

regasm.exeを使用して、エンドユーザーのマシンにOutlookプラグインをインストールしています。しかし、私は、ターミナルサーバー環境では、私のアドインがすべてのユーザーのために読み込まれないことに気付きました。 addinレジストリキーが現行のユーザーハイブの下に作成されていて、ローカルのマシンのハイブではないことがわかりました。ローカルマシンのレジストリハイブにOutlookアドインをインストールする

プラグマをインストールまたはアンインストールするときにregasmがHKLMの下にあるキーを作成/削除できるようにプラグインに追加できるものはありますか?

答えて

0

をアンインストールした上で、それらの変更をロールバックするようなコードを持っています私のサンプルNetOffice Outlook addinプロジェクトを掘り下げてください!

あなたが必要とするのは、ComRegisterFunctionAttributeComUnregisterFunctionAttributeという属性を持つ公開静的メソッドです。 Regasm.exeは、プラグインのインストールまたはアンインストール時にこれらのメソッドでコードを自動的に実行します。

私が使用しているコードは、HKLMレジストリキーをサポートするためにテンプレートから少し変更されています。これらのメソッドをOutlookアドインクラスに追加します。

これらを手動で処理する場合は、Alekの回答を使用できます。

[ComRegisterFunctionAttribute] 
    public static void RegisterFunction(Type type) 
    { 
     try 
     { 
      // add codebase value 
      Assembly thisAssembly = Assembly.GetAssembly(typeof(OutlookPlugin)); 
      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 outlook addin key 
      Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable"); 
      Registry.CurrentUser.CreateSubKey(_addinOfficeRegistryKey + _prodId); 
      RegistryKey rk = Registry.CurrentUser.OpenSubKey(_addinOfficeRegistryKey + _prodId, true); 
      rk.SetValue("LoadBehavior", Convert.ToInt32(3)); 
      rk.SetValue("FriendlyName", _addinFriendlyName); 
      rk.SetValue("Description", _addinDescription); 
      rk.Close(); 

      //Add registry key under HKLM 
      RegistryKey regHKLM = Registry.LocalMachine; 

      regHKLM = regHKLM.CreateSubKey(@"SOFTWARE\Microsoft\Office\Outlook\Addins\" + _prodId); 

      regHKLM.SetValue("Friendly Name", _addinFriendlyName); 
      regHKLM.SetValue("Description", _addinDescription); 
      regHKLM.SetValue("LoadBehavior", 3, RegistryValueKind.DWord); 
     } 
     catch (System.Exception ex) 
     { 
      string details = string.Format("{1}{1}Details:{1}{1}{0}", ex.Message, Environment.NewLine); 
      MessageBox.Show("An error occured." + details, "Register " + _prodId, MessageBoxButtons.OK, MessageBoxIcon.Error); 
     } 
    } 

    [ComUnregisterFunctionAttribute] 
    public static void UnregisterFunction(Type type) 
    { 
     try 
     { 
      Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable", false); 
      Registry.CurrentUser.DeleteSubKey(_addinOfficeRegistryKey + _prodId, false); 

      Registry.LocalMachine.DeleteSubKey(@"SOFTWARE\Microsoft\Office\Outlook\Addins\" + _prodId); 
     } 
     catch (System.Exception throwedException) 
     { 
      string details = string.Format("{1}{1}Details:{1}{1}{0}", throwedException.Message, Environment.NewLine); 
      MessageBox.Show("An error occured." + details, "Unregister " + _prodId, MessageBoxButtons.OK, MessageBoxIcon.Error); 
     } 
    } 
1

アドインの登録時にウインドウズのUACを避けたかったので、私はregasm.exeと同様の問題を抱えていたので、comレジストラを登録するための適切なレジストリキーを自分で作成しました。あなたはそれらの場所にレジストリキーを持ってそれに応じて、このコードを変更する必要があります

あなたがそれらをしたいし、明らかにあなたのアドイン

答えを見つけ
class ComAddinRegistrar 
{ 
    private static string CLSID = "{CLSID}"; 
    private static string ASSEMBLY_NAME = "Outlook.Addin"; 
    private static string ASSEMBLY_DLL = "Outlook.Addin.dll"; 
    private static string VERSION = "1.0.0.0"; 
    private static string IMPLEMENTED_CATEGORY = "{CATEGORY_ID}"; 

    public static void RegisterAddin(bool is64Bit) 
    { 
     // Get path of dll: 
     var apPpath = System.Reflection.Assembly.GetExecutingAssembly().Location; 
     apPpath = Path.GetDirectoryName(apPpath); 
     var path = ASSEMBLY_DLL; 
     var dllPath = Path.Combine(apPpath, path); 

     // Com registration 
     RegistryKey rkey; 
     if (is64Bit) 
      rkey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64) 
       .OpenSubKey("Software").OpenSubKey("Classes", true); 
     else 
      rkey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32) 
       .OpenSubKey("Software").OpenSubKey("Classes", true); 

     var comAssemblyNameKey = rkey.CreateSubKey(ASSEMBLY_NAME); //HKCU/Software/Classes/Outlook.Addin 
     comAssemblyNameKey.SetValue("", ASSEMBLY_NAME); // default value 
     var clsidAssemblyNameComKey = comAssemblyNameKey.CreateSubKey("CLSID"); //HKCU/Software/Classes/Outlook.Addin/{CLSID} 
     clsidAssemblyNameComKey.SetValue("", CLSID); // default value 
     RegistryKey clsidComKey; 
     if (is64Bit) 
      clsidComKey = rkey.CreateSubKey("CLSID").CreateSubKey(CLSID); //HKCU\Software\Classes\CLSID\{CLSID} 
     else 
      clsidComKey = rkey.CreateSubKey("Wow6432Node").CreateSubKey("CLSID").CreateSubKey(CLSID); //HKCU\Software\Classes\CLSID\{CLSID} 
     clsidComKey.SetValue("", ASSEMBLY_NAME); // default value 
     var inProcServerKey = clsidComKey.CreateSubKey("InprocServer32"); //HKCU\Software\Classes\CLSID\{CLSID}\InProcServer32 
     inProcServerKey.SetValue("", "mscoree.dll"); 
     inProcServerKey.SetValue("ThreadingModel", "Both"); 
     inProcServerKey.SetValue("Class", "Outlook.Addin.Addin"); 
     inProcServerKey.SetValue("Assembly", $"Outlook.Addin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); 
     inProcServerKey.SetValue("RuntimeVersion", "v4.0.30319"); 
     inProcServerKey.SetValue("CodeBase", dllPath); 

     var versionKey = inProcServerKey.CreateSubKey(VERSION); //HKCU\Software\Classes\CLSID\{CLSID}\InProcServer32\1.0.0.0 
     versionKey.SetValue("Class", "Outlook.Addin.Addin"); 
     versionKey.SetValue("Assembly", $"Outlook.Addin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"); 
     versionKey.SetValue("RuntimeVersion", "v4.0.30319"); 
     versionKey.SetValue("CodeBase", dllPath); 

     var progIdKey = clsidComKey.CreateSubKey("ProgId"); //HKCU\Software\Classes\CLSID\{CLSID}\ ProgId 
     progIdKey.SetValue("", ASSEMBLY_NAME); 

     var implementedCategoryKey = clsidComKey.CreateSubKey("ImplementedCategories"); //HKCU\Software\Classes\CLSID\{CLSID}\ImplementedCategories 
     implementedCategoryKey.CreateSubKey(IMPLEMENTED_CATEGORY); 

     //AddIn registration 
     //HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Outlook\Addins\Outlook.Addin 
     var okey = Registry.CurrentUser.OpenSubKey("SOFTWARE") 
             .OpenSubKey("Microsoft") 
             .OpenSubKey("Office") 
             .OpenSubKey("Outlook") 
             .OpenSubKey("Addins", true); 
     var addinKey = okey.CreateSubKey(ASSEMBLY_NAME); 
     addinKey.SetValue("FileName", dllPath); 
     addinKey.SetValue("FriendlyName", "My addin"); 
     addinKey.SetValue("Description", "some addin description"); 
     addinKey.SetValue("LoadBehavior", 3, RegistryValueKind.DWord); 
    } 
} 
+0

ありがとうございます。これを試してみましょう! – NASHA

関連する問題