C#:安装Windows服务,动态指定服务名及描述
Installer.cs>>
public Installer(){InitializeComponent();/* 服务未注册前,System.Configuration.ConfigurationManager.AppSettings读取无效。//serviceInstaller1.ServiceName = "ChinaHN.XHService." + System.Configuration.ConfigurationManager.AppSettings["Service_ID"];//serviceInstaller1.DisplayName = System.Configuration.ConfigurationManager.AppSettings["Service_DisplayName"];//serviceInstaller1.Description = System.Configuration.ConfigurationManager.AppSettings["Service_Description"]; *//* 指定该服务的启动模式:自动,手动,禁用serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.;*/using (SettingHelper setting = new SettingHelper()){//系统用于标志此服务名称(唯一性)serviceInstaller1.ServiceName = setting.ServiceName;//向用户标志服务的显示名称(可以重复)serviceInstaller1.DisplayName = setting.DisplayName;//服务的说明(描述)serviceInstaller1.Description = setting.Description;} }
配置类:SettingHelper.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text;using System; using System.IO; using System.Xml;//------------------------------------- // 描述:初始化服务配置帮助类 // 作者:fooo // 完成时间:2013-12-16 //------------------------------------- namespace XHService {public class SettingHelper : IDisposable {#region 私有成员private string _ServiceName;private string _DisplayName;private string _Description;#endregion#region 构造函数/// <summary> /// 初始化服务配置帮助类 /// </summary> public SettingHelper(){InitSettings();}#endregion#region 属性/// <summary> /// 系统用于标志此服务的名称 /// </summary> public string ServiceName{get { return _ServiceName; }}/// <summary> /// 向用户标志服务的友好名称 /// </summary> public string DisplayName{get { return _DisplayName; }}/// <summary> /// 服务的说明 /// </summary> public string Description{get { return _Description; }}#endregion#region 私有方法#region 初始化服务配置信息/// <summary> /// 初始化服务配置信息 /// </summary> private void InitSettings(){ string root = System.Reflection.Assembly.GetExecutingAssembly().Location;string xmlfile = root.Remove(root.LastIndexOf('\\') + 1) + "XHService.exe.config";if (File.Exists(xmlfile)){//系统用于标志此服务名称(唯一性)_ServiceName = "XHService." + Get_ConfigValue(xmlfile , "Service_ID");//向用户标志服务的显示名称(可以重复)_DisplayName = Get_ConfigValue(xmlfile, "Service_DisplayName");//服务的说明(描述)_Description = Get_ConfigValue(xmlfile, "Service_Description");}else{throw new FileNotFoundException("未能找到服务名称配置文件 ChinaHN.XHService.exe.config!路径:" + xmlfile);}}/// <summary>/// 读取 XML中指定节点值/// </summary>/// <param name="configpath">配置文件路径</param>/// <param name="strKeyName">键值</param> /// <returns></returns>protected static string Get_ConfigValue(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 "";}#endregion#endregion#region IDisposable 成员private bool disposed = false;public void Dispose(){Dispose(true);GC.SuppressFinalize(this);}protected virtual void Dispose(bool disposing){if (!this.disposed){if (disposing){//managed dispose _ServiceName = null;_DisplayName = null;_Description = null;}//unmanaged dispose }disposed = true;}~SettingHelper(){Dispose(false);}#endregion } }
C#:安装Windows服务,动态指定服务名及描述相关推荐
- 利用PHP安装windows自动运行的服务,PHP程序可以实现长时间、自动运行、定时更新功能,直接可以用在项目中的类源代码...
为什么80%的码农都做不了架构师?>>> 什么 windows服务 ? Windows 服务(即,以前的 NT 服务)使您能够创建在它们自己的 Windows 会话中可长时间运 ...
- mybatis动态指定表名注意点
须知:${}和#{}区别 ${}为早期使用的,不能防止sql注入. #{}为现在使用的,是可以防止sql注入. 能尽量使用#{}则使用#{},少使用${}. 注意点描述: 我们如果在xml中动态指定表 ...
- Linux服务篇--openssh服务
Linux高级篇–SSH服务 一. SSH ssh: secure shell, protocol, 22/tcp, 安全的远程登录 具体的软件实现: OpenSSH: ssh协议的开源实现,Ce ...
- Spring Cloud微服务之Nacos服务发现(八)
Nacos服务发现 一.什么是Nacos? 二.微服务中常见的注册中心 三.Nacos主要提供以下四大功能: 四.Nacose结构图 5.Nacos下载和安装 1.下载地址和版本 2.启动nacos服 ...
- 通过pxe从网络启动安装Windows XP
搭建Linux系统中的PXE远程安装 Windows XP 和Linux 服务已经有很长时间了,大概折腾了一个多星期 ,Linux系统安装比较简单,已经搞定了.但是Windows XP的安装遇到了太多 ...
- 安装Windows服务时出现试图加载格式不正确的程序或系统找不到指定的文件以及相关问题
安装Windows服务可使用, C:\Windows\Microsoft.NET\Framework64\v4.0.30319>installUtil.exe Microsoft (R) .NE ...
- Windows下当地RabbitMQ服务的安装
Windows下本地RabbitMQ服务的安装 本文参考:刘若泽相关技术文档 当然这些内容页可以通过RabbitMQ官方网站获得. RabbitMQ配置说明手册 一.RaibbitMQ服务器配置 1. ...
- 腾讯云服务器/Windows Server 2012 R2 上搭载web服务 动态图图解(http协议)# 谭子
一.基于Windows Server 2012 r2搭网站/挂网页 在写好网页后,经常想着用链接的形式进行访问(拿手机或者浏览器能直接打开),网上搭建网站的方法很多,这里介绍一种在Windows Se ...
- C# WindowService 动态修改服务名
serviceInstaller1中可以设置服务名,描述等 在实际情况中,我们可能需要将Service多开来达到我们的目的,但是安装两次以上会有错误提示,因为服务名已经重复了,这个时候,我们需要动态改 ...
最新文章
- 全栈AI工程师指南,DIY一个识别手写数字的web应用
- 在终端输入命令打开mac自带的python工具IDLE
- python语言解释器的全部代码都是开源的_Python IDE和解释器的区别是什么?
- 利用git 进行多人协作开发
- 数学之路(2)-数据分析-R基础(2)
- java统计各空气质量最大值_空气质量历史数据分析
- python traceback什么意思_浅谈Python traceback的优雅处理
- mysql数据库入门教程(14):函数
- zookeeper安装包下载地址
- C# DatatTable某一列是否有重复判断
- 华为可以升级鸿蒙的机型,首批升级鸿蒙机型提前泄露,华为这保密措施需要加强...
- Myrrix——基于Mahout的开源推荐系统
- 油猴安装错误问题(下载中断问题)及脚本安装
- oracle找出两张表中不同的数据
- matplotlib之pyplot模块之网格线设置(grid():设置网格线外观)
- 港科夜闻|香港科技大学与越秀集团举行捐赠仪式暨合作框架协议签约仪式,再次捐赠1亿港币...
- Android 在现有项目中引入Compose
- uniapp ios原生插件开发 (framework,cocoapods)
- 记账的目的和好处是什么
- 介绍国内外CMS系统
热门文章
- c语言调用自己编译的头文件,写自己的头文件 ——C语言的多文件编译
- java ssh完整配置文件_ssh框架整合笔记---配置文件
- 无限循环python代码_python - 代码遇到意外的无限循环? - SO中文参考 - www.soinside.com...
- kuboard使用mysql_Kuboard Kubernetes安装
- python3发送邮件_Python3 SMTP发送邮件
- oracle事件号,oracle8管理员账号密码Oracle-等待事件解读
- 安全云盘项目(四)4.1: 云盘原型系统详细设计
- TCL微型计算机如何投屏,TCL电视怎么投屏?3个办法帮助你完美解决
- centos桌面系统怎么退回终端系统_【社群话题分享】Linux 各大发行版你怎么选?...
- acivity 横屏_Activity横竖屏切换时先看到横屏/竖屏再变换回竖屏/横屏