views:

140

answers:

3

Hi,

When a machine reboots, do all the services which are run under the accounts (system/service/network service) get run before a user logs on?

JD.

A: 

Yes, using (by default) a built-in Windows account. In Services (run services.msc) there is a "Log On As" column that tells you the user that the service logs in as.

Richard Ev
A: 

I do not think so. This should be asynchronous. If you are fast enough to log on, some of the services will still be coming up. This does not include "system" services

mfeingold
+3  A: 

Services have a "start type" defined per-service, those types are boot, system, auto, demand, disabled. Services also have dependencies on each other, defined in the registry.

Services with boot and system start type are started during the time period when only NT Native binaries can run (the Win32 API is not yet ready). For example, these services include such as csrss.exe which provides some of the Win32 API.

Once Win32 has been initialized, the services with start type automatic are started. During this time, the service which allows the user to log in runs -- this displays the login prompt and does allow the user to log in.

In every case, if the service being start depends on other services, then the other services will be started in advance.

So, yes, it is possible for users to log in prior to the execution of a service. However, if the login service were to depend on your service... Better, though, if you detect that your service has started. Considering using a named global event with CreateEvent() api. Your service creates the event, your application awaits the event before calling the service. Also, your app can use the ServiceControl API to start the service only when in use.

The windows "Services.msc" management plug-in hides the boot and system services. To learn more about these startup types, refer to this API documentation: MSDN: ChangeServiceConfig Function .

Heath Hunnicutt
Hi, I can only see (in Services.msc) start up types "Manual, disabled, automatic", where can you see the boot, system and demand types? You also mentioned a login prompt, are you saying if I created a service to run under another user account (not mine), and I restarted my machine and logged in with my user account, I would be shown a login prompt for the service?
JD
Try using the command line tool sc.exe where you can see the boot and system types. BTW, your service cannot use these earlier types unless you compile it as NT Native, which is very hard and requires the DDK.
Heath Hunnicutt
It sounds like what you need is to use the services API and use StartService() API to guarantee your service will start and to know when it has finished its start-up.
Heath Hunnicutt
You would not be shown a log-in prompt. When you configure a service to start with a specific user's credentials, you provide those credentials to the services.msc and they are in turn stored in the registry. Later, when the password for that user is changed, the service will fail to start until the stored credentials are updated.
Heath Hunnicutt
Thank Heath, I felt a bit embarrassed asking the question but I am happy I did ask.
JD
LOL, there are no stupid questions!!! If you can find a copy, Marshal Brain's text "Win32 Services: The heart of Windows NT" is an excellent book on these topics. Although written for the C API, the knowledge transfers to .Net.
Heath Hunnicutt