WIX-Installer ServiceControl "sufficient privileges" 错误

WIX-Installer ServiceControl "sufficient privileges" error

Visual Studio 2015 年款 Wix v3.10.0.1726

我正在为 windows 服务创建安装程序。我已经使用 InstallUtil 测试了该服务,它运行良好。不幸的是,我在使用 Wix 时遇到了一些麻烦,这是确切的错误 -

"Service 'Service Name' failed to start. Verify that you have sufficient privileges to start system services."

现在我已将问题缩小到通过 WIX 启动服务。如果我放弃 ServiceControl 标签并使用 services.msc 手动启动它,它工作正常。

从其他问题来看,这个错误似乎是一个一般的 catch 错误,在各种情况下都会发生。最流行的是,如果您的服务依赖于安装到 GAC(全局程序集缓存)的程序集,我也不清楚。我从不隐式地将任何内容保存到 GAC,我的服务只是调用我编写的包含在项目中的 .cs 文件。

如有任何帮助,我们将不胜感激!

<Component Id="ProductComponent7">
    <File Source="$(var.ServiceName.TargetPath)" KeyPath="yes" Vital="yes"/>
    <ServiceInstall Id="ServiceName.exe"
                      Account="LocalSystem"
                      Arguments="-start"
                      Type="ownProcess" 
                      Name="ServiceName.exe" 
                      DisplayName="ServiceName Service" 
                      Description="sdfg" 
                      Start="auto" 
                      Interactive="yes"
                      ErrorControl="critical" />
  <ServiceControl Id="ServiceControl" Name="ServiceName" Start="install"  />
        </Component>

我也在 ServiceControl 中尝试了各种不同的属性,我最近将它们全部删除以尽量使其尽可能简单。

如果有人有任何见解那就太好了!

正确,这是一个一般性错误。您必须分析您的服务才能了解它无法启动的原因。

GAC 只是一种情况。在那种情况下,这是因为 MSI 直到 StartServices 之后才将程序集发布到 GAC。导致缺少依赖项和错误的经典竞争条件。

在消息框仍然存在的情况下,运行 来自控制台的 EXE。你有错误吗?您的应用程序日志中是否有任何错误?找出服务无法修复的原因,解决它并重试。

问题似乎是您安装了一个名为 ServiceName.exe 的服务,而您正在尝试启动一个名为 ServiceName 的服务。名称值需要匹配。

对我来说,错误是由于 ServiceInstall 标签中的 Name 属性与 ServiceBase child class InitializeComponent() 中指定的名称值不同方法。

代码更新:

在Product.wxs中:

<ServiceInstall Id="ServiceInstaller"
          Type="ownProcess"
          Name="MyWindowsService"
          DisplayName="$(var.ServiceDisplayName)"
          Description="$(var.ServiceDiscription)"
          Start="auto"
          Account="LocalSystem"
          ErrorControl="normal" />

在 ServiceBase 子项中 class:

private void InitializeComponent()
{
    components = new System.ComponentModel.Container();
    this.ServiceName = "MyWindowsService";
}