Discussion:
Service parameters ignored
(too old to reply)
Tom
2009-12-08 14:32:12 UTC
Permalink
I am trying to create/start an NT service on Windows server 2003 using
sc.exe The problem is that the parameters are not getting passed as I
would expect to the service. Instead unless I manually start the
service from the windows services viewer and explicitly give the
parameters they are not passed to the service.

Here is my sc command
sc.exe create CalcService binPath= "C:\Model\CalcService
\CalcService.exe -p C:\Model\CalcService"
sc.exe start CalcService # Does not start w/ parameters

Thanks for any help,
Tom
Don Burn
2009-12-08 14:38:12 UTC
Permalink
Probably becuase the arguments should be provided in the "sc start" command
not the binPath of the "sc create"
--
Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Post by Tom
I am trying to create/start an NT service on Windows server 2003 using
sc.exe The problem is that the parameters are not getting passed as I
would expect to the service. Instead unless I manually start the
service from the windows services viewer and explicitly give the
parameters they are not passed to the service.
Here is my sc command
sc.exe create CalcService binPath= "C:\Model\CalcService
\CalcService.exe -p C:\Model\CalcService"
sc.exe start CalcService # Does not start w/ parameters
Thanks for any help,
Tom
__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4670 (20091208) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
__________ Information from ESET NOD32 Antivirus, version of virus signature database 4670 (20091208) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
Tom
2009-12-08 16:24:58 UTC
Permalink
Post by Don Burn
Probably becuase the arguments should be provided in the "sc start" command
not the binPath of the "sc create"
Thank you I was able to start it using the sc command by adding the
parameters
But I do not want to always manually start this service so what is the
appropriate
method to add parameters so that if the service is set to automatic
when the machine comes
up the service is started and given these parameters? And similarly if
I use the windows service
browser to stop the service, shouldn't I be able to right click the
service, stop/then start and see
the service start with the parameters.
Remy Lebeau
2009-12-08 21:28:24 UTC
Permalink
Post by Tom
But I do not want to always manually start this service so what is
the appropriate method to add parameters so that if the service
is set to automatic when the machine comes up the service is started
and given these parameters?
You have two choices:

1) continue putting the parameters in the .exe file's command-line like you already are, but then update your service code to look at the .exe's command-line parameters in addition to, or instead or, the service start parameters

2) store the parameters in the Registry or a cofig file somewhere, and have the service load them at startup as needed. Many Microsoft and third-party services have a "Parameters" subkey in the Registry for that purpose, in other words:

"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<ServiceName>\Parameters"
Post by Tom
And similarly if I use the windows service browser to stop the service,
shouldn't I be able to right click the service, stop/then start and see the
service start with the parameters.
Not if you use standard service start parameters, no. Those can only be specified on a per-start basis within the SCM UI, or the Win32 API StartServie() function. Persistant parameters need to be handled differently, as described above.
--
Remy Lebeau (TeamB)
Tom
2009-12-09 22:50:17 UTC
Permalink
Thank you for the detailed response got it working now.

Tom
dcipher
2011-03-17 20:29:55 UTC
Permalink
Remy Lebeau wrote on 12/08/2009 16:28 ET
"Tom" wrote in messag
news
On Dec 8, 8:38 am, "Don Burn
Post by Tom
But I do not want to always manually start this service so what i
the appropriate method to add parameters so that if the servic
is set to automatic when the machine comes up the service is starte
and given these parameters
You have two choices
1) continue putting the parameters in the .exe file's command-line like yo
already are, but then update your service code to look at the .exe'
command-line parameters in addition to, or instead or, the service star
parameter
2) store the parameters in the Registry or a cofig file somewhere, and hav
th
service load them at startup as needed. Many Microsoft and third-part
services have a "Parameters" subkey in the Registry for that purpose
in other words
"HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServices<ServiceName>Parameters
Post by Tom
And similarly if I use the windows service browser to stop the service
shouldn't I be able to right click the service, stop/then start and see th
service start with the parameters
Not if you use standard service start parameters, no. Those can only b
specified on a per-start basis within the SCM UI, or the Win32 AP
StartServie() function. Persistant parameters need to be handle
differently
as described above
Remy Lebeau (TeamB
H

What I need to know is how to obtain the "Service Start Parameters
used in the MMC. I can get the command line ones for the process but I do no
know how to get the service specific parameters that can be manually entere
i
the MMC's "StartUp Parameters" box

Thanks
Simon

Remy Lebeau
2009-12-08 21:23:40 UTC
Permalink
Post by Tom
The problem is that the parameters are not getting passed
as I would expect to the service.
You are specifying command-line parameters for the .exe file itself, not start parameters for your service that runs inside the .exe file. Those are two different things. When you start a service, the .exe command-line parameters are used when the SCM needs to spawn a new process. Those parameters are accessible via the Win32 API GetCommandLine() function, the RTL's argc/argv[] array, etc. The service start parameters, on the other hand, are passed to the running service via the lpszArgv parameter of its register ServiceMain() callback instead. It sounds like you are expecting your .exe command-line parameters to appear in the service start parameters, and that is simply not what happens.
Post by Tom
Instead unless I manually start the service from the windows services viewer
and explicitly give the parameters they are not passed to the service.
They are not supposed to be, because you put them in the wrong place for that.
Post by Tom
sc.exe start CalcService # Does not start w/ parameters
Yes, it does, just not where you are expecting them to appear.
--
Remy Lebeau (TeamB)
Continue reading on narkive:
Loading...