You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MSI安装报错:‘验证您拥有启动系统服务的足够权限’求助

.NET 服务

我一直搞不懂为什么安装会出现这个错误。我创建了一个基础的.NET 4.8 Windows服务,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Test
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
#if DEBUG
            Service1 test = new Service1();
            test.OnDebug();
            Thread.Sleep(Timeout.Infinite);
#else

            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            ServiceBase.Run(ServicesToRun);
#endif

        }
    }
}
using Serilog;
using System;
using System.ServiceProcess;

namespace Test
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();

            Log.Logger = new LoggerConfiguration()
            .WriteTo.File("<Log path>", rollingInterval: RollingInterval.Day)
            .MinimumLevel.Information()
            .CreateLogger();
        }

        public void OnDebug()
        {
            try
            {
                OnStart(null);
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                Log.Information("Service Started");
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }
        }

        protected override void OnStop()
        {
            try
            {
                Log.Information("Service Stopped");
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }
        }
    }
}

WIX 项目

我创建了一个基础WIX项目,按常规方式添加该服务作为引用。

以下是Package.wxs文件内容:

<?xml version="1.0" encoding="UTF-8"?>

<?define Name = "Test" ?>
<?define Manufacturer = "Test" ?>
<?define Version = "1.0.0.0" ?>
<?define UpgradeCode = "1D38B1B5-0BD5-419B-9BAC-9F571D2F8048" ?>

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Package
        Name="$(Name)"
        Manufacturer="$(Manufacturer)"
        Version="$(Version)"
        UpgradeCode="$(var.UpgradeCode)"
        Compressed="yes">

        <MajorUpgrade DowngradeErrorMessage="A later version is already installed." />

        <Media Cabinet="cab1.cab" Id="1" EmbedCab="yes"></Media>

        <Feature Id="Service" Title="Test Service" Level="1">
            <ComponentRef Id="ServiceExecutable" />
        </Feature>

    </Package>
</Wix>

我的Components.wxs文件:

<?xml version="1.0" encoding="UTF-8"?>

<?define Name = "Test Service" ?>

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Fragment>
        <ComponentGroup Id="Components" Directory="INSTALLFOLDER">

            <Component Id="ServiceExecutable" Bitness="always64">

                <File Id="Test.exe"
                      Source="$(var.Test.TargetDir)\\Test.exe"
                      KeyPath="true" />

                <RemoveFile Id="ALLFILES" Name="*.*" On="both" />

                <ServiceInstall Id="ServiceInstaller"
                                Name="Service1"
                                Type="ownProcess"
                                DisplayName="$(Name)"
                                Description="This is a test service"
                                Start="disabled"
                                ErrorControl="normal" />

                <ServiceControl Id="StartService"
                                Name="Service1"
                                Start="install"
                                Stop="both"
                                Remove="uninstall"
                                Wait="true" />
            </Component>

        </ComponentGroup>
    </Fragment>
</Wix>

我的Folders.wxs文件:

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
  <Fragment>
    <StandardDirectory Id="ProgramFiles6432Folder">
      <Directory Id="INSTALLFOLDER" Name="!(bind.Property.Manufacturer) !(bind.Property.ProductName)" />
    </StandardDirectory>
  </Fragment>
</Wix>

移除ServiceControl组件时,服务能正常安装运行,但安装程序就失去了应有的功能。

仅添加ServiceControl后,会出现错误:"Verify that you have sufficient privileges to start system services"。我查看日志文件未发现异常,以管理员权限通过PowerShell运行MSI仍遇到该问题。

我尝试为ServiceInstall添加Account属性,没有效果;还按照教程将账户添加到服务组策略中,同样无法解决问题。

现在实在没辙了,求各位帮忙。

内容的提问来源于stack exchange,提问作者Ruben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 16:14:53