WiX MSI 在不启动的情况下安装 Windows 服务

标签 wix windows-services windows-installer

我正在尝试为我的 Windows 服务创建一个 WiX MSI 安装程序,它将安装该服务,但不启动它。我似乎无法找到任何解释如何执行此操作或是否可能的地方。

我试图删除用于启动服务的 ServiceControl 以及切换 ServiceInstall 上的 Start 属性,但没有任何运气。必须有可能做到这一点,对吧?我只希望 MSI 文件安装该服务,并让用户在需要时启动它。

<Component Id="ServiceInstaller" Guid="9e578e3d-0339-425c-8633-f54ffaaa4921">

    <ServiceInstall Id="ReportingServiceInstaller"
                    Type="ownProcess"
                    Vital="yes"
                    Name="WindowsService.exe"
                    DisplayName="WindowsService"
                    Description="Wickedly awesome and amazing service."
                    ErrorControl="ignore"
                    Account="NT AUTHORITY\LocalService"
                    Start="auto"
                    Interactive="no" />

    <ServiceControl Id="ServiceControl_Stop"
                    Name="WindowsService.exe"
                    Stop="both"
                    Remove="uninstall"
                    Wait="no" />

</Component>

最佳答案

不要使用 ServiceControl 元素,因为它将启动和停止服务。通过调用它,您是在要求安装程序对服务执行某些操作。您只需要调用 ServiceInstall 即可创建服务。正如 Stefan Wanitzek 建议的那样,您应该在 ServiceInstall 的 Start 属性中使用 demand。这是为了使您的服务在用户重新启动计算机时不会开始运行。如果您的安装程序也安装 .exe,请使用安装服务添加该文件。我建议使用从您的代码中获取的以下内容:

<Component Id="ServiceInstaller" Guid="3e412e3d-0339-325c-8633-f54ffaaa4921">
        <File Id="WindowsService.exe" 
         Name="WindowsService.exe" 
         KeyPath="yes"
         Source="Path to the EXE"/>
        <ServiceInstall Id="ReportingServiceInstaller"
                Type="ownProcess"
                Vital="yes"
                Name="WindowsService"                    
                DisplayName="WindowsService"
                Description="Wickedly awesome and amazing service."
                ErrorControl="ignore"
                Account="NT AUTHORITY\LocalService"
                Start="demand"
                Interactive="no" />
</Component>

关于WiX MSI 在不启动的情况下安装 Windows 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34046837/

相关文章:

c# - 如何从 wix 安装具有 .NET Core 运行时先决条件的网络核心应用程序

visual-studio-2010 - WiX Burn Bootstrapper 的替代品? (可以使用 InstallShield LE Bootstrap 吗?)

c# - Windows服务中未处理的异常

c# - 为什么 VS2010 "Lose"我的引用构建?

windows-installer - 尽管产品代码不同,MSIEXEC 仍无法安装产品 "a newer version of this product is already installed"

c# - .NET 4.0 自定义操作失败

WiX/MSI : How to update an registered shell extension on Windows XP

user-interface - WiX 内置的 WixUI 对话框集的水平线有点太短(包括图片)

.net - Windows 无法在 Win Server 2008 R2 SP1 上启动服务(错误 1053)

installation - 使用 Wix 安装 32 位和 64 位驱动程序?