我正在使用WiX安装一个Windows服务。如何使服务在运行安装程序的Windows用户的上下文中运行?
发布于 2009-09-30 18:33:53
您需要拥有要运行该服务的用户的帐户名和密码。为此,我在安装程序中添加了一个自定义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>https://stackoverflow.com/questions/1487638
复制相似问题