Click here to Skip to main content
Sign Up to vote bad
good
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 - 8:33


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.
  Permalink  
Comments
Mehdi Gholam - 24 May '12 - 3:44
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:47
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 415
1 Arun Vasu 399
2 Sergey Alexandrovich Kryukov 368
3 Tadit Dash 198
4 Maciej Los 191
0 Sergey Alexandrovich Kryukov 9,955
1 OriginalGriff 7,589
2 CPallini 4,028
3 Rohan Leuva 3,422
4 Maciej Los 2,949


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid