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启动服务的更多相关文章

  1. 使用instsrv.exe+srvany.exe将应用程序安装为windows服务[转]

      转自:http://qingmu.blog.51cto.com/4571483/1248649 一.什么是instsrv.exe和srvany.exe instsrv.exe.exe和srvany ...

  2. 用instsrv.exe+srvany.exe将应用程序安装为windows服务

    下载 链接:https://pan.baidu.com/s/1gKu_WwVo-TeWXmrGAr9qjw 提取码:s1vm 用instsrv.exe安装srvany.exe 将instsrv.exe ...

  3. exe文件添加为服务

    首先,去下载一个叫rktools.exe的工具(我提供个下载地址Windows 2003 Resource Kits),下载完后安装该资源包,里面有个instsrv.exe和srvany.exe的工具 ...

  4. 利用instsrv和srvany来手动安装服务

    Windows提供了两个小工具instsrv.exe和srvany.exe来把任何应用包装成windows服务.顾名思义instsrv(install service)是用来安装服务的,而srvany ...

  5. 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 ...

  6. 在64位windows下使用instsrv.exe和srvany.exe创建windows服务[转]

    本文转自:https://www.iflym.com/index.php/computer-use/201205020001.html 在32位的windows下,包括windows7,windows ...

  7. 在64位windows下使用instsrv.exe和srvany.exe创建windows服务

    在64位windows下使用instsrv.exe和srvany.exe创建windows服务   在32位的windows下,包括windows7,windows xp以及windows 2003, ...

  8. 【转】在64位windows下使用instsrv.exe和srvany.exe创建windows服务

    本文转自:https://www.iflym.com/index.php/computer-use/201205020001.html 在32位的windows下,包括windows7,windows ...

  9. Instsrv.exe和Srvany.exe的使用方法

    要把应用程序添加为服务,你需要两个小软件:Instsrv.exe和Srvany.exe.Instsrv.exe可以给系统安装和删除服务,Srvany.exe可以让程序以服务的方式运行.这两个软件都包含 ...

随机推荐

  1. Knockout开发中文API系列4–绑定关键字

    目的 Visible绑定通过绑定一个值来确定DOM元素显示或隐藏 示例 <div data-bind="visible: shouldShowMessage"> You ...

  2. SQL SERVER 事务和锁

    内容皆整理自网络 一.事务 作者:郭无心链接:https://www.zhihu.com/question/31346392/answer/59815366来源:知乎著作权归作者所有.商业转载请联系作 ...

  3. oozie java api提交作业

    今晚试验用java的api来提交代码,由于代码是在我机器上写的,然后提交到我的虚拟机集群当中去,所以中间产生了一个错误..要想在任意一台机器上向oozie提交作业的话,需要对hadoop的core-s ...

  4. 【C】——信号量 互斥锁 条件变量的区别

    信号量用在多线程多任务同步的,一个线程完成了某一个动作就通过信号量告诉别的线程,别的线程再进行某些动作(大家都在semtake的时候,就阻塞在哪里).而互斥锁是用在多线程多任务互斥的,一个线程占用了某 ...

  5. WPF ICommandSource Implementations Leak Memory!

    Actually the title of this article should be entitled "How to use WeakEventManager with IComman ...

  6. 通配符的匹配很全面, 但无法找到元素 'context:property-placeholder'

    解决方案就是如下: xmlns:context="http://www.springframework.org/schema/context" 同时在xsi:schemaLocat ...

  7. 手机web——自适应网页设计(html/css控制)http://mobile.51cto.com/ahot-409516.htm

    http://mobile.51cto.com/ahot-409516.htm 一. 允许网页宽度自动调整: "自适应网页设计"到底是怎么做到的? 其实并不难. 首先,在网页代码的 ...

  8. Python WSGI开发随笔

    本文记录学习WSGI时的一些知识点,值得后续学习中注意. wsgi应用接口只要是一个可调用的对象就行,这个可调用的对象需要: 1. 接受两个位置参数: a. 包含CGI形式变量的字典: b. 应用调用 ...

  9. 【翻译自mos文章】Linux的/var/log/messages是空的(0k),messages.0, messages.1也是空的

    Linux的/var/log/messages是空的(0k),messages.0, messages.1也是空的 来源于: The /var/log/messages is empty, and s ...

  10. application/json 与 application/x-www-form-urlencoded的简单比较

    application/x-www-form-urlencoded 提交请求示例 curl -X POST 'http://localhost:8080/formPost' -d 'id=1& ...