WiX ServiceInstall - 设置服务以当前 Windows 用户身份运行

标签 wix serviceinstall

我正在使用 WiX 安装 Windows 服务。如何使服务在运行安装程序的 Windows 用户的上下文中运行?

最佳答案

您需要拥有要作为其运行服务的用户的帐户名和密码。我能够通过向我的安装程序添加自定义 UI 来要求用户名和密码,然后使用 ServiceInsall 元素上的 Account 和 Password 属性提供的值来完成此操作。

请注意,用于运行服务的任何帐户都需要具有登录身份服务特权。默认情况下,这不会授予用户。我能够使用 UtilExtension 架构中的 User 元素将此权限添加到用户。仅当运行安装程序的用户是管理员时,才能向用户添加特权。

这是我使用的代码。 SERVICECREDENTIALS_USERLOGIN 和 SERVICECREDENTIALS_PASSWORD 是从自定义 UI 填充的属性。

<Component Id="ServiceEXE" Guid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">
  <File Id="ServiceEXE" Name="YourService.exe" DiskId="1"
        Source="path\to\YourService.exe" KeyPath="yes" />
  <util:User Id="UpdateUserLogonAsService" UpdateIfExists="yes" CreateUser="no" Name="[SERVICECREDENTIALS_USERLOGIN]"
             LogonAsService="yes" />
  <ServiceInstall Id="ServiceInstall" Type="ownProcess" Vital="yes" Name="YourService"
                  DisplayName="Your Service" Description="Your Service description"
                  Start="auto" Account="[SERVICECREDENTIALS_USERLOGIN]" Password="[SERVICECREDENTIALS_PASSWORD]"
                  ErrorControl="normal" Interactive="no" />
  <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="YourService" Wait="yes" />
</Component>

关于WiX ServiceInstall - 设置服务以当前 Windows 用户身份运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1487638/

相关文章:

wix - 使用 Wix 安装程序更改功能时更新属性值

Wix ExePackage 始终安装,无论 DetectCondition、InstallCondition、安装或卸载

c# - 安装程序 OnCommitted 问题

windows-services - WIX ServiceInstall - 将服务设置为在 NetworkService 帐户下运行

visual-studio-2012 - 使用wix在程序数据中添加文件

visual-studio - WiX "Undefined Preprocessor Variable"尽管 .wxi 文件中有变量

permissions - Wix:使用permissionEx 在安装文件夹中设置文件夹的权限

c# - 使用服务安装 msi,如果输入的凭据不正确,是否有办法强制安装程序重新提示用户

.net - WiX 安装程序中的参数化服务启动选项