【问题标题】:WiX Windows Service won't start when Account is not LocalSystem当帐户不是 LocalSystem 时,WiX Windows 服务不会启动
【发布时间】:2020-12-11 22:15:48
【问题描述】:

将设置应用程序转换为 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>

提前致谢,

肯特

【问题讨论】:

    标签: windows-services wix3.11


    【解决方案1】:

    经过大量的实验,我想出了答案。它实际上似乎是 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>
    

    祝你一切顺利, 肯特

    【讨论】:

    • 这是最有可能的答案。有关实际安装权限、作为服务登录和缺少依赖项的其他答案可能会有所帮助,但它们可能只是少数可以解决此问题的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    相关资源
    最近更新 更多