ServiceType in AssemblyInstaller

谁说我不能喝 提交于 2019-12-11 12:56:13

问题


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".


回答1:


YourServiceType is the type name of your Windows service. If you've followed my directions from scratch, then you originally created your service using the template provided by Visual Studio. By default, this gives you a service class named something like Service1. If you have not changed the name of your class, use Service1. Otherwise, use the name you changed it to.

private static AssemblyInstaller GetInstaller()
{
    AssemblyInstaller installer = new AssemblyInstaller(
        typeof(Service1).Assembly, null);
    installer.UseNewContext = true;
    return installer;
}


来源:https://stackoverflow.com/questions/21912515/servicetype-in-assemblyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!