I am using InstallUtil to install my service and I just cannot figure out how to specify the startup parameters for it!
Here is my Installer subclass:
I know this is an old post but thought I'd post my response. I did this in a .net 4 service using the BeforeInstall event.
The ServiceProcessInstaller's BeforeInstall event:
private void serviceProcessInstaller1_BeforeInstall(object sender, InstallEventArgs e)
{
System.ServiceProcess.ServiceProcessInstaller installer = sender as System.ServiceProcess.ServiceProcessInstaller;
if (installer != null)
{
//Get the existing assembly path parameter
StringBuilder sbPathWIthParams = new StringBuilder(installer.Context.Parameters["assemblypath"]);
//Wrap the existing path in quotes if it isn't already
if (!sbPathWIthParams[0].Equals("\""))
{
sbPathWIthParams.Insert(0, "\"");
sbPathWIthParams.Append("\"");
}
//Add desired parameters
sbPathWIthParams.Append(" test");
//Set the new path
installer.Context.Parameters["assemblypath"] = sbPathWIthParams.ToString();
}
}
The installed service looks as follows:
It executes fine, and I can examine the parameters from within the main function of the service.