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 无密码登录 发表 ...
随机推荐
- Zabbix之Python脚本端口自动发现
Zabbix监控服务端口,可以手动添加配置,但是如果一个服务器上需要监控的端口数较多,那么利用Zabbix自动发现,比较高效,下面是自动发现port的Python脚本. #!/usr/bin/pyth ...
- [转]Tomcat启动报错:AnnotationConfigBeanDefinitionParser are only available on JDK 1.5 and higher
原文地址:https://blog.csdn.net/daochuwenziyao/article/details/54949151 问题描述: 控制台输出AnnotationConfigBeanDe ...
- MongoDB阅读精要
部署:MongoDB服务端可运行在Linux.Windows或IOS平台,支持32位和64位应用,默认端口为27017.推荐运行在64位平台,因为MongoDB在32位模式运行时支持的最大文件尺寸为2 ...
- IDEA使用教程-踩得坑
最近来公司才换的IDEA,而且是mac版本的,踩了好多坑,所以想记录下来. 1. 创建Web聚合项目(Maven多模块项目) 参考多模块项目创建 2. IDEA热部署(jetty插件启动maven项目 ...
- [转]Nginx的负载均衡方式
如果Nginx没有仅仅只能代理一台服务器的话,那它也不可能像今天这么火,Nginx可以配置代理多台服务器,当一台服务器宕机之后,仍能保持系统可用.具体配置过程如下: 1. 在http节点下,添加ups ...
- hbase 学习(十五)缓存机制以及可以利用SSD作为存储的BucketCache
下面介绍Hbase的缓存机制: a.HBase在读取时,会以Block为单位进行cache,用来提升读的性能 b.Block可以分类为DataBlock(默认大小64K,存储KV).BloomBloc ...
- 【驱动】——错误: 初始值设定项里有未知的字段‘ioctl’
这个错误网上搜索发现3.0.0.15版本内核 file_operation结构体已经删除了ioctl函数,取代的是: long (*unlocked_ioctl) (struct file *, un ...
- WebRTC 源码分析(二):安卓预览
有过一定相机开发经验的朋友可能会疑惑,预览还有什么好分析的,不是直接 camera.setPreviewDisplay 或者 camera.setPreviewTexture 就能在 SurfaceV ...
- label文字居中
height: height,//"20px" "line-height": height, autosize:true, &qu ...
- android调用系统的自定义裁剪后得到的图片不清晰,使用MediaStore.EXTRA_OUTPUT获取缓存下的清晰图片
在使用系统自带的剪切图片工具时,通常只能设置一些比较小的值,像 intent.putExtra("outputX", 320); intent.putExtra("out ...