Wix 安装程序无法启动服务

Wix Installer unable to start service

我创建了一个 Wix 安装程序来安装服务。这是我的 product.wxs :

<?xml version="1.0" encoding="UTF-8"?>
<?define compagny = "MyCompagny"?>
<?define product = "My Service"?>
<?define service = "MyService"?>
<?define version = "!(bind.FileVersion.MyService.exe)"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" 
           Name="$(var.product)"
           Language="1033"
           Version="$(var.version)"
           Manufacturer="$(var.compagny)" 
           UpgradeCode="XXXXXXX">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated"/>
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <Media Id="1" Cabinet="MyService.cab" EmbedCab="yes" />

        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
        <Directory Id="CPGNYFOLDER" Name="$(var.compagny)">
          <Directory Id="INSTALLFOLDER" Name="$(var.product)" >
            <Directory Id="Service_tessdata" Name="tessdata"/>
            <Directory Id="Service_x64" Name="x64"/>
            <Directory Id="Service_x86" Name="x86"/>            
          </Directory>
        </Directory>
            </Directory>
        </Directory>

    <ComponentGroup Id="InstallComponents">
      <Component Id="InstallService" Guid="XXXXXXX" Directory="INSTALLFOLDER">
        <File Id="MyService.exe.config"
              Name="$(var.service).exe.config"
              Source="$(var.MyService.TargetDir)$(var.service).exe.config"
              Vital="yes"/>
        <File Id="MyService.exe"
              Name="$(var.service).exe"
              Source="$(var.MyService.TargetDir)$(var.service).exe"
              Vital="yes"/>
        <!-- Install all dll -->

        <RemoveFile Id="ALLFILES" Name="*.*" On="both" />
        <ServiceInstall Id="ServiceInstaller"
                        Type="ownProcess"
                        Vital="yes"
                        Name="$(var.service)"
                        DisplayName="$(var.product)"
                        Description=""
                        Start="auto"
                        Account="LocalSystem"
                        ErrorControl="normal" />
        <ServiceControl Id="Service_Start" Name="MyService" Start="install" Wait="no" />
        <ServiceControl Id="Service_Stop" Name="MyService"  Stop="both" Remove="uninstall" Wait="yes" />
      </Component>

        <!-- Install all directories -->
    </ComponentGroup>

    <!-- Tell WiX to install the files -->
    <Feature Id="ProductFeature" Title="$(var.product)" Level="1">
      <ComponentGroupRef Id="InstallComponents" />
    </Feature>
    </Product>
</Wix>

当我尝试安装我的服务时,出现错误:

Service 'My Service' (MyService) failed to start. Verify that you have sufficient privileges to start system services

我看到这个错误是一个一般错误。所以我忽略了它。在我的 INSTALLFOLDER 中,我有所有文件。然后我开始 services.msc 并尝试启动我的服务。错误是:

Cannot start the service on local computer. Error 193:0xc1

我尝试提供更多详细信息,但找不到问题所在。我该如何解决这个问题?

终于找到问题了

在我的服务属性中,我看到服务路径指向 MyService.exe.config

我通过在 .exe 上添加 KeyPath 解决了这个问题:

<File Id="MyService.exe"
      Name="$(var.service).exe"
      Source="$(var.MyService.TargetDir)$(var.service).exe"
      Vital="yes"
      KeyPath="yes"/>