相关疑难解决方法(0)

如何从app.config获取Windows服务名称

我有一个app.config

  <appSettings>
    <add key="ServiceName" value="HasService"/>
    <add key="ServiceDisplayName" value="HasService"/>
  </appSettings>
Run Code Online (Sandbox Code Playgroud)

我的服务安装程序类

 [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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我想从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?
    }
Run Code Online (Sandbox Code Playgroud)

如何从MyServiceInstaller类中的app.config文件获取服务名称和服务显示名称.

c# windows-services

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

windows-services ×1