您需要同时拥有要运行服务的用户的帐户名和密码.我可以通过在我的安装程序中添加一个自定义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://www.jb51.cc/windows/364028.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。