4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WiX Toolset v4 GUIほぼ無しインストーラ編

Last updated at Posted at 2023-08-22

ユーザに選択肢を与えないタイプのインストーラ。
必要ない処理はタグごと消せば良い。ついでにFeatureからも消す。

Launchを使用するときは以下に注意
  1. wix extension addが事前に必要になる
  2. 拡張はエンコードの指定をしてあげる必要があるため、build時に-culture ja-JPが必要になる

インストーラ作成のコマンド

通常

wix build hoge.wxs

Launch使用時

wix extension add -g WixToolset.Util.wixext
wix build hoge.wxs -ext WixToolset.Util.wixext -culture ja-JP

hoge.wxsの中身

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Package
        Name="(アプリ名)"
        UpgradeCode="(自分で用意したGUID①)"
        Language="1041"
        Manufacturer="(会社名)"
        Version="1.0.0"
        Scope = "perMachine"    
        ProductCode="(自分で用意したGUID②)">
        <!-- Name、Manufacturerは漢字使用OK
             日本語は1041
             perMachineにするとStartupFolderの参照先が`C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup`になる。perUserにすると`C:\Users\(ユーザ名)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup`になる。
          -->

        <SummaryInformation Keywords="Installer" />

        <!-- ファイルを1つにまとめ、配布しやすい hoge.msi を作るために必要なおまじない。 -->
        <Media Id="1" Cabinet="app.cab" EmbedCab="yes" />   

        <!-- WiXの本体(?)とも言うべきところ。
             インストールするコンポーネント(StandardDirectoryの奥深くにあるComponentのId)をここで指定。
          -->
        <Feature Id="Complete" Level="1">
            <ComponentRef Id="SoftDir" />
            <ComponentRef Id="SoftDirDesktop" />
            <ComponentRef Id="SoftDirProgramMenu" />
            <ComponentRef Id="SoftDirStartup" />
        </Feature>

        <!-- アイコンは事前にIconタグを書き、Idを作っておく必要がある。
             相対参照は hoge.wxsがあるディレクトリからの相対参照(正確にはCWD)
          -->
        <Icon Id="appicon.ico" SourceFile="(自分で用意したアイコンへの相対参照)" />

        <!-- インストールしたいアプリ本体をProgramFilesにコピーする記述。
             ScopeにperMachineを指定した場合、インストール先として C:\Program Files (x86)\(会社英名)\(アプリ英名) が作成される。
             ProgramFilesFolderは事前定義されているフォルダ。他にもProgramFiles64Folderが使用可能。
             Directoryタグでネストしていけば奥深くまでディレクトリを構築可能。
             相対参照は hoge.wxsがあるディレクトリからの相対参照(正確にはCWD)
          -->
        <StandardDirectory Id="ProgramFilesFolder">
            <Directory Id="ManufactureDir" Name="(会社英名)">
                <Directory Id="SoftDir" Name="(アプリ英名)">

                    <Component Id="SoftDir" Guid="(自分で用意したGUID-当コンポーネント用①)">
                        <File Id="ExeFile" Source="(自分で用意したEXEファイルへの相対参照)" Checksum="yes" />
                        <File Id="IcoFile" Source="appicon.ico" Checksum="yes" />
                        <RemoveFolder Id="SoftDir" On="uninstall" />
                    </Component>

                </Directory>
            </Directory>
        </StandardDirectory>

        <!-- ユーザのデスクトップにショートカットを作成する記述。
             DesktopFolderは事前定義されているフォルダ。
             WorkingDirectoryにはDirectoryのIdを入れること。
             Targetは [] で括ればDirectoryのIdも使用可能。絶対参照にすること。
          -->
        <StandardDirectory Id="DesktopFolder">
            <Component Id="SoftDirDesktop" Guid="(自分で用意したGUID-当コンポーネント用②)">
            <Shortcut Id="ExeFileDesk" Directory="DesktopFolder" Name="(ショートカットファイル名)" WorkingDirectory="SoftDir" Target="[SoftDir]\\(自分で用意したEXEファイル名)" Icon="appicon.ico" />
                <RemoveFolder Id="SoftDirDesktop" On="uninstall" />
            </Component>
        </StandardDirectory>

        <!-- スタートのすべてのアプリにショートカットを作成する記述。
             ProgramMenuFolderは事前定義されているフォルダ。
          -->
        <StandardDirectory Id="ProgramMenuFolder">
            <Component Id="SoftDirProgramMenu" Guid="(自分で用意したGUID-当コンポーネント用③)">
                <Shortcut Id="ExeFileMenu" Directory="ProgramMenuFolder" Name="(ショートカットファイル名)" WorkingDirectory="SoftDir" Target="[SoftDir]\\(自分で用意したEXEファイル名)" Icon="appicon.ico" />
                <RemoveFolder Id="SoftDirProgramMenu" On="uninstall" />
            </Component>
        </StandardDirectory>

        <!-- スタートアップにショートカットを作成する記述。
             StartupFolderは事前定義されているフォルダ。Scope/@Scopeの値によって参照先が変動する。
          -->
        <StandardDirectory Id="StartupFolder">
            <Component Id="SoftDirStartup" Guid="(自分で用意したGUID-当コンポーネント用④)">
                <Shortcut Id="ExeFileStartup" Directory="StartupFolder" Name="(ショートカットファイル名)" WorkingDirectory="SoftDir" Target="[SoftDir]\\(自分で用意したEXEファイル名)" Icon="appicon.ico" />
                <RemoveFolder Id="SoftDirStartup" On="uninstall" />
            </Component>
        </StandardDirectory>

        <!-- インストール後に再起動を促す記述 -->
        <InstallExecuteSequence>
            <ScheduleReboot After="InstallFinalize" />
        </InstallExecuteSequence>

        <!-- 通常権限で起動する場合。
             ※用途としてはreadmeとかサイトを開くときに使用する。
             ※Value="https://www.google.com/" とするとサイトが開く
             ※インストール時の権限(管理者権限)のまま起動させたい場合は DllEntry="WixShellExec" に変更する。
             ※アンインストール時にも起動してしまうため要調査
          -->
        <SetProperty Id="WixShellExec" Value="notepad.exe" Before="LaunchCustomAction" Sequence="execute" />
        <CustomAction Id="LaunchCustomAction" BinaryRef="Wix4UtilCA_$(sys.BUILDARCHSHORT)" DllEntry="WixUnelevatedShellExec" Execute="immediate" Return="check"/>
        <InstallExecuteSequence>
            <Custom Action="LaunchCustomAction" Before="AppSearch" />
        </InstallExecuteSequence>

    </Package>
</Wix>
4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?