我想通过编程方式安装 Windows 服务example. https://stackoverflow.com/questions/1195478/how-to-make-a-net-windows-service-start-right-after-the-installation/1195621#1195621
这是代码片段。
private static AssemblyInstaller GetInstaller()
{
AssemblyInstaller installer = new AssemblyInstaller(
typeof(YourServiceType).Assembly, null);
installer.UseNewContext = true;
return installer;
}
我不知道这里的“YourServiceType”是什么。 AssemblyInstaller 构造函数的语法MSDN http://msdn.microsoft.com/en-us/library/9ysya0ff%28v=vs.110%29.aspx is
public AssemblyInstaller(
Assembly assembly,
string[] commandLine
)
UPDATE:
疯狂的是,如果在文件夹 bin\debug 下运行命令“MyApplication.exe -install”,我无法启动该服务。
但是,如果在调试模式下,我将参数放在项目属性的“启动选项”中。没关系。为什么?我按照以下步骤进行操作example. https://stackoverflow.com/questions/593454/easiest-language-for-creating-a-windows-service/593803#593803我将“StartType”设置为“自动”。
YourServiceType
是 Windows 服务的类型名称。如果您从头开始遵循我的指示,那么您最初是使用 Visual Studio 提供的模板创建的服务。默认情况下,这会为您提供一个名为类似的服务类Service1
。如果您尚未更改班级名称,请使用Service1
。否则,请使用您更改后的名称。
private static AssemblyInstaller GetInstaller()
{
AssemblyInstaller installer = new AssemblyInstaller(
typeof(Service1).Assembly, null);
installer.UseNewContext = true;
return installer;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)