简体   繁体   English

.NET Windows服务用户名

[英].NET Windows Service Username

I have a Windows Service that I created with .NET 4.5. 我有一个使用.NET 4.5创建的Windows服务。 It needs to run under the context of a Domain User Account (service account) to connect to a SQL Server using a trusted connection. 它需要在域用户帐户(服务帐户)的上下文中运行,才能使用受信任的连接连接到SQL Server。 In VS2013 I set the ProjectInstaller to use Account type "User." 在VS2013中,我将ProjectInstaller设置为使用帐户类型“用户”。

When I install and start the Service for the first time it prompts be for a the username and password. 首次安装并启动服务时,提示输入用户名和密码。 This is expected since I haven't stored anywhere What I find annoying is that anytime the service is stopped and started, it continues will always ask for the username and password. 这是预料之中的,因为我没有存储任何地方,但我感到烦恼的是,无论何时停止和启动该服务,该服务始终都会要求用户名和密码。

I assume (haven't been able to verify) that if service stops and is set to automatically restart, that it wouldn't be able to automatically restart because it will need the username and password. 我假设(无法验证)如果服务停止并设置为自动重新启动,则它将无法自动重新启动,因为它将需要用户名和密码。

Is there solution to this issue, possibly adding the username and password into the installer? 是否有解决此问题的方法,可能将用户名和密码添加到了安装程序中?

It just doesn't sound like a great thing to embed domain account credentials into the service installer. 将域帐户凭据嵌入服务安装程序听起来并不好。

The following properties should help you 以下属性应该对您有帮助

  • Account : The user account context in which the service runs 帐户 :服务在其中运行的用户帐户上下文
  • AccountType : When set to Automatic, when the machine reboots, your service will be started as part of the boot AccountType :当设置为Automatic时,当计算机重新启动时,您的服务将在启动过程中启动

If the service has already been installed, you can navigate to Local Services from the control panel, right click on your service from the list, and go to properties. 如果已经安装了该服务,则可以从控制面板导航到“本地服务”,右键单击列表中的服务,然后转到属性。 The "logon" tab allows you to specify which account the service runs as. “登录”选项卡允许您指定服务运行的帐户。

Additional References: 其他参考:

I ended finding what I need. 我结束了寻找我所需要的。 You can pass a username and password in the command line for installutil. 您可以在命令行中为installutil传递用户名和密码。 Details at: Using InstallUtil and silently setting a windows service logon username/password 详细信息: 使用InstallUtil并静默设置Windows服务登录用户名/密码

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM