Click here to Skip to main content
12,248,681 members (57,114 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 23-May-12 9:33am
Mehdi Gholam305.7K

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100