Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: System service command line parameters

309 views
Skip to first unread message

boris

unread,
Mar 5, 2009, 6:19:16 AM3/5/09
to
"Peter" <Pe...@discussions.microsoft.com> wrote in message
news:17A98FB0-8CC4-4520...@microsoft.com...
> In Services panel I can start service manually with
> command line parameters types into "Start parameters" edit box.
> Does system support any way to store such command line parameters
> persistenly and use them to start service automatically ?
>
> Peter
Yes it does.

http://msdn.microsoft.com/en-us/library/ms682450(VS.85).aspx
>>PASTE>>>>>
lpBinaryPathName [in, optional]

The fully-qualified path to the service binary file. If the path contains a
space, it must be quoted so that it is correctly interpreted. For example,
"d:\\my share\\myservice.exe" should be specified as "\"d:\\my
share\\myservice.exe\"".

The path can also include arguments for an auto-start service. For example,
"d:\\myshare\\myservice.exe arg1 arg2". These arguments are passed to the
service entry point (typically the main function).


<<PASTE<<<


Each service has key in Windows Registry.


The path is: Local Machime\System\CurrentControlSet\Services\<service name>


- where "service name" is different from its name in Services Applet (which
corresponds to service "display name").

Boris


Stefan Kuhr

unread,
Mar 5, 2009, 7:03:08 AM3/5/09
to
Hi Peter,

Peter wrote:
> In Services panel I can start service manually with
> command line parameters types into "Start parameters" edit box.
> Does system support any way to store such command line parameters
> persistenly and use them to start service automatically ?
>
> Peter

No there isn't. The parameters that you pass in the services mmc-snap-in
are those that are passed to the ServiceMain routine if you now start
the service from this mmc snap-in. Those that are stored in the registry
as mentioned in Boris' post are those that are passed as the process
command line parameters, when the process that hosts the service (there
can be more than one service per process) is started by the SCM. Both
string vectors are something entirely different: The parameters that
ServiceMain gets are passed to the StartService API (by the servicex MMC
snap-in for example) whereas those that the service process gets as its
command line parameters are specified at service creation time using the
CreateService API's lpBinaryPathName parameter, as mentioned in Boris' post.

--
Stefan Kuhr

Peter

unread,
Mar 6, 2009, 1:47:01 AM3/6/09
to
Hi Stefan,

I tried it again.
In my experiment I use such command line argument which logs error into
application log and stops service after starting.
It works only from mmc Services when started manually with typed command
line argument into "Start parameters" edit box, like I described in previous
post.
But it is not functional when service starts automatically with system
restart.
My service is installed with one command line argument described above.
I checked service_name registry key, there is right "ImagePath" and after it
there is append my command line parameter, but when service started
automatically,
it is not passed into service_main, and service does not stop.
So I dont know why, but it is not functional on my system
I have W2K3 Server R2 + SP2.
(I hope that I understand right your words and words in CreateService() doc,
and your words: "...is started by the SCM" you mean starting automatically
after machine restart)

Peter

Stefan Kuhr

unread,
Mar 6, 2009, 4:55:39 AM3/6/09
to
Hi Peter,

Peter wrote:
> Hi Stefan,
>
> I tried it again.
> In my experiment I use such command line argument which logs error into
> application log and stops service after starting.
> It works only from mmc Services when started manually with typed command
> line argument into "Start parameters" edit box, like I described in previous
> post.
> But it is not functional when service starts automatically with system
> restart.
> My service is installed with one command line argument described above.
> I checked service_name registry key, there is right "ImagePath" and after it
> there is append my command line parameter, but when service started
> automatically,
> it is not passed into service_main, and service does not stop.
> So I dont know why, but it is not functional on my system
> I have W2K3 Server R2 + SP2.
> (I hope that I understand right your words and words in CreateService() doc,
> and your words: "...is started by the SCM" you mean starting automatically
> after machine restart)
>


What you experience is the whole point of my answer, so I try it again
with other words: The vector you pass as the command line is something
different than the parameters you pass in the services MMC snap-in as
the service start parameters. If the service is yours and you want to
examine the parameters that are stored in the registry, then in your
service you should not evaluate the parameters that are passed to your
ServiceMain (these are the ones from the services MMC snap-in), but you
should instead do a GetCommandLine followed by CommandLineToArgvW. The
concept of command line parameters *and* the concept of service start
parameters is domething entirely different and is necessary because one
process can host multiple services, each with a different set of service
start parameters.

--
Stefan Kuhr

0 new messages