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 无密码登录 发表 ...
随机推荐
- filezilla修改默认21端口
一.filezilla修改端口21 1.修改ftp端口号,例如我们想把21修改成888 2.修改数据端口号为N-1,即888-1=887 3.防火墙中开启端口888和887 完成一个FTP的传输过程不 ...
- MySQL查看当前运行的事务和执行的账户
-- 查看当前运行的事务,这点在变更表结构之前必须要查看select * from information_schema.innodb_trx; -- 查看当前运行的事务的账户和事务开始的时间,及其事 ...
- C#学习笔记(26)——委托计算器
说明(2017-11-20 15:14:18): 1. 委托一直稀里糊涂的,有人说简单,有人说难,艹你们! 2. 其实主要是因为,平时不用委托也能解决大部分问题,所以都没有特意去用,网上也没有什么很好 ...
- vue-router "path" is required in a route configuration
启用了动态路由,一直提示这个错误,页面打开也是空白,后来发现原来是component参数错误. 正确的写法为: component: () => import ('@/views/own-spa ...
- 在SQL Server中创建用户角色及授权
参考文献 http://database.51cto.com/art/201009/224075.htm 正文 要想成功访问 SQL Server 数据库中的数据, 我们需要两个方面的授权: 获得准许 ...
- C语言 · 数组输出
算法提高 数组输出 时间限制:1.0s 内存限制:512.0MB 输入一个3行4列的数组,找出该数组中绝对值最大的元素.输出该元素及其两个下标值.如有多个输出行号最小的,还有多个的话 ...
- Android View.MeasureSpec
有时,Android系统控件无法满足我们的需求,因此有必要自定义View. 一般来说,自定义控件都会去重写View的onMeasure方法,因为该方法指定该控件在屏幕上的大小,[protected v ...
- android 开发第三库
http://blog.daimajia.com/android-library-collection/ http://www.apkbus.com/android-180062-1-1.html h ...
- win10无法访问局域网共享文件?解决如此简单。。。。。
1 笔记本系统win10 X64企业版,其中一文件夹已设置为“共享”.本地帐号登录系统. 2 平板电脑系统win8.1 X64专业版,可以顺畅的访问笔记本的共享文件.微软帐号登录系统. 3 平板电脑系 ...
- Microsoft.AspNet.Identity.EntityFramework/IdentityDbContext.cs
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; ...