WiX ServiceInstall - 设置服务以当前 Windows 用户身份运行 [英] WiX ServiceInstall - setting the service to run as the current windows user

查看:32
本文介绍了WiX ServiceInstall - 设置服务以当前 Windows 用户身份运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am installing a Windows service using WiX. How can I make the service run in the context of Windows User that runs the installer?

推荐答案

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

You need to have both the account name and password for the user you want to run the service as. I was able to accomplish this by adding a custom UI to my installer asking for a User Name and Password, and then using the supplied values for the Account and Password attributes on the ServiceInsall element.

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

Note that what ever account is used to run the service will need to have the Log On As Service privileged. This is not granted to users by default. I was able to use the User element from the UtilExtension schema to add this priveledge to the user. Adding the privileged to the user would only succeed if the user running the installer is an administrator.

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

Here's the code I used. SERVICECREDENTIALS_USERLOGIN and SERVICECREDENTIALS_PASSWORD are the properties populated from the custom 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 用户身份运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆