0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【インストーラー編】VSCodeでOutlookのCOMアドインをつくる

Posted at

前回つくったOutlookのCOMアドインにて、インストーラーをInno Setupでつくります。

前回の記事では、Visual Studio Codeと.NET Frameworkを使ってOutlookのCOMアドインをつくりました。
今回はその続きとして、作成したCOMアドインをユーザーが簡単に導入できるよう、インストーラーを作成します。
使用するツールはInno Setupです。

インストーラー(Inno Setup)

  • Inno Setupのライセンスはバージョン6.5.0より大きく変わっています
  • 商用利用の場合は公式サイトでライセンス情報を確認必要です

処理内容

  • Guidはpowershellで生成してAppId={{GUID}}へ入れます
    • ClassLib.csで入れたGUIdとは別にします
  • MyAppPathはdllが保存されているパスにします
  • インストーラーのverはdllのverを取得して合わせるようにしています
    • MyAppVersion GetVersionNumbersString(MyAppPath + MyAppExeName)
    • dllのバージョンが、4つのドット区切りの数値(1.1.2.5)でないと上手く取得できない可能性があります

インストーラーでは以下の処理を行います:

  • DLLの配置
  • COMアドインとして登録(RegAsm.exeを使用)
    • .NETで作成したdllをCOMとして使えるように登録するため、RegAsm.exeでの処理が必要です
    • RegAsm.exeは.NET Framework付属のツールで、windows11では通常.NET Framework4.8がインストールされているので存在するはずです
    • 保存フォルダC:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe
    • RegAsm.exeをインストーラーに含めて再配布するとライセンス違反になるので注意
  • Outlookのレジストリ登録
    • OutlookにCOMアドインとして読み込ませるためにレジストリ登録の部分が必要です
    • subkey:ClassLibのProgIdと合わせる必要があります
      Subkey: "Software\Microsoft\Office\Outlook\Addins\OutlookCOMAddin.Connect"
    • Description:説明文を入れます
    • FriendlyName:COMアドインで表示される名前です
    • LoadBehavior:起動時のCOMアドイン読み込み状態
      3でスタート時に読み込み
  • Outlookの再起動
  • アンインストール
    • RegAsm.exeでCOM登録を削除
    • RegAsm.exeを使用して追加した内容はRegAsm.exeを使ってアンインストールする必要があります
inno setupの全体

OutlookCOMAddin.iss
⇒OutlookCOMAddinSetup.exeが出力されます

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "OutlookCOMAddin"
; #define MyAppVersion "0.0.0.0"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "OutlookCOMAddin.dll"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt
; パスは""ではなく''で囲む
#define MyAppPath 'C:\Users\path\publish\'
#define MyAppVersion GetVersionNumbersString(MyAppPath + MyAppExeName)

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{GUID}}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
; AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
; プログラムフォルダ
; DefaultDirName={autopf}\{#MyAppName}
; マイドキュメント
DefaultDirName={userdocs}\{#MyAppName}
UninstallDisplayIcon={app}\{#MyAppExeName}
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only).
PrivilegesRequired=none
OutputDir=.
OutputBaseFilename=OutlookCOMAddin
; SetupIconFile=
SolidCompression=yes
VersionInfoVersion={#MyAppVersion}
WizardStyle=modern
; 始めの画面にメッセージをだす
; InfoBeforeFile=InfoBefore.txt


[Languages]
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"

[Tasks]
; Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}";
; Name: "startupicon"; Description: "スタートアップにショートカットを作成";

[Files]
; dllなど
Source: "{#MyAppPath}*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKCU; Subkey: "Software\Microsoft\Office\Outlook\Addins\OutlookCOMAddin.Connect"; Flags: uninsdeletekey
Root: HKCU; Subkey: "Software\Microsoft\Office\Outlook\Addins\OutlookCOMAddin.Connect"; ValueType: string; ValueName: "Description"; ValueData: "テストのCOMアドインです"
Root: HKCU; Subkey: "Software\Microsoft\Office\Outlook\Addins\OutlookCOMAddin.Connect"; ValueType: string; ValueName: "FriendlyName"; ValueData: "OutlookCOMAddin"
Root: HKCU; Subkey: "Software\Microsoft\Office\Outlook\Addins\OutlookCOMAddin.Connect"; ValueType: dword; ValueName: "LoadBehavior"; ValueData: 3

[Icons]
; Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
; Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
; Name: "{userstartup}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: startupicon

[Run]
; COMの登録
Filename: "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe"; Parameters: """{app}\OutlookCOMAddin.dll"" /codebase"; Flags: runhidden
; Outlook を終了(強制終了)
Filename: "taskkill.exe"; Parameters: "/IM outlook.exe /F"; Flags: runhidden
; Outlook を再起動
Filename: "{autopf}\Microsoft Office\root\Office16\OUTLOOK.EXE"; Flags: shellexec postinstall
; 既定のブラウザでreadmeを開く
Filename: "{app}\Package\readme.html"; Flags: shellexec postinstall

[UninstallRun]
; Outlook を終了(強制終了)
Filename: "taskkill.exe"; Parameters: "/IM outlook.exe /F"; Flags: runhidden; RunOnceId: "KillOutlook"
; COMの登録解除
Filename: "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe"; Parameters: """{app}\OutlookCOMAddin.dll"" /u"; Flags: runhidden; RunOnceId: "Unreg_OutlookCOMAddin"
; Outlook を再起動
Filename: "{autopf}\Microsoft Office\root\Office16\OUTLOOK.EXE"; Flags: shellexec; RunOnceId: "RestartOutlook"

インストール

  • OutlookCOMAddinSetup.exeを実行してOutlookへCOMアドインが追加されました!

image.png

アンインストール

  • windows設定のアプリ一覧からOutlookCOMAddinをアンインストールすればレジストリ含めすべて削除されます

リボンのカスタマイズ

次回はリボンのカスタマイズを行う予定です

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?