简体   繁体   中英

.NET Windows Service Username

I have a Windows Service that I created with .NET 4.5. It needs to run under the context of a Domain User Account (service account) to connect to a SQL Server using a trusted connection. In VS2013 I set the ProjectInstaller to use Account type "User."

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

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. Details at: Using InstallUtil and silently setting a windows service logon username/password

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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