加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

WiX ServiceInstall – 将服务设置为当前Windows用户运行

发布时间:2020-12-14 04:32:35 所属栏目:Windows 来源:网络整理
导读:我正在使用WiX安装 Windows服务.如何使服务在运行安装程序的Windows用户的上下文中运行? 您需要同时拥有要运行服务的用户的帐户名和密码.我可以通过在我的安装程序中添加一个自定义UI来完成此操作,要求输入用户名和密码,然后使用ServiceInsall元素上的Accou
我正在使用WiX安装 Windows服务.如何使服务在运行安装程序的Windows用户的上下文中运行?
您需要同时拥有要运行服务的用户的帐户名和密码.我可以通过在我的安装程序中添加一个自定义UI来完成此操作,要求输入用户名和密码,然后使用ServiceInsall元素上的Account和Password属性提供的值.

请注意,用于运行服务的帐户将需要具有“登录服务”权限.默认情况下不会授予用户.我可以使用UtilExtension模式的User元素将该priveledge添加到用户.如果运行安装程序的用户是管理员,则向用户添加特权只能成功.

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

<Component Id="ServiceEXE" Guid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx">
  <File Id="ServiceEXE" Name="YourService.exe" DiskId="1"
        Source="pathtoYourService.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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读