Click here to Skip to main content
14,928,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When installing a windows service with ManagedInstallerClass and Installer how can you set the start-up command line arguments to the service?

i.e. Path to executable = "c:\service.exe -p param1 -q param2"
Posted

1 solution

A service is ran by the service host, started by the service manager. There are no arguments. You have to store these parameters somewhere (registry for example) during installation, or using a standalone configuration application - and read them in the service.

Update: I have done some research, and it seems, that you can pass arguments, as you intend. See this: http://www.c-sharpcorner.com/UploadFile/ankithakur/Passing_parameters_to_Windows_Services10062006000204AM/Passing_parameters_to_Windows_Services.aspx[^], but I think that dedicated registry key in HKLM is cleaner.
   
v3
Comments
Mehdi Gholam 24-May-12 3:44am
   
Found this that works :
protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
{
Context.Parameters["assemblypath"] = "\"" + this.GetType().Assembly.Location + "\" -p " + Program.Port + " -f \"" + Program.Path + "\"";
base.OnBeforeInstall(savedState);
}
Mehdi Gholam 24-May-12 3:47am
   
5'ed thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900