【问题标题】:Wix Installer unable to start serviceWix 安装程序无法启动服务
【发布时间】:2018-08-07 09:52:48
【问题描述】:

我创建了一个 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>

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

服务“我的服务”(MyService) 无法启动。确认您 有足够的权限启动系统服务

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

无法在本地计算机上启动服务。错误 193:0xc1

我尝试了解更多细节,但找不到问题所在。我该如何解决这个问题?

【问题讨论】:

  • 您能否查看事件日志并发布与此事件相关的日志。
  • 另外试试这个命令修改服务启动权限并检查是否有效,"subinacl /SERVICE \\%hostname%\servicename /GRANT=S-1-5-11=F"在这里下载" microsoft.com/en-in/download/details.aspx?id=23510"

标签: c# service wix


【解决方案1】:

我终于找到了问题所在。

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

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

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

【讨论】:

  • 另外,您可以简单地交换两个文件元素的顺序,因为 WiX 会自动将第一个文件元素设置为组件的键路径。虽然我认为显式设置 keypath 更好,因为它会使源代码对未来的变化更加健壮(比如另一个开发人员在组件的开头插入一个文件)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多