From: Tom on
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
From: Don Burn on
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


"Tom" <depkefamily(a)gmail.com> wrote in message
news:00c1d272-1b6c-4c7b-be83-32b9b6ef1993(a)9g2000yqa.googlegroups.com...
>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




From: Tom on
On Dec 8, 8:38 am, "Don Burn" <b...(a)stopspam.windrvr.com> wrote:
> 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.
From: Remy Lebeau on


"Tom" <depkefamily(a)gmail.com> wrote in message news:00c1d272-1b6c-4c7b-be83-32b9b6ef1993(a)9g2000yqa.googlegroups.com...

> 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.

> 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.

> sc.exe start CalcService # Does not start w/ parameters

Yes, it does, just not where you are expecting them to appear.

--
Remy Lebeau (TeamB)
From: Remy Lebeau on

"Tom" <depkefamily(a)gmail.com> wrote in message news:7d42130b-60cf-4fce-8d72-170a72bb8a52(a)v30g2000yqm.googlegroups.com...
On Dec 8, 8:38 am, "Don Burn" <b...(a)stopspam.windrvr.com> wrote:

> 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"

> 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)