service auto start

R

Roger Levy

I want to start a service written as a Win32 .exe (not a driver) at boot time.
I have referred to the XPe MSDN documentation on "service data" and I also found
just one relevant message thread via Google Groups. The message thread, which
was from last February, was inconclusive and some of the information contradicts
MSDN. Some of the people contributing to that thread were Heidi Linda, Jon
Fincher, and "The Real Andy." Unfortunately the thread ends with a request that
the discussion be continued via private mail so potentially useful information
was not shared.

I created a component from my service .exe and set service data according to my
best interpretation of the MSDN documentation. However my service does not
start. I'm particularly unclear about two parameters:

StartType - The SERVICE_AUTO_START type is described in MSDN as "Indicates a
driver or service started on demand, either by the Plug and Play Manager when
the corresponding device is enumerated or by the Service Control Manager in
response to an explicit user demand." Does this mean the service will start
automatically? What is meant by "response to an explicit user demand?" Is
there some other type that will start my service automatically or is there some
other service information involved in auto start?

ServiceType - SERVICE_WIN32_OWN_PROCESS (numeric value 16 - a service that runs
in its own process) seems to most closely fit my service. However in the
message thread Jon Fincher provides information that didn't even include this
type and said "Unless it's a file system driver, use 1" which is described as a
"kernel driver".

I got no response to questions on this topic posted last week and since there
seems to be a real lack of information on the topic, I'm hoping to get some
help.

Roger Levy
 
H

Heidi Linda eMVP

This one sadly got dropped. I believe the only way to get
a standard .exe to run as a service (when not originally
written as a service) is to use additional software, which
I did not have room for in my build. My system therefore
automatically logs in, then locks itself so that you can't
use it without the password. The app is started from a
batch file which is started from the Run key.
An app that runs as a service under 2k/xp is no problem,
would it be possible to rewrite the app as a service?
 
R

Roger Levy

The program is written as a service which is a fact I put in my mail last week
but forgot to repeat. I had no experience developing services but I found an
article at devcentral.iftech.com by Marshall Brain titled "Win32 Programming
Features" that includes a section on services. I adapted his code into a
trivial service that I will enhance as I go and I tested the end product on my
NT desktop. I can start, pause, and stop the service on NT and it does what I
expect however it does not even start when configured into XPe according to the
information I described which was all I could find.

Some other info which may be relevant is that I am using Minlogon and Command
Shell. I found a newsgroup posting last week which unfortunately I cannot
locate again that suggested these components may not pull in enough dependencies
to start a service. The suggestion was to include Winlogon, run dependency
check to pull in additional components, and then disable Winlogon and build
without running dependency check again. I tried this approach but this system
died with a blank screen after displaying the splash screen immediately
following the FBA reboot, i.e. at the time that is usually followed shortly by
the "sealed" message.

Roger Levy
 
S

Slobodan Brcin

Roger, although you are writing service for XPe you are in the wrong NG.

You should post similar questions to
microsoft.public.development.device.drivers there are other groups as well.
This is issues for programmers and not for XPe users. And you are probably
wasting your time waiting for answer on this matter in this NG.

Come back when it start working on XP, and you need to componentize it for
XPE.

Best regards,
Slobodan
 
H

Heidi Linda

Probably a stupid question, but have you tried it on XPPro?
I'd highly recommend doing that. Also - have you tried
doing it with winlogon? I believe minlogon only leaves you
with the localsystem account, which may be why you're
having problems.
I had terrible trouble getting my Apache service to run
when installed from Target Designer, and it turned out to
be that I needed to use ntrights.exe to give the user the
right to log on as a service. I have the setup batch file
I use delete this file once that has been done, however,
as the file cannot be distributed with XPe.
The service data is baffling.
I have apache set up as follows:
StartType: 2 (this appears to be 'automatic'
StartName: .\User (the user name)
ServiceType: 16 (not a clue)
ServiceName: Apache
ServiceDisplayName: Apache
ServiceDescription: Apache/1.3.27 (Win32)
ServiceBinary: D:\program files\apache
group\apache\apache.exe
Password: UserPass
ErrorControl: 1
Dependencies: 'tcpip', 'afd'

I have no idea if this is of any help...
 
S

Slobodan Brcin

Heidi,
Most services are working within system account.

Also they are working with minlogon, because if they didn't XPe with
minlogon would be useful.
Probably there are services that require User account, but I don't use them.

If I understood correctly Roger is trying to write service, so this is wrong
NG for him at least for the moment.


Regards,
Slobodan
 
H

Heidi Linda

Slobodan Brcin said:
Heidi,
Most services are working within system account.

Also they are working with minlogon, because if they didn't XPe with
minlogon would be useful.
Probably there are services that require User account, but I don't use them.

If I understood correctly Roger is trying to write service, so this is wrong
NG for him at least for the moment.
Thinking about it, you're right, I was having problems because Apache
just won't work set up to run as localsystem - there are networking
issues.
In any case, I believe Roger is actually at the stage of
*componentising* a service he's already written, not trying to write
one, so he *is* in the right group.
 
R

Roger Levy

I'm in the right NG. The service is written and it works fine on both NT4 and
XP-Pro desktops. In its current form it is a trivial service based on the code
I referenced in my original post. I made some simple modifications for it to
create a socket, listen, and after accepting a connection it simply writes the
messages it receives from a peer into a log file. It also writes some status
information into the file. This is a test level framework that I'll extend for
the real application. As I said it works fine on XP-Pro. I have small command
line programs to install and delete the service. The start, stop, pause, and
resume functions of the service management GUI work fine and my file is being
populated as expected.

I componentized the .exe of the service by following basic steps for creating a
component that were provided in a tutorial for a Hello World component. I
populated the required service data fields but none of the optional ones. I
included the basic TCP/IP networking component in my target. As I stated, I
don't feel the documentation for the service data fields is well written -- I'd
still love to know what "an explicit user demand" means.

Caveats - I am a beginner with XPe (but a software engineer for 30+ years) and
I'm mostly synthesizing techniques that I glean from the tutorials. My system
is Minlogon based with command shell and a ramdisk. It is network booted. I
can find no tools in this configuration to examine the state of services so
that's another question I have -- are there such tools for my configuration? My
conclusion that my service does not start is based on the fact the log file that
it creates and populates does not get created in my ramdisk. I have assumed
this is a service start problem as opposed to a permissions problem because it
is my understanding that under minlogon everything runs under a single account
that automatically is logged in. So in summary I believe the service is not
starting and I can't find any tools for my configuration that would help me
understand what's going on. The tools issue is a big concern to me. Even the
most basic 8K monitors that I've worked with in tiny embedded systems provide
some means for examining task and resource states. Can it be true that an XPe
system that does not include Winlogon and graphical components provides no such
tools?

Roger Levy
 
D

Doug Hoeffel \(eMVP\)

How about sc.exe? It's the Service Command Line Tool component.

HTH... Doug
 
S

Slobodan Brcin

Sorry,

I'll try to give you separate answers in few postings, but last service I
have written was two years ago, so my knowledge on this is litle rusty.
Caveats - I am a beginner with XPe (but a software engineer for 30+ years) and
I'm mostly synthesizing techniques that I glean from the tutorials. My system
is Minlogon based with command shell and a ramdisk. It is network booted. I
can find no tools in this configuration to examine the state of services so
that's another question I have -- are there such tools for my configuration? My
conclusion that my service does not start is based on the fact the log file that
it creates and populates does not get created in my ramdisk. I have assumed
this is a service start problem as opposed to a permissions problem because it
is my understanding that under minlogon everything runs under a single account
that automatically is logged in. So in summary I believe the service is not
starting and I can't find any tools for my configuration that would help me
understand what's going on. The tools issue is a big concern to me. Even the
most basic 8K monitors that I've worked with in tiny embedded systems provide
some means for examining task and resource states. Can it be true that an XPe
system that does not include Winlogon and graphical components provides no such
tools?

Minlogon does not impact services, they are executed on XP, as on XPE in
system account.
But on minlogon even ordinary programs are executed under system account.


Monitor, ah yes, you won't it and ntoskrnl.exe got it.

in boot.ini from target device you need to enter switches
/debug /debugport=com1 /baudrate=115200

This will allow you to debug any driver or executable using WinDbg on
development machine. Look for parameters.
Also it will show every output sent to debugger.
Use API commands like OutputDebugString to make text output to debugger.

Since you are software engineer everything else should be easy.

And I still think what I have said you are in wrong NG since you are asking
questions what SERVICE_AUTO_START does, etc.
To this questions in right NG you would get in few hours many answers, and
references. So for you it would be better.

Best regards,
Slobodan
 
S

Slobodan Brcin

How about sc.exe? It's the Service Command Line Tool component.

Yes this would be my next post :)

It is working under minlogon. I have used it few times before. And also
tried it before my first post.

Slobodan
 
S

Slobodan Brcin

I componentized the .exe of the service by following basic steps for
creating a
component that were provided in a tutorial for a Hello World component. I
populated the required service data fields but none of the optional ones. I
included the basic TCP/IP networking component in my target. As I stated, I
don't feel the documentation for the service data fields is well written -- I'd
still love to know what "an explicit user demand" means.

You can always import registry entries from XP registry to your component,
so it will be preinstalled on XPE exactly as on XP.

Yes I agree that there are many fields than are not described, but one can
always assume what they are used for reading non XPE related docs.
If not you can always do one thing in many different ways.


Slobodan
 
S

Slobodan Brcin

I'm in the right NG. The service is written and it works fine on both NT4
and
XP-Pro desktops. In its current form it is a trivial service based on the code
I referenced in my original post. I made some simple modifications for it to
create a socket, listen, and after accepting a connection it simply writes the
messages it receives from a peer into a log file. It also writes some status
information into the file. This is a test level framework that I'll extend for
the real application. As I said it works fine on XP-Pro. I have small command
line programs to install and delete the service. The start, stop, pause, and
resume functions of the service management GUI work fine and my file is being
populated as expected.

This one is last from me.

While you test applications and services, you should copy all binaries
manually to XPE, don't use component which will modify registry, because it
can make mess in initial testing.

Then use your install application, and manually install service like you
would on XP.
Add to start of service and in other part of service code OutputDebugString
instead (or use them combined) of writes to file.

So you will see what check points are passed in remote debugger.


Best regards,
Slobodan
 
H

Heidi Linda eMVP

For checking the state of services you can include sc.exe (called
something line service command line tool) in your build, or, if you
want, the services control panel. If you include that, (as I was doing
for ages, and it might be worth doing just for debug purposes) you can
launch it (sevices.exe iirc) from the command line. It took quite a bit
of doing to get things working *without* that control panel.
 
R

Roger Levy

Thanks for the pointer sc.exe. Let's call my service "myService." When I
execute "sc query myService" I see that the service is in a STOPPED state. When
I execute "sc start myService" I get:
[SC] StartService FAILED 2:
The system cannot find the file specified

When I componentized the service binary I specified the following in
Components/Files:
Name: myService.exe
Path: %24%\myService
and in the runtime I find that myService.exe is in directory C:\myService.

Also at component definition time I specified the following in
Components/Resources/ServiceData:
ServiceBinary: %24%\myService\myService.exe

When I execute "sc qc myService" the response includes:
BINARY_PATH_NAME: C:\myService\myService.exe

All the path and file specifications seem consistent and correct to me so why
can't the "sc start" command find the file and start it as a service? Also,
with apologies to Slobodan for asking in this NG, once that problem is figured
out will the service start automatically if the StartType is 2?

Roger Levy
 
S

Slobodan Brcin

Thanks for the pointer sc.exe. Let's call my service "myService." When I
execute "sc query myService" I see that the service is in a STOPPED state. When
I execute "sc start myService" I get:
[SC] StartService FAILED 2:
The system cannot find the file specified

When I componentized the service binary I specified the following in
Components/Files:
Name: myService.exe
Path: %24%\myService
and in the runtime I find that myService.exe is in directory C:\myService.

This is ok %24% is valid here.
Also at component definition time I specified the following in
Components/Resources/ServiceData:
ServiceBinary: %24%\myService\myService.exe

But %24% is probably not valid entry here. (try entering full path
C:\myService\myService.exe)
Is there a good reason why you don't use system32 folder as all other
services?
All the path and file specifications seem consistent and correct to me so why
can't the "sc start" command find the file and start it as a service?
For start try with system32, and when it start working then if you need
change to folder that you want.
Also, with apologies to Slobodan for asking in this NG,
Why apologies, I just wanted to guide you to place where this would be
answered more accurately and faster than here.

Most people here don't write drivers, nor services as that matter. And some
of them know what this field means, but they don't have to know it to
successfully use CD and TD.
If someone has written service that is working, and give you way to install
it. Then you only need to make components based on info you gather from inf
files and registry.
And if all go well you don't have to analyze why someone used some value.
Since you are that someone, the best way to find info is from others like
you.
once that problem is figured out will the service start automatically if
the StartType is 2?

Yes it should. But you are currently working on this service and testing it,
so you should know better than me.
If you doubt restarts XP, and see if it will start. If it does then it will
on XPE, it is simple as that.


Best regards,
Slobodan
 
H

Heidi Linda

Name: myService.exe
Path: %24%\myService
and in the runtime I find that myService.exe is in directory C:\myService.

I assume you mean c:\myService\myService.exe?
Also at component definition time I specified the following in
Components/Resources/ServiceData:
ServiceBinary: %24%\myService\myService.exe

When I execute "sc qc myService" the response includes:
BINARY_PATH_NAME: C:\myService\myService.exe

All the path and file specifications seem consistent and correct to me so why

There should be some registry entries about the service, see if they
indicate the correct paths.
 
R

Roger Levy

Slobodan,
I didn't use an explicit path for ServiceBinary as you suggest because the
documentation specifically said not to do so. The documentation said the
parameterized version of the path should be used and it even provided a link
to a table defining the relationship between %n% values and path type
(%24% -> Apps). This is explained at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xpehelp/html/xeconservicedata.asp

As for why I didn't choose System32, my answer is why should it matter other
than it being a convention? I suppose I am influenced by the way Unix
programmers generally organize directories -- a locally developed command
would not be placed in /bin or /usr/bin which contain standard commands but
rather in /usr/local/bin. It makes more sense to me especially if someone
else examines a system to see what local features have been added but as I
said I don't think that the directory structure should matter given that the
parameterized path provided in the service data resolves to a full path
name.

Therefore I think that your statement that using %24% in the service data
"is probably not valid" is incorrect but please explain if you still believe
otherwise. And again I do not agree that I am testing the service -- it
does exactly what I expect in XP-Pro despite me never having put it in
System32. The problem always has been that it will not start in XPe and the
XPe specific documentation is unclear. Nonetheless I will try System32
tomorrow and if it works then I will claim it to be a bug because XPe will
have behaved differently from XP-Pro and XPe will be treating System32 in
some special way that it should not be doing in this case.

Thanks for your continued interest and support,
Roger Levy

Slobodan Brcin said:
Thanks for the pointer sc.exe. Let's call my service "myService." When I
execute "sc query myService" I see that the service is in a STOPPED state.
When I execute "sc start myService" I get:
[SC] StartService FAILED 2:
The system cannot find the file specified

When I componentized the service binary I specified the following in
Components/Files:
Name: myService.exe
Path: %24%\myService
and in the runtime I find that myService.exe is in directory
C:\myService.

This is ok %24% is valid here.
Also at component definition time I specified the following in
Components/Resources/ServiceData:
ServiceBinary: %24%\myService\myService.exe

But %24% is probably not valid entry here. (try entering full path
C:\myService\myService.exe)
Is there a good reason why you don't use system32 folder as all other
services?
All the path and file specifications seem consistent and correct to me so
why can't the "sc start" command find the file and start it as a
service?
For start try with system32, and when it start working then if you need
change to folder that you want.
Also, with apologies to Slobodan for asking in this NG,
Why apologies, I just wanted to guide you to place where this would be
answered more accurately and faster than here.

Most people here don't write drivers, nor services as that matter. And some
of them know what this field means, but they don't have to know it to
successfully use CD and TD.
If someone has written service that is working, and give you way to install
it. Then you only need to make components based on info you gather from inf
files and registry.
And if all go well you don't have to analyze why someone used some value.
Since you are that someone, the best way to find info is from others like
you.
once that problem is figured out will the service start automatically if
the StartType is 2?

Yes it should. But you are currently working on this service and testing it,
so you should know better than me.
If you doubt restarts XP, and see if it will start. If it does then it will
on XPE, it is simple as that.


Best regards,
Slobodan
 
S

Slobodan Brcin

Roger,

I had some problems with ServiceBinary field myself, long time ago. But I
have not investigated to see what it was.

Use regedit on your device, and go to the
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services and analyze ImagePath for
your service, and also look for other services and drivers as well.
And you will see that they begin with System32\DRIVERS\ or
%SystemRoot%\System32\ etc, I don't see full resolved path names, here.
And if this field is really pointing to your service path then service
should work.

It you are not testing service, then why don't you use same value you used
with CreateService( ...) dwStartType value?

And yes you are right, you have followed instructions MS gave on this link
correctly, and it is not working. Test and see if this is true or not. I
don't know.

I know that is this was true, then paths would have two meanings. One for
low-level drivers, and one for rest of the services and drivers, which would
be inefficient. I say low-level because there in not guarantied that there
is drive letter while they are starting.

Please let us know what you have found, at the end.

Regards,
Slobodan
 
S

Slobodan Brcin

I know that is this was true, then paths would have two meanings. One for
low-level drivers, and one for rest of the services and drivers, which would
be inefficient. I say low-level because there in not guarantied that there
is drive letter while they are starting.

They probably do have two meanings.

And try to manually compare XP and XPE registry entries for your service.

Slobodan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top