How to pass arguments to installutil MyService.exe Parameter1 Parameter2

user2075283 picture user2075283 · Feb 18, 2013 · Viewed 8.7k times · Source

How to pass arguments to installutil MyService.exe Parameter1 Parameter2

I MyService is a windows service. I want to pass the arguments to this service.

Answer

Sumeshk picture Sumeshk · Aug 29, 2013

override the install method of ProjectInstaller class

public override void Install(System.Collections.IDictionary stateSaver)
        {
              base.Install(stateSaver);
              string lParam1 = Convert.ToString(GetParam("Param1"));  

        }

        private object GetParam(string p)
        {
            try
            {
                if (this.Context != null)
                {
                    if (this.Context.Parameters != null)
                    {
                        string lParamValue = this.Context.Parameters[p];
                        if (lParamValue != null)
                            return lParamValue;
                    }
                }
            }
            catch (Exception ex )
            {

            }
            return string.Empty;
        }

and install the service using installutil /Param1=value path_to_your_exename