Click here to Skip to main content
Rate this: bad
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 Gholam250.3K

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 at 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 at 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
0 OriginalGriff 470
1 Maciej Los 345
2 Richard MacCutchan 230
3 Mathew Soji 220
4 BillWoodruff 180
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986

Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2014
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