I would like to be able to pass parameters in the installation of the service. I have modified the C# code of the class that inherit from Installer... My problem is the InstallUtil.exe doesn't work with parameters (well not as I know).
Any suggestion?
Answers. You can add command line arguments to the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[YourService]\ImagePath registry entry. These will get picked up by the Main() method in your service application. From there you can parse them and pass them to your service via properties, custom constructors, etc.
Click the Start button in the Windows taskbar. In the menu, right-click Command Prompt. On the pop-up right click context menu, select Run as administrator. At the command prompt, enter the SC Config command with the service name to be modified and the parameters to be changed.
We have the same scenario and it works. You've to pass the parameters as follows
InstallUtil.exe /Param1="Value" /Param2="Value" "Path to your exe"
Then you've to override Install method on your installer
public override void Install(System.Collections.IDictionary stateSaver)
{
var lParam1 = GetParam("Param1");
}
private string GetParam(string pKey)
{
try
{
if (this.Context != null)
{
if (this.Context.Parameters != null)
{
string lParamValue = this.Context.Parameters[pKey];
if (lParamValue != null)
return lParamValue;
}
}
}
catch (Exception)
{
}
return string.Empty;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With