How to register .Net service with command line parameters +?

I would like to be able to pass parameters in a service installation . I changed the C # class code that inherits from Installer ... My problem is that InstallUtil.exe does not work with parameters (well, as I know).

Any suggestion?

+4
source share
4 answers

We have the same scenario and it works. You must pass the parameters as follows

InstallUtil.exe /Param1="Value" /Param2="Value" "Path to your exe" 

Then you must override the installation method in 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; } 
+9
source

This can actually be done using InstallUtil.exe, the .NET installation utility that ships with the .NET Framework.

Take a look at this CodeProject article.

+2
source

Try NSIS . This is a scripting language created for installations that allows you to do all kinds of complex things. Personally, I would use it for any installation that goes beyond the scope of "Next, Next, Next." Very smooth and not all that hard to learn.

0
source

Build and install using Visual Studio or something like Wix . In Visual Studio, you can do Custom Action and pass parameters to the CustomActionData field.

0
source

Source: https://habr.com/ru/post/1286096/


All Articles