Share via


Passing Start Parameters Into A Service

Question

Thursday, January 19, 2006 6:42 AM

Hi all ...

I'm using VS 2005 and .Net 2.0    I've been able to set up a service based on the VS service application, get it installed, and start/stop it using the Windows Services SCM.

On the properties window for my service there's the standard "Start Parameters" field.  I believe the idea is just like passing Main command line arguments to a console application.

I'd like to pass in one data value to my service when it starts using the Start Parameters option.  I experimented with Main and OnStart, but wasn't having much luck.  Is there a reference or example on how to do this?

Thanks!

DB

All replies (2)

Friday, January 20, 2006 10:16 PM âś…Answered | 1 vote

Did you know the Start Paremeters are not saved?

They are only sent to the service, if you enter them in the SCM and click Start. The next time you display the properties for the service, the Start Parameters will be blank.

You should however see these parameters in an overriden OnStart method.

For persistent parameters, the registry is a good option. .NET's Registry class makes retrieval easy (Microsoft.Win32 namespace).

Service parameters are normally stored in key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Your App Name> (use Registry.LocalMachine). 

 

 


Tuesday, April 29, 2014 11:19 AM

What I need to do start a service at a particular port.

It can be done manually by typing  -p <port no> at the start parameter and starting the service.

how it can be done using a single command in a cmd prompt

I wish to execute this only once, not every time.