0

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

编辑: 我也尝试了一些解决方案,但我无法在安装程序类中访问 Configuration 或 ConfigurationManager ......我应该添加一些参考吗?

4

1 回答 1

0

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

首先添加对 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);

我现在很开心!!:)

于 2013-03-18T11:04:14.993 回答