2

I have coded a simple c# windows service.If its installed using installutil ,will the service be available for all users of the system?

In case of server operating system,under what account the service should be installed so that it will start automatically on server startup?

Please throw some light on this.

techno
  • 181
  • 1
  • 8

1 Answers1

3

Yes. Ordinary Windows services are inherently global; it makes no difference which account was used to install the service. So far as I'm aware, Windows doesn't even record that information.

You do need to have administrator privilege in order to install a service.

To configure a service to start automatically with Windows, configure the service start type appropriately. See step 5 in How to: Add Installers to Your Service Application.

Addendum: if the service is running in a domain account, it might in some situations be necessary to configure the service for a delayed start. This answer explains how to do that in .NET. If the service runs normally when started manually but generates "invalid username or password" type errors when starting automatically, configuring it for delayed start may help. I'm not sure yet of the underlying cause of the problem.

(If a service uses the SERVICE_USER_OWN_PROCESS or SERVICE_USER_SHARE_PROCESS type, then there are separate instances of the service for each logged on user, and the behaviour of this sort of service does not appear to be properly documented. However, I believe the answer is the same: the installation is still global and it still makes no difference which account installs the service.)

Harry Johnston
  • 6,005
  • 4
  • 35
  • 52
  • 1
    Windows doesn't record who installed the service, other than potentially in logging. Service registration is primarily under `HKLM\System\CurrentControlSet\Services` which is inherently global. – Matthew Wetmore Aug 26 '18 at 01:36
  • Thanks for your input.Currently i'm installing the service to run as the current user by supplying the user credentials.I'm doing this to allow the service to access network locations accessible by the logged in user.If the service runs from another logon session by another user,will the network shares still remain accessible? How does this work on server operating systems? Please advice. – techno Aug 26 '18 at 04:45
  • If a service needs access to network shares, it should have its own account - preferably a [managed service account](https://blogs.technet.microsoft.com/askds/2009/09/10/managed-service-accounts-understanding-implementing-best-practices-and-troubleshooting/). Using a user's account is considered bad practice for various reasons, e.g., if the user changes their password the service will stop working. – Harry Johnston Aug 26 '18 at 08:14
  • 2
    ... and if your code should have the same access to the network as the logged on user, then it should just be running in the logged on user's context, i.e., it shouldn't be a service at all. – Harry Johnston Aug 26 '18 at 08:14
  • The application only needs access to a single folder set by the user.I'm not familiar with server operating systems,will this scenario work out with server operating systems. – techno Aug 26 '18 at 18:21
  • It isn't clear to me what you're trying to do. But it makes no difference whether you are running on Windows Server or a desktop edition of Windows, they behave in exactly the same way. – Harry Johnston Aug 26 '18 at 19:35
  • thanks for your response.What im trying to achieve is the following. --> Monitor a folder for new files and perform some operation on the newly created files and save it to another location.The application works fine on the local machine folders.But when a user selects a network location to monitor, the service running as 'local system' does not have access to the folder.I'm solving this issue by running the service as the currently logged in user by supplying the credentials. – techno Aug 27 '18 at 06:58
  • The currently logged in user has access to the network location as he/she has supplied the credentials already in windows explorer.When it comes to server operating systems will the service needs the user to be logged in to function? Please advice – techno Aug 27 '18 at 07:06
  • It makes no difference to the service whether the user is logged in or not. – Harry Johnston Aug 27 '18 at 08:18
  • This should be a scheduled task. It can run as the currently logged on user and will have their permissions – spacenomyous Aug 27 '18 at 13:13
  • @HarryJohnston So,the service will start working when the server is turned on ? – techno Aug 27 '18 at 18:09
  • Yes, at least in theory. As it happens I've just been having some trouble with a similar scenario: it may be necessary to configure the service start type to Automatic (Delayed Start) rather than just Automatic. See [this answer](https://stackoverflow.com/a/9525289/886887). – Harry Johnston Aug 27 '18 at 19:36
  • @HarryJohnston Thanks for your help,I have run into another problem.A service installed to run as 'LocalSytem' cannot access network locations.The scenario is this - In explorer I navigate to network places,open a system, i enter the credentials of the system i get access to the folder in the remote machine. – techno Sep 01 '18 at 07:02
  • The service cannot access the folder unless i install it using the remote computer user name and password,I have tried using the local user credentials(as the current user has access to the folder as i have already authenticated) but it does not work. Seems like i need to install the service with the remote machine username and password. – techno Sep 01 '18 at 07:02
  • In reallife scenarios a network share access needs remote machine user credentials right? – techno Sep 01 '18 at 07:06
  • Sounds like you're not in a domain environment. To make it work the way you want it to, the user will need to provide the service with the remote credentials, and the service will have to explicitly provide those credentials when connecting to the remote machine. – Harry Johnston Sep 01 '18 at 10:11