如何在WIX工具包中获取应用程序文件夹以安装服务

时间:2019-02-25 11:49:44

标签: windows installation wix windows-installer

我正在尝试为第三方应用程序编写安装程序。 该服务应已安装并使用参数运行。参数之一是安装服务的主文件夹。

如何读取应用程序的安装文件夹,并将其作为参数传递给Wix Element:ServiceInstall。

                <ServiceInstall Id="SInstall"
                        Type="ownProcess"
                        Name="myservice"
                        DisplayName="MyService"
                        EraseDescription="no"
                        Start="demand"
                        ErrorControl="normal"
                        Arguments="-folder '[INSTALLDIR]\config.txt'>

但是[INSTALLDIR]为空; 我想应该通过使用SetProperty来完成它并阅读它,但是找不到任何引用该怎么做。

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFiles64Folder">
                <Directory Id="ManufacturerFolder" Name="OEM_XXX">
                    <Directory Id="INSTALLFOLDER" Name="Product  $(var.ProductVersion)">
                        <Directory Id="DirA" />
                        <Directory Id="DirB" Name="SubService">
                            <Directory Id="DirC" Name="ComponentA">
                                <Directory Id="ComponentB" Name="content" />
                            </Directory>
                        </Directory>
                    </Directory>
                </Directory>
            </Directory>
        </Directory>
    </Fragment>
    <Fragment>
        <DirectoryRef Id="DirB">
            <Component Id="Svc1" Guid="b033eb95-ce88-48ac-b40f-6913c5e4b978" Win64="yes">
                <File Source="$(var.SourceDir)\service.exe" />

                    <ServiceInstall Id="SInstall"
                        Type="ownProcess"
                        Name="myservice"
                        DisplayName="MyService"
                        EraseDescription="no"
                        Start="demand"
                        ErrorControl="normal"
                        Arguments="-folder '???????\config.txt'>

                     <ServiceConfig DelayedAutoStart="no" OnInstall="yes" OnReinstall ="yes" />

                </ServiceInstall>

                <ServiceControl Id="SControl"
                        Stop="both"
                        Remove="uninstall"
                        Name="myservice"
                        Wait="no" />                
            </Component>
        </DirectoryRef>
    </Fragment>

谢谢。

1 个答案:

答案 0 :(得分:1)

使用[{directoryId}作为参考;

在我的情况下是

 <ServiceInstall Id="SInstall"
                        Type="ownProcess"
                        Name="myservice"
                        DisplayName="MyService"
                        EraseDescription="no"
                        Start="demand"
                        ErrorControl="normal"
                        Arguments='-folder "[DirB]config.txt"'>

您可以在MSDN上找到的可用系统文件夹的完整列表:

https://docs.microsoft.com/en-us/windows/desktop/msi/property-reference#system-folder-properties

有时名称可能会使您感到困惑,但请阅读说明。 例如,如果您想定义%PROGRAMDATA%的路径,则应使用[CommonAppDataFolder]

P.S。内置变量以斜杠结尾

相关问题