instsrv.exe srvany.exe启动服务
1.通过注册表注册服务
private static readonly string regpath = @"SYSTEM\CurrentControlSet\Services\ConsulClient\Parameters"; /// <summary>
/// 通过注册表注册Consul Agent服务
/// </summary>
/// <param name="consulPath">exe所在文件夹</param>
/// <param name="consulExeLocal">consul.exe,exe物理路径</param>
private static void ConsulClientRegEdit(string consulPath, string consulExeLocal)
{
try
{
LogWriter.ToInfo("[ConsulClientRegEdit]配置注册表开始"); List<Tuple<string, string, RegistryValueKind>> list = new List<Tuple<string, string, RegistryValueKind>>();
list.Add(new Tuple<string, string, RegistryValueKind>("AppParameters", "agent -config-file conf", RegistryValueKind.String));
list.Add(new Tuple<string, string, RegistryValueKind>("Application", consulExeLocal, RegistryValueKind.String));
list.Add(new Tuple<string, string, RegistryValueKind>("AppDirectory", consulPath, RegistryValueKind.String));
WinRegistryHelper.Register(Registry.LocalMachine, regpath, list);
LogWriter.ToInfo("[ConsulClientRegEdit]配置注册表完成");
}
catch (Exception ex)
{
LogWriter.ToError("[ConsulClientRegEdit]注册表操作失败", ex);
throw new Exception("[ConsulClientRegEdit]注册表操作失败,请联系管理员!");
}
} public class WinRegistryHelper
{
public static void Register(RegistryKey root, string subkey, List<Tuple<string, string, RegistryValueKind>> list)
{
DeleteRegist(root, subkey);
RegistryKey aimdir = Registry.LocalMachine.CreateSubKey(subkey);
if (aimdir == null)
throw new Exception("注册表操作失败");
foreach (var item in list)
{
aimdir.SetValue(item.Item1, item.Item2, item.Item3);
}
}
/// <summary>
/// 删除注册表中指定的注册表项
/// </summary>
/// <param name="name"></param>
public static void DeleteRegist(RegistryKey root, string subkey)
{
RegistryKey myKey = Registry.LocalMachine.OpenSubKey(subkey);
if (myKey != null)
root.DeleteSubKeyTree(subkey);
}
}
2.instsrv.exe srvany.exe启动服务
string consulExeLocal = DefautToolsRelyHelper.Consul + "\\consul.exe";
string srvanyPath = DefautToolsRelyHelper.Srvany + @"\srvany\srvany.exe";
string instsrvPath = DefautToolsRelyHelper.Srvany + @"\srvany\instsrv.exe";
CheckRelyTools(consulExeLocal, srvanyPath, instsrvPath);
//exe程序注册到注册表中的服务中
ConsulClientRegEdit(DefautToolsRelyHelper.Consul, consulExeLocal);
ConsulClientWinServerRigister(srvanyPath, instsrvPath); /// <summary>
/// 启动服务
/// </summary>
/// <param name="srvanyPath">srvany.exe物理路径</param>
/// <param name="instsrvPath">instsrv.exe物理路径</param>
private static void ConsulClientWinServerRigister(string srvanyPath, string instsrvPath)
{
LogWriter.ToInfo("[ConsulClientWinServerRigister]使用 srvany注册服务开始"); ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.FileName = "\"" + instsrvPath + "\"";
psInfo.Arguments = consulServiceName + " " + "\"" + srvanyPath + "\""; //设置启动动作,确保以管理员身份运行
psInfo.Verb = "runas";
Process.Start(psInfo);
LogWriter.ToInfo("[ConsulClientWinServerRigister]使用 srvany注册服务完成");
}
instsrv.exe srvany.exe启动服务的更多相关文章
- 使用instsrv.exe+srvany.exe将应用程序安装为windows服务[转]
转自:http://qingmu.blog.51cto.com/4571483/1248649 一.什么是instsrv.exe和srvany.exe instsrv.exe.exe和srvany ...
- 用instsrv.exe+srvany.exe将应用程序安装为windows服务
下载 链接:https://pan.baidu.com/s/1gKu_WwVo-TeWXmrGAr9qjw 提取码:s1vm 用instsrv.exe安装srvany.exe 将instsrv.exe ...
- exe文件添加为服务
首先,去下载一个叫rktools.exe的工具(我提供个下载地址Windows 2003 Resource Kits),下载完后安装该资源包,里面有个instsrv.exe和srvany.exe的工具 ...
- 利用instsrv和srvany来手动安装服务
Windows提供了两个小工具instsrv.exe和srvany.exe来把任何应用包装成windows服务.顾名思义instsrv(install service)是用来安装服务的,而srvany ...
- Go Node.js 生成的exe公布成windows服务
环境变量 GOBIN E:\01_SOFT\go1.9.2\bin GOROOT E:\01_SOFT\go1.9.2 GOPATH(下载包的存放位置:go get github.com/gin-go ...
- 在64位windows下使用instsrv.exe和srvany.exe创建windows服务[转]
本文转自:https://www.iflym.com/index.php/computer-use/201205020001.html 在32位的windows下,包括windows7,windows ...
- 在64位windows下使用instsrv.exe和srvany.exe创建windows服务
在64位windows下使用instsrv.exe和srvany.exe创建windows服务 在32位的windows下,包括windows7,windows xp以及windows 2003, ...
- 【转】在64位windows下使用instsrv.exe和srvany.exe创建windows服务
本文转自:https://www.iflym.com/index.php/computer-use/201205020001.html 在32位的windows下,包括windows7,windows ...
- Instsrv.exe和Srvany.exe的使用方法
要把应用程序添加为服务,你需要两个小软件:Instsrv.exe和Srvany.exe.Instsrv.exe可以给系统安装和删除服务,Srvany.exe可以让程序以服务的方式运行.这两个软件都包含 ...
随机推荐
- java IO【转】
Java 流在处理上分为字符流和字节流.字符流处理的单元为 2 个字节的 Unicode 字符,分别操作字符.字符数组或字符串,而字节流处理单元为 1 个字节,操作字节和字节数组. Java 内用 U ...
- javascript 获取当前部署项目路径
javascript 获取当前部署项目路径 ========================================= javascript获取当前部署项目路径: 主要用到Location 对 ...
- 1<<30 hashMap 中使用位移运算的意义
static final int MAXIMUM_CAPACITY = 1 << 30; 计算过程已1<<30为例,首先把1转为二进制数字 0000 0000 0000 000 ...
- WEB打印(jsp版)
<%@ page contentType="text/html; charset=UTF-8" language="java"%> <%@in ...
- e864. 取的显示器大小尺寸
See also e670 缓冲图像转换为图像. try { Robot robot = new Robot(); // Capture a particular area on the screen ...
- (转)OpenGL ES编程入门资源集合
出自:http://blog.csdn.net/u013467442/article/details/44498125 OpenGL ES 2.0中文手册:http://www.dreami ...
- memcached -- 运行memcached
Memcached 运行 Memcached命令的运行: $ /usr/local/memcached/bin/memcached -h 注意:如果使用自动安装, memcached 命令位于 /us ...
- 下载android源码
http://source.android.com Step 1.按照http://source.android.com/source/initializing.html配置好android编译环境 ...
- Winform控件学习笔记【第五天】——ListView
[第五天] 常用的基本属性: FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. GridLines:设置行和列之间是否显示网格线.( ...
- html固定宽度下拉框内容显示不全问题解决方法
不少时候在页面中为了布局的需要,下拉列表<select>的宽度需要设成比较小的值,这时如果恰巧它包含的选择项<option>的内容比较长,那么超出select宽度的部分将会被截 ...