views:

97

answers:

2

I'm building a Windows service that performs different actions based on which Windows user is logged in. If I install my service under one user, and set it to start-up, will a separate instance of it run for each user that logs in, continuing to run, even if more than one user is currently logged in?

This is the behavior I would like, but if it is not possible, I'll have to plan for something else.

And in general, is each user log-in session like its own, independent environment? In other words, if I have a driver installed that interacts with my service via named pipes, will the piped message sent from the currently logged in user's driver be also be received by the other service instances running in under other logged-in users (assuming they do run separate instances, as asked above)? Or are they completely separate environments with their own drivers/kernal instances?

+1  A: 

At least as of XP, services could only have one instance. Of course, a privileged service could create processes as other users, but they wouldn't be, formally, services.

bmargulies
So if I created a privileged service, would it start when Windows started, or when the first user logged in? Would I have it start up a new process for new users when those users logged in? And in my driver example, how would I know which user performed an action that triggered the driver to interact with the service? On service to rule them all would work fine for me, I just need to work out these details.
Mike Pateras
Services have two ways to start. At boot, or 'manually'. If you want login to trigger it, you need to write some sort of a hook (perhaps related to GINA) to notice the login and start your service.
bmargulies
+1  A: 

As noted, a Windows service has one instance. By default it runs as the Local System account and not as any particular user (and it does not have access to individual users' environments etc.) It does not inherit anything from the currently logged-in user in terms of credentials. You can set specific user credentials for the service (through the service control manager, for example) to run the one instance of the service as any given user. But you only get one.

Joe