简体   繁体   English

Windows服务在安装时选择用户或系统帐户

[英]Windows Service Choose User or System Account on Install

When installing a windows service, is there a way to let the user installing choose between a specific user account and a computer account, such as LocalSystem? 安装Windows服务时,有没有办法让用户安装在特定用户帐户和计算机帐户之间进行选择,例如LocalSystem? I see how to do this at build time through service installer properties, but not during install. 我看到如何通过服务安装程序属性在构建时执行此操作,但在安装期间不这样做。

@Doobi, @Eric, in my experience (Win7Home 64-bit, VS2010Express, not on a domain) @Doobi,@ Eric,根据我的经验(Win7Home 64位,VS2010Express,不在域上)

 processInstaller.Account = ServiceAccount.LocalService;
 processInstaller.Username = null;
 processInstaller.Password = null;

will install the service as LocalService without a password prompt. 将在没有密码提示的情况下将服务安装为LocalService。

To install the service as a local user account (and provide a password prompt to enable the user to supply the credentials) I had to use: 要将服务安装为本地用户帐户(并提供密码提示以使用户能够提供凭据),我必须使用:

 this.serviceProcessInstaller.Account =System.ServiceProcess.ServiceAccount.User;
 this.serviceProcessInstaller.Password = null;
 this.serviceProcessInstaller.Username = null;

The important step I had to take to get the service installed is to put the computer name in the credentials dialog box, ie MYPC\\dave instead of dave . 我必须采取的安装服务的重要步骤是将计算机名称放在凭据对话框中,即MYPC\\dave而不是dave I was surprised that I'd have to do this as it's not on a domain. 我很惊讶我必须这样做,因为它不在域上。 I've added this comment as no other posts I've seen about this mention having to prefix the username with the PC name. 我添加了这条评论,因为没有其他帖子我看过这个提及必须在用户名前加上PC名称。

Yes there is, it's on the process installer. 是的,这是在流程安装程序上。 I think in the newer frameworks it's a visible property if you select the process installer on the design surface. 我认为在较新的框架中,如果您在设计图面上选择流程安装程序,则它是一个可见属性。 The last time I did it (.NET 2.0) you have to add something similar to this to the *.designer.cs file: 我最后一次(.NET 2.0)你必须在* .designer.cs文件中添加类似的内容:

 processInstaller.Account = ServiceAccount.LocalService;
 processInstaller.Username = null;
 processInstaller.Password = null;

Adding to previous answers, don't forget to append Machine name to Username while entering "Username" Field of password prompt. 添加到以前的答案,在输入“用户名”密码提示字段时,不要忘记将机器名称附加到用户名。 Otherwise service will not accept the credentials although if you give correct username and pwd. 否则服务将不接受凭证,但如果您提供正确的用户名和密码。 It will keep on pop up prompt to enter credentials. 它将继续弹出提示输入凭据。 It took me one day to figure out this. 我花了一天时间弄明白这一点。 Thanks to Badgerspot! 感谢Badgerspot!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows服务安装程序用于不同的用户帐户(本地系统除外) - Windows service installer for different user account (other than local system) Windows服务(使用用户帐户登录) - Windows service with User account Login 作为系统帐户运行的 Windows 服务如何获取当前用户的 \AppData\Local\ 特殊文件夹? - How can Windows service running as System account get current user's \AppData\Local\ special-folder? 是否可以以编程方式设置Windows服务的用户帐户? - Is it possible to programmatically set the user account for a windows service? 从Windows Service本地服务帐户静默安装MSI - Silent install msi from a windows service local service account 如何将 Windows 服务安装到另一个系统? - How to install Windows service to another system? Windows 服务作为本地系统帐户停留在“启动”状态 - Windows Service stuck on "starting" status as local system account 如何在系统 Windows 用户帐户下启动控制台应用程序? - How to start a Console App as running under the System Windows user account? 如何使用 c# 以编程方式安装系统服务以使用组托管服务帐户 (gMSA)? - How can I programmatically install a system service using c# to use a Group Managed Service Account (gMSA)? 在带有“本地系统帐户”的“ Windows服务”下运行时,.NET Windows 7截屏不起作用 - .NET Windows 7 take screenshot not working when running under 'Windows Service' with 'Local System Account'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM