When do windows xp services get started? - windows

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.

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 .

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.

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

Related

Is a serviced component shared between user sessions on a terminal server, or is one process started for each user session?

I have some .NET code in a COM+/Enterprise Services serviced component. I communicate with this component from a WPF application and also from a legacy VBA application.
This arrangement works well when only one user is logged on to a machine. The component starts in its own process when either the .NET or the legacy application instantiates one of its COM objects.
The system also works for the first user to try to run it on a terminal server installation. However, when another user logs on, he/she is unable to use the application. I had hoped that each session would run in isolation, and that one host process would run per session. Am I wrong in this expectation?
In Component Services on the Activation tab my application is configured to run as a "Server application". On the Identity tab, "Interactive user" is selected. On the Security tab, "Enforce access checks for this application" is unchecked.
There isn't session isolation as you describe, instead process ownership limits what you have access to.
Your conclusion seems correct & you will need to determine a suitable mechanism to exchange data with the service.
I used WCF to create a service with a net named pipe listener https://learn.microsoft.com/en-us/dotnet/framework/wcf/index
The idea of using proxies to make rpc calls is attractive, but I found the proxy definitions and stubs to link it all together quite clumsy to use.
If you have events that may be triggered at either end then keeping client/service in sync becomes problematic.
AIUI you cannot invoke a rpc method that ends up invoking an rpc back at the originating end, although that could be a named pipe limitation.
If I was doing this again I would use a socket server in the service & the websocket protocol for biderectional data transfer, even though you might need to implement some thread handling to avoid the listener thread blocking whilst servicing requests.
Hard to find anything authoritative on this. For standard COM you can set the identity to 'Launching user'. The same is not available for COM+.
According to this archived post,
A COM+ application can be configured to run under the logged in account, or
a specified account. Under the application properties, see the Identity tab.
...
Once set however, it remains under that account until the application shuts
down, so you can't have multiple users using the same COM+ application under
different IDs.
That seems to match what is said in this knowledge base article too.
My conclusion is, I should probably accept that my component must run once per machine rather than once per session. It will need to be modified to accommodate this. Since it needs to start new processes in individual sessions, it will have to run as a Windows service under the Local System account (giving due attention to the security implications).

Error 1053: The service did not respond to the start or control request in a timely fashion

I have an executable that I would like to set to run as a service. Using the sc.exe tool provided by windows (see KB article here: http://support.microsoft.com/kb/251192), I successfully "registered" the service. However, when I go to the Service Management Console (Start->Run->services.msc) and start the service, I get the following error:
Error 1053: The service did not respond to the start or control request in a timely fashion.
After reading around my initial impression is that service executables have to conform to an API, and that among the required functions/methods a service has to respond to are a start/stop/restart command. However, this seems to defeat the whole point of the sc.exe tool which is advertised with the ability to turn any executable into a service.
Can anyone shed some light on this for me?
This is the code you are looking for:
sc create SERVICENAME binPath= "cmd /c c:\programlocation\program.exe"
It will not rid you of error 1053, but at least this will apply to the console (CMD) who already did the job of running the app in the background (check task manager to confirm).
Take a look at Topshelf-project which turns many arbitrary executables into services.
When you reference Topshelf, you can run your exe from a command-line, or install it into Windows Services with:
your.exe install
Even with topshelf registered, you would still want to have a logging facility -- such as log4net -- to monitor bootstrapping activities that could prevent it from launching in a timely fashion.
One very likely cause of this behavior is the application that is started is displaying a request for interaction with the end user (messagebox, input prompt, licensing dialog, etc). We have run into this more than once. This usually happens with applications that aren't designed to run as services. You could try running the service as Local System and check the Allow service to interact with desktop checkbox.
The other possibility is that the user the service is configured to run as doesn't have access to resources (disks, databases, etc). If the process works correctly interactively, then try changing the service's user credentials to your user and see if that gets you any further.
Update
Apologies, I assumed the question was regarding srvany which is the application you are looking for.

How to code the OnStart function for windows service program?

I created a service in Visual C++. Installed it using instsrv.exe and srvany.exe.
When I check at the Services applet in Control Panel, the service is registered. But when I want to start it, this message appears:
the service on Local Computer started and then stopped. Some service stop automatically if they have no work to do, for example the Performance logs and Alert Service.
I just have this code inside my OnStart function:
(void)system("C:\ReleaseExe\Example1Server.exe");
I my code correct? Or is there any other way to code it to make sure that the service can be in running state?
Assuming that exe you are starting up is actually your service, this is the wrong way to do it.
The Windows Service Control Manager (SCM) actually calls into your service's EXE via defined entry points - you need to provide the logic to do what your particular service needs in those entry points, including notifying the SCM of state changes in your service (STOPPED-> RUNNING, RUNNING->STOPPED, and so on).
Read the background info on MSDN, starting here, for clarification of what you must provide. Note that OnStart is specific to implementing Services in managed code, you won't be doing it that way in Visual C++. Perhaps C# would be an easier route?

How to deny accessing to a service?

Some services can't start or stop with Service Management Console.
ex) DcomLaunch, SamSs
These services's stop button is disabled on Service Management
Console.
So, we can't stop the services.(Even if we have a Administrator
account)
Is it possible?
How can I do that?
Thanks in advance.
Your service ultimately calls SetServiceStatus to specify its status. Part of this is what controls it accepts. If you don't specify SERVICE_ACCEPT_STOP, the service cannot be shutdown. For managed code, you can set the CanStop property on ServiceBase.
Another possibility that allows a bit more finegrained control is to change the ACL on your service. MSDN has a sample article here. This is usually used if you want to allow non-admin users to be able to control when your service is running.
Please think very carefully if your service shouldn't be stopped - users should be in control of their machine and allowed to stop services at will.

Custom Windows 2003 Services

I have an .exe I want to start when the Win2k3 server boots. Does .exe needs to be setup as a custom service. If so, what is the process to setup the custom service?
I assume you don't really mean at boot time (you would have to write a driver service for that) but rather at user mode system start up.
If your process is uncomplicated you could just set it up as a scheduled task - with the trigger set to system start. If it needs to interact with the system more, i.e. needs to be paused, needs to be shutdown, warned of system events such as power events or shutdown, etc. then you should probably look to convert it to a Win32 service.
If you do need to convert to a service then start reading here and then continue with something like Richter's or Miller's books until you really understand what you are doing. Then write your service application.
If you want to create that service manually, you can use sc.exe for the job. However that exe must be capable to run as service of course.
XYNTservice a simple service that can start pretty much any program as a service.
http://www.codeproject.com/KB/system/xyntservice.aspx

Resources