C#实现windows服务安装,服务名可配置时出问题(无法创建 ProjectInstaller 安装程序类型的实例)
【参考资料】Windows 安装服务 的两种方式
一、问题出在System.Configuration.ConfigurationManager.AppSettings[""].ToString()无法读取 config文件配置
二、ProjectInstaller.Designer.cs源码
using System.Xml; namespace ServiceHost
{
partial class ProjectInstaller
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller()
{
Description = "Description ",
DisplayName = Get_ConfigValue(this.GetType().Assembly.Location + ".config", "JobDisplayName"),//System.Configuration.ConfigurationManager.AppSettings["JobDisplayName"].ToString(),
ServiceName = Get_ConfigValue(this.GetType().Assembly.Location + ".config", "JobServiceName"),//System.Configuration.ConfigurationManager.AppSettings["JobServiceName"].ToString(),
StartType = System.ServiceProcess.ServiceStartMode.Automatic
};
this.serviceInstaller2 = new System.ServiceProcess.ServiceInstaller()
{
Description = "Description ",
DisplayName = Get_ConfigValue(this.GetType().Assembly.Location + ".config", "InterfaceDisplayName"), //System.Configuration.ConfigurationManager.AppSettings["InterfaceDisplayName"].ToString(),
ServiceName = Get_ConfigValue(this.GetType().Assembly.Location + ".config", "InterfaceServiceName"),//System.Configuration.ConfigurationManager.AppSettings["InterfaceServiceName"].ToString(),
StartType = System.ServiceProcess.ServiceStartMode.Automatic
};
//
// serviceProcessInstaller1
//
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null; //
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1,
this.serviceInstaller2}); } #endregion private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller2; protected static string Get_ConfigValue(
style="color: #0000ff;">string configpath, string strKeyName)
{
using (XmlTextReader tr = new XmlTextReader(configpath))
{
while (tr.Read())
{
if (tr.NodeType == XmlNodeType.Element)
{
if (tr.Name == "add" && tr.GetAttribute("key") == strKeyName)
{
return tr.GetAttribute("value");
}
}
}
}
return "";
}
} }
C#实现windows服务安装,服务名可配置时出问题(无法创建 ProjectInstaller 安装程序类型的实例)的更多相关文章
- 解决:Windows安装Composer及全局配置时提示部分.dll结尾的php扩展文件找不到指定的模板
当安装Composer或者全局配置时出现.dll扩展文件找不到指定模板,如下图: 解决办法: 打开php.ini,将extension_dir 改为绝对路径即可 例如:
- CentOS7安装CDH 第四章:CDH的版本选择和安装方式
相关文章链接 CentOS7安装CDH 第一章:CentOS7系统安装 CentOS7安装CDH 第二章:CentOS7各个软件安装和启动 CentOS7安装CDH 第三章:CDH中的问题和解决方法 ...
- Ubuntu下软件安装方式、PATH配置、查找安装位置
Ubuntu 18.04, 安装方式 目前孤知道的Ubuntu下安装软件方式有3种(命令): 1.make 2.apt/apt-get 3.dpkg 方式1基于软件源码安装,需要经历配置(可选).编译 ...
- MAVEN(一) 安装和环境变量配置
一.安装步骤 1.安装maven之前先安装jdk,并配置好环境变量.确保已安装JDK,并 “JAVA_HOME” 变量已加入到 Windows 环境变量. 2.下载maven 进入官方网站下载网址如下 ...
- jdk11下载安装及环境变量配置
jdk11下载安装及环境变量配置 官网地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-50666 ...
- Java中jdk安装与环境变量配置
Java中jdk安装与环境变量配置 提示:下面是jdk1.7和jdk1.8的百度网盘链接 链接:https://pan.baidu.com/s/1SuHf4KlwpiG1zrf1LLAERQ 提取码: ...
- Android Studio安装及主题字体配置
在2013 Google I/O 大会上,谷歌推出了自家全新的安卓软件集成开发工具 Android Studio,这是 Google 基于 IntelliJ IDEA 改动而来. 谷歌称 Androi ...
- Vbox安装CentOS7及网络配置
安装CentOS7及网络配置 Vbox和其他虚拟机一样,安装完成一个虚拟机,需要配置网络才能实现物理主机和虚拟机之间的访问.虚拟主机和Internet(外网)的访问 1.设置Vbox全局网络 单击主界 ...
- Ubuntu 安装 SSH server 并配置 SSH 无密码登录
https://hinine.com/install-and-configure-ssh-server-on-ubuntu/ Ubuntu 安装 SSH server 并配置 SSH 无密码登录 发表 ...
随机推荐
- Mac下使用su命令提示sorry
Mac下使用su命令提示sorry,解决办法如下: ➜ Downloads su Password: su: Sorry 谷歌之,两个解决方式: sudo su - # 输入开始第一个创建用户的密码 ...
- maven profile 多环境
<profiles> <profile> <!-- 本地开发环境 --> <id>dev</id> <properties> & ...
- 【转】提交http请求之python与curl
提交http请求之python与curl 由于Openstack是python实现wsgi的REST ful架构,在学习和调试的过程中,常常会遇到http请求的提交,于是顺手整理下python和cur ...
- Jenkins自动化构建python nose测试
[本文出自天外归云的博客园] 简介 通过Jenkins自动化构建python nose测试分两步: 1. 创建节点(节点就是执行自动化测试的机器): 2. 创建任务并绑定节点(用指定的机器来跑我们创建 ...
- css3 data-attribute属性打造漂亮的按钮
之前介绍了几款css3实现的按钮,今天为网友来款比较新鲜的,用css3的data-attribute属性开发按钮,当鼠标经过显示按钮的详细信息.而且实现过程很简单,几行代码就搞定.大家试一试吧.如下图 ...
- Oracle 重启数据库实例
看你当前有多少个已经启动的实例: ps -ef|grep smon ORA-27101 Shared memory realm does not existORA-01034 ORACLE not a ...
- 常用Git命令清单(转)
文/阮一峰 我每天使用 Git ,但是很多命令记不住. 一般来说,日常使用只要记住下图 6 个命令,就可以了.但是熟练使用,恐怕要记住 60-100 个命令. 下面是我整理的常用 Git 命令清单.几 ...
- 编辑距离算法(Levenshtein)
编辑距离定义: 编辑距离,又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的最少编辑操作次数. 许可的编辑操作包括:将一个字符替换成另一个字符,插入一个字符,删除一个字符. 例如 ...
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
在使用selenium处理中文网页或者网页标题是中文的时候,出现UnicodeEncodeError: 'ascii' codec can't encode characters in positio ...
- 如何修改被hosts.deny禁止访问的IP
自己的密码忘记了,重试了很多次被加入了黑名单. 如果仅仅清空 /etc/hosts.deny 文件内容,你会发现过一会自己的IP又进入里面了. 其实系统后台会定期自动扫描一些文件,然后将这些异常的IP ...