0

I pass the service name into the argument list, but when I look in the installers context it is not there:

args = new[] { Assembly.GetExecutingAssembly().Location, "/ServiceName=WinService1" };
ManagedInstallerClass.InstallHelper(args);

Why are key value pairs not pass into the installers context?

public override void Install(IDictionary stateSaver)
{
    foreach (var param in Context.Parameters)
    {
       // ServiceName is not available in the Parameters collection
    } 
}
Rookian
  • 19,841
  • 28
  • 110
  • 180

2 Answers2

5

This is quite old thread, but maybe someone still could use the answer like I could have if it was here earlier :). Only parameters before location are being passed into the context for the installer. Try this:

args = new[] { "/ServiceName=WinService1", Assembly.GetExecutingAssembly().Location };
ManagedInstallerClass.InstallHelper(args);
PrzemekP
  • 51
  • 1
  • 2
  • This gives me `System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\path\to\exe\ --params' or one of its dependencies. The system cannot find the file specified.` (note, doesn't actually pass the exe's name, only the folder it's in) – gregmac Aug 29 '16 at 18:51
0

Try this code:

IDictionary dictionary = new Dictionary<string, IEnumerable<string>>();
dictionary.Add(Assembly.GetExecutingAssembly().Location, 
               new string [] {"/ServiceName=WinService1"});
ManagedInstallerClass.InstallHelper(dictionary);
oleksii
  • 35,458
  • 16
  • 93
  • 163
  • ManagedInstallerClass.InstallHelper needs an array of strings. – Rookian May 30 '11 at 15:45
  • @Rookian from your code it takes IDictionary, but see my update if that will help. Sorry if it is totally wrong direction – oleksii May 30 '11 at 15:47
  • @oleksii, cannot convert from 'System.Collections.IDictionary' to 'string[]' –  Mar 26 '14 at 15:03