I am trying to install a windows service without using the installutil. An understandable and straightforward way to do this which I found is to use:
ManagedInstallerClass.InstallHelper
So I end up with the following Program.cs:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
if (args.Length >0)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "--install":
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
break;
case "--uninstall":
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new PicknikService()
};
ServiceBase.Run(ServicesToRun);
}
}
}
After I Build the service and execute MyService.exe --install I get the following:
Cannot start service from the command line or debugger. A winwows Service must first be installed(using installutil.exe) and then started with the ServerExplorer, Windows Services Afministrative tool or the NET START command.
Any thoughts?