Connect with Expertise | Find Experts, Get Answers, Share Insights

How register service with command line arguments

 
Join Date: Dec 2009
Posts: 2
#1: Dec 1 '09
Hello,

I would like to register service to start with some arguments - meaning command line arguments of service itself. The best approach was some articles about selfregistrating service, like f.e. http://alt.pluralsight.com/wiki/default.aspx/Craig/SelfInstallingService.html

In this case I had assembly executable and could add my parameter at the end, but unfortunately registration itself closed it into dobulequotes :(, so result was "c:\directory\myservice.exe /param" and service didn't not start of couse.

I spent almost all day looking for some solution but till now nothing. Do somebody know some solution or only way is to use an API function ?

tvr

Plater's Avatar
E
M
C
 
Join Date: Apr 2007
Location: New England
Posts: 7,492
#2: Dec 3 '09

re: How register service with command line arguments


Well you can start your service with arguments from the command line
It's like:
Expand|Select|Wrap|Line Numbers
  1. NET START MYSERVICE /param1 /param2 /param3
  2.  
There might be something you can take away from that?

Also there might be something you can do in the registry at:
Expand|Select|Wrap|Line Numbers
  1. HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\MYSERVICE
  2.  
 
Join Date: Dec 2009
Posts: 2
#3: Dec 4 '09

re: How register service with command line arguments


Thank for response, just now I am not in hurry to solve it, but in case I will need, I will try it by edit registry. I am just disapointed to have an installation support inside .net, but no support for add command line parameters when service is beeing registered
Frinavale's Avatar
E
M
C
 
Join Date: Oct 2006
Location: The Great White North
Posts: 7,106
#4: Dec 4 '09

re: How register service with command line arguments


I'm a little confused.

What do you mean exactly when you say "register service"?

Do you want to register a .NET DLL (that can be exposed to COM) into the Windows Registry?

Do you want to "register" the software against some sort of database or web service/website?

What tool are you attempting to "register" your service with?
Is it your own tool that you've developed?

-Frinny
Plater's Avatar
E
M
C
 
Join Date: Apr 2007
Location: New England
Posts: 7,492
#5: Dec 4 '09

re: How register service with command line arguments


You have to register your service with the service control manager SCM(services.exe) in windows.
For .NET services, this is done with:
Expand|Select|Wrap|Line Numbers
  1. //INSTALL COMMAND
  2. // C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /i <path and filename of service>
  3. //UN-INSTALL COMMAND
  4. // C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil /u <path and filename of service>
  5.  
(or similar depending on your .NET package I suppose)

I however have not seen anything in InstallUtil, nor the System.ServiceProcess.ServiceProcessInstaller or System.ServiceProcess.ServiceInstaller classes that allow for parameters.

http://msdn.microsoft.com/en-us/libr...e.onstart.aspx
Process initialization arguments for the service in the OnStart method, not in the Main method. The arguments in the args parameter array can be set manually in the properties window for the service in the Services console. The arguments entered in the console are not saved; they are passed to the service on a one-time basis when the service is started from the control panel. Arguments that must be present when the service is automatically started can be placed in the ImagePath string value for the service's registry key (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servi ces\<service name>). You can obtain the arguments from the registry using the GetCommandLineArgs method, for example: string[] imagePathArgs = Environment.GetCommandLineArgs();.

From what I have read, the default servicetype does not allow parameters(my service has the parameters box grayed out in the services.msc settings)
This talks about a FileHandlingWinService type:
http://support.microsoft.com/?kbid=829483
Reply