Emotion Wave Tech Blog

福岡にあるエモーションウェーブ株式会社のエンジニアが書いています。

WixインストーラのCustomAction覚書

f:id:devew:20191224114505j:plain

ホリノウチです。

先日、Wixを使ってbat処理を行うインストーラを作ったので、その時のCustomActionの覚書です。 ちなみにココで言うWixコレの事ね。webサイト作成サービスではありません。

wixには既存のActionが存在し、その前後に自前のCustomActionを動かす事ができます。下記では「InstallFinalize」の前にCustomActionである「LaunchFile」を実行します。

<Property Id="SETUP">フルパス/SetUp.bat</Property>
<CustomAction Id="LaunchFile" Property="SETUP" ExeCommand="" Return="ignore" />
<InstallExecuteSequence>
    <Custom Action="LaunchFile" Before="InstallFinalize"/>
</InstallExecuteSequence>


この場合、アンインストール時にはCustomActionは実行しません。なぜならば、指定したファイルはInstallFinalizeのタイミングには既に削除されているからです(InstallInitializeなら削除前なので実行されます)。この対処はFileではなくBinaryを使用します。Binaryの場合batは使用できなかったはず。。。

<Binary Id="SETUP" SourceFile="相対パス\SETUP.dll" />
<CustomAction Id="LaunchFile" BinaryKey="SETUP" ExeCommand="" Return="ignore" />
<InstallExecuteSequence>
    <Custom Action="LaunchFile" Before="InstallFinalize"/>
</InstallExecuteSequence>


この状態だとインストール・アンインストールに実行されます。下記では「Not Installed」「Installed」の設定でインストール・アンインストール時のCustomActionをわけています。

<Property Id="SETUP">フルパス/SetUp.bat</Property>
<CustomAction Id="LaunchFile" Property="SETUP" ExeCommand="" Return="ignore" />
<Property Id="REMOVE">フルパス/Remove.bat</Property>
<CustomAction Id="RemoveFile" Property="REMOVE" ExeCommand="" Return="ignore" />
<InstallExecuteSequence>
    <!-- インストール時 -->
    <Custom Action="LaunchFile" Before="InstallInitialize">Not Installed</Custom>
    <!-- アンインストール時 -->
    <Custom Action="RemoveFile" Before="InstallInitialize">Installed</Custom>
</InstallExecuteSequence>


前後しますが、自作CustomActionにもさらに処理を紐付けできます。下記ではLaunchFileの前にBeforeFileを実行します。

<Property Id="SETUP">フルパス/SetUp.bat</Property>
<CustomAction Id="LaunchFile" Property="SETUP" ExeCommand="" Return="ignore" />
<Property Id="BEFORE">フルパス/Befor.bat</Property>
<CustomAction Id="BeforeFile" Property="BEFORE" ExeCommand="" Return="ignore" />
<Property Id="REMOVE">フルパス/Remove.bat</Property>
<CustomAction Id="RemoveFile" Property="REMOVE" ExeCommand="" Return="ignore" />

<InstallExecuteSequence>
    <!-- インストール時 -->
    <Custom Action="LaunchFile" Before="InstallInitialize">Not Installed</Custom>
    <!-- LaunchFile前 -->
    <Custom Action="BeforeFile" Before="LaunchFile"/>
    <!-- アンインストール時 -->
    <Custom Action="RemoveFile" Before="InstallInitialize">Installed</Custom>
</InstallExecuteSequence>


ちなみに、後に実行する場合はAfter属性を使用して下さい。 Return属性は、処理を同期・非同期で行ったり戻り値を判定したりできます。 もっと情報が必要な方はココを見てください、詳しく書いてあります。 気が向いたら、今度はUACについて書きます。 ほんと覚書なので間違いあったらご指摘ください。 ではではこの辺でおしまいにします。