无法在WiX安装程序中安装和启动Windows服务

zho*_*ang 15 windows-services wix wix3.8

我正在创建一个MSI包,用于使用WiX v3.8安装和启动Windows服务.代码如下:

<Component Id="INSTALLAPSSERVICE" Guid="991D5F82-0E77-4FE3-B1D8-4C941B84C7CD" Win64="yes">
   <File Id="ApsService.exe"
         Name="ApsService.exe"
         Source="Resource\ApsService.exe"
         KeyPath="yes"
         Vital="yes"
         DiskId="1"></File>
   <ServiceInstall Id="ApsServiceInstaller"
                   Name="ApsService"
                   DisplayName="ApsService"
                   Type="ownProcess"
                   Start="auto"
                   ErrorControl="normal"
                   Description="A monitor service for windows application."
                   Account="[SERVICEACCOUNT]"
                   Password="[SERVICEPASSWORD]"
                   Vital="yes"
                   Interactive="no"></ServiceInstall>
    <ServiceControl Id="StartService"
                    Start="install"
                    Stop="both"
                    Remove="uninstall"
                    Name="ApsService"
                    Wait="yes"/>
</Component>
Run Code Online (Sandbox Code Playgroud)

但安装失败,日志中出现以下错误:

Executing op: ServiceControl(,Name=ApsService,Action=1,Wait=1,)
StartServices: Service: ApsService
Error 1920. Service 'ApsService' (ApsService) failed to start. Verify that you have      sufficient privileges to start system services.
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3676 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 1888 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 1764 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3504 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 2100 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 2752 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3672 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 3876 could not be cancelled. Error: 1168
MSI (s) (F0:D0) [15:57:28:630]: I/O on thread 1400 could not be cancelled. Error: 1168
MSI (s) (F0:C0) [15:57:28:630]: Product: WinApsSetup64 -- Error 1920. Service 'ApsService' (ApsService) failed to start. Verify that you have sufficient privileges to start system services.
Run Code Online (Sandbox Code Playgroud)

我该如何修复错误?

Rob*_*ing 13

您收到的错误消息是Windows Installer在安装期间无法启动服务时发送的通用消息.问题几乎总是服务缺少依赖关系,或者在启动时没有完全配置.要调试root问题,请尝试:

  1. 安装MSI包.
  2. 出现错误对话框时指示无法启动服务*请勿关闭对话框.
  3. 启动services.msc或从命令行使用sc.exe尝试启动服务.Windows Installer应该已经配置了足够的服务,以便能够更深入地调试它失败的原因.
  4. 如有必要,可直接调试服务可执行文件以查看无法启动的原因.

如果这是用托管代码编写服务,确保它依赖于文件被放置在GAC.在安装过程中非常非常晚,文件不在GAC中.如果必须使用GAC中的文件,则无法使用内置ServiceControl元素,并且必须编写自定义操作才能运行InstallFinalize.请注意,在InstallFinalize不提升自定义操作后,您的服务必须支持由非提升用户启动.我再次建议不要依赖GAC.

祝你好运调试你的服务!


Chr*_*uer 6

在OP的示例中对ServiceInstall帐户进行了模糊处理,但如果忘记完全限定帐户,则会发生此错误,如下所示:

<ServiceInstall ... Account="NT AUTHORITY\LocalService" />

如果您只指定用户名(没有NT Authority),您的安装程序将失败:

<ServiceInstall ... Account="LocalService" />