Windows服务名称我有一个的app.config如何从app.config中
<appSettings>
<add key="ServiceName" value="HasService"/>
<add key="ServiceDisplayName" value="HasService"/>
</appSettings>
我的服务安装程序类
[RunInstaller(true)]
public class MyServiceInstaller : System.Configuration.Install.Installer
{
public MyServiceInstaller()
{
var process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem};
var serviceAdmin = new ServiceInstaller
{
StartType = ServiceStartMode.Manual,
ServiceName = "HasService",
DisplayName = "HasService"
};
Installers.Add(process);
Installers.Add(serviceAdmin);
}
}
我想从app.config中获得服务名称。
var serviceAdmin = new ServiceInstaller
{
StartType = ServiceStartMode.Manual,
ServiceName = GetServiceNameAppConfig("ServiceName"),
DisplayName = GetServiceNameAppConfig("ServiceDisplayName")
};
public string GetServiceNameAppConfig(string serviceName)
{
//what should i write here?
}
如何从MyServiceInstaller类的app.config文件中获取服务名称和服务显示名称。
你为什么要这么做?我可以看到把“有可能改变某一天的东西”放到配置文件中的争论,但是你会认真地将服务的名称放在这个类别中吗?您也可以根据需要更改配置文件,但除非您重新安装该服务(即除非MsServiceInstaller完成其任务),否则实际上不会更改服务名称。这可能会让人不知所措。 – PeteH
@Pete我想用两个不同的名字来运行服务。 – sinanakyazici
@sinanakyazici它为我工作!非常感谢 –