gpt4 book ai didi

c# - AssemblyInstaller 中的服务类型

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:25 26 4
gpt4 key购买 nike

我想通过 example. 以编程方式安装 Windows 服务

这是代码片段。

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

我不知道这里的“YourServiceType”是什么。 MSDN 中 AssemblyInstaller Constructor 的语法是

public AssemblyInstaller(
Assembly assembly,
string[] commandLine
)

更新:

疯狂的是,如果在文件夹 bin\debug 下运行命令“MyApplication.exe -install”,我无法启动该服务。但是,如果在 Debug模式下,我将参数放在项目属性的“启动选项”中。没关系。为什么?我确实按照 example. 中的步骤操作 我将“StartType”设置为“自动”。

最佳答案

YourServiceType 是您的 Windows 服务的类型名称。如果您是按照我的指示从头开始,那么您最初是使用 Visual Studio 提供的模板创建服务的。默认情况下,这会为您提供一个名为 Service1 的服务类。如果您没有更改类的名称,请使用 Service1。否则,请使用您将其更改为的名称。

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

关于c# - AssemblyInstaller 中的服务类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21912515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com