【问题标题】:Set windows service account in config在配置中设置 Windows 服务帐户
【发布时间】:2013-03-18 09:13:03
【问题描述】:

我需要在配置文件中为 Windows 服务设置 serviceaccount。但我无法访问安装程序中的配置值。我阅读了this 问题,但我不想使用安装参数。有没有办法做到这一点?

编辑: 我也尝试了some solutions in this,但我无法访问安装程序类中的 Configuration 或 ConfigurationManager ......我应该添加一些参考吗?

【问题讨论】:

    标签: c# configuration windows-services service-accounts service-installer


    【解决方案1】:

    经过大量研究,我找到了自己的解决方案……

    首先添加对 System.Configuration 的引用

    然后在安装程序类中添加如下代码

    Assembly service = Assembly.GetAssembly(typeof(ProjectInstaller));
    string assemblyPath = service.Location;
    Configuration config = ConfigurationManager.OpenExeConfiguration(assemblyPath);
    KeyValueConfigurationCollection mySettings = config.AppSettings.Settings;
    processInstaller.Account = (ServiceAccount)Enum.Parse(typeof(ServiceAccount), mySettings["Account"].Value);
    

    我现在很开心!! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      • 2015-11-14
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多