Click here to Skip to main content
12,757,627 members (36,952 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 Gholam332.8K

1 solution

Rate this: bad
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:[^], but I think that dedicated registry key in HKLM is cleaner.
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 + "\"";
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.170217.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2017
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