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

我正在使用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="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>

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...