WiX Windows 当帐户不是 LocalSystem 时服务不会启动

WiX Windows Service won't start when Account is not LocalSystem

将设置应用程序转换为 WiX,对于用 C# 编写的 Windows 服务应用程序,我遇到以下现象:

1.) 配置具有 ServiceInstall 部分的主要 EXE 组件分配 Account="LocalSystem" 应用程序将成功安装但不会 运行 (-start)。它没有对其将连接到的数据库的身份验证,所以不足为奇。

2.) 使用第一项中的安装,我将 ValidAccount 和 ValidPassword 应用到服务属性的“登录”选项卡。服务启动,并且 运行 像预期的那样手动完成时成功。

3.) 回到 Wix 项目,我将上述 ServiceInstall 部分更改为具有与步骤 2 中使用的相同的 Account="ValidAccount" Password="ValidPassword" 并重建 MSI 文件。在 ServiceInstall 之后安装失败并显示以下日志消息:

InstallServices: Service: 
    Error 1923. Service 'My Service' (MyService.exe) could not be installed. Verify that you have sufficient privileges to install system services.
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 20432 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 13032 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 10548 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 19688 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 6588 could not be cancelled. Error: 1168
    MSI (s) (B4:30) [12:54:38:616]: I/O on thread 10132 could not be cancelled. Error: 1168
    MSI (s) (B4:94) [12:54:38:616]: Product: MyService -- Error 1923. Service 'My Service' (MyService.exe) could not be installed. Verify that you have sufficient privileges to install system services.

4.) 我已确认 ValidAccount 是本地管理员组的成员。

5.) 我已确认将 ValidAccount 添加到“作为服务登录”策略中。

6.) 我在服务中没有 GAC 依赖项(有人发现 GAC 依赖项是在最后添加的,可能会中断安装。)

我错过了什么? ...即使是使用 LocalSystem 的无所事事的服务也可以。但是,如果我如下设置帐号和密码,它不会安装。

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="TestService.exe" Guid="196BB5E5-F157-4CA2-B740-0A68E1539B7C">
        <File 
          Id="TestService.exe" 
          Source="$(var.TestService.TargetPath)" 
          KeyPath="yes" />
    
        <ServiceInstall 
          Id="TestService.exe" 
          Name="TestService.exe" 
          DisplayName="Test Service"
          Description="This is a test service to test installation with WiX."
          Account="myDomain\myAccount" <!-- using myAccount without the domain yields same failure -->
          Password="myAccountPassword"
          Arguments="-start" 
          Start="auto" 
          Interactive="yes" 
          Type="ownProcess" 
          Vital="yes" 
          ErrorControl="ignore" />

        <ServiceControl 
          Id="TestService.exe" 
          Name="TestService.exe" 
          Stop="both" 
          Start="install" 
          Remove="uninstall" 
          Wait="no" />
      </Component>
    </ComponentGroup>
  </Fragment>

提前致谢,

肯特

经过一系列实验,我得出了答案。它实际上似乎是 WiX 工具集(版本 3.11.2)中的一个错误,但我不确定是否有人故意这样做。当您向 ServiceInstall 添加密码时,Interactive 属性 必须设置为“no”。

由于某些未知原因,如果您将其设置为“是”,则只会安装不需要密码的帐户。

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="TestService.exe" Guid="196BB5E5-F157-4CA2-B740-0A68E1539B7C">
        <File 
          Id="TestService.exe" 
          Source="$(var.TestService.TargetPath)" 
          KeyPath="yes" />
    
        <ServiceInstall 
          Id="TestService.exe" 
          Name="TestService.exe" 
          DisplayName="Test Service"
          Description="This is a test service to test installation with WiX."
          Account="myDomain\myAccount" <!-- using myAccount without the domain yields same failure -->
          Password="myAccountPassword"
          Arguments="-start" 
          Start="auto" 
          Interactive="no" <!-- MUST BE NO WHEN PASSWORD IS USED -->
          Type="ownProcess" 
          Vital="yes" 
          ErrorControl="ignore" />

        <ServiceControl 
          Id="TestService.exe" 
          Name="TestService.exe" 
          Stop="both" 
          Start="install" 
          Remove="uninstall" 
          Wait="no" />
      </Component>
    </ComponentGroup>
  </Fragment>

祝你一切顺利, 肯特