I want to install a windows service programmatically by the example.
Here is the code snippet.
private static AssemblyInstaller GetInstaller()
{
AssemblyInstaller installer = new AssemblyInstaller(
typeof(YourServiceType).Assembly, null);
installer.UseNewContext = true;
return installer;
}
I don't know what is the "YourServiceType" here. The syntax of AssemblyInstaller Constructor in MSDN is
public AssemblyInstaller(
Assembly assembly,
string[] commandLine
)
UPDATE:
The wild thing is that I can't start the service if running the command "MyApplication.exe -install" under the folder bin\debug. However if in debug mode, which I put the argument in "Start Options" of the project property. It is okay. Why? I did following the steps at example. I set the "StartType" as "Automatic".