instsrv.exe srvany.exe启动服务

instsrv.exe srvany.exe启动服务1.通过注册表注册服务privatestaticreadonlystringregpath=@”SYSTEM\CurrentControlSet\Services\ConsulClient\Parameters”;///<summary>///通过注册表注册ConsulAgent服务///</summary>///<p…

大家好,又见面了,我是你们的朋友全栈君。

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注册服务完成");
}

  

转载于:https://www.cnblogs.com/liuqiyun/p/9897455.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/141914.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • FileUpload文件上传控件「建议收藏」

    FileUpload文件上传控件「建议收藏」1.FileUpload控件的主要功能是向指定目录上传文件。FileUpload控件不会自动上传控件,而需要设置相关的事件处理程序,然后在程序中实现文件上传。2.FileUpload控件常见的属性

    2022年7月1日
    28
  • 多线程编程 -wait(),notify()/notityAll()方法

    多线程编程 -wait(),notify()/notityAll()方法

    2021年5月6日
    121
  • 【Windows网络编程】完成端口IOCP介绍(超详细)

    【Windows网络编程】完成端口IOCP介绍(超详细)这篇文档我非常详细并且图文并茂的介绍了关于网络编程模型中完成端口的方方面面的信息,从API的用法到使用的步骤,从完成端口的实现机理到实际使用的注意事项,都有所涉及,并且为了让朋友们更直观的体会完成端口的用法,本文附带了有详尽注释的使用MFC编写的图形界面的示例代码。       我的初衷是希望写一份互联网上能找到的最详尽的关于完成端口的教学文档,而且让对Socket编程略有了解的人都能够

    2022年4月18日
    355
  • nvprof –help

    nvprof –helpUsage:nvprof[options][application][application-arguments]Options:–aggregate-mode&lt;on|off&gt;Turnon/offaggregatemodeforeventsandmetricsspecifiedbysubsequent"–events"and"–…

    2022年5月3日
    45
  • 玩玩webgame开发(4):游戏数据结构设计[通俗易懂]

    玩玩webgame开发(4):游戏数据结构设计[通俗易懂]很久没做更新了。最近比较忙碌,手头的webgame也都放下。最近很想念我的小webgame了,回来继续写。上篇玩玩webgame开发(3):自动战斗实现以及一些游戏细节(下)http://playfish.iteye.com/blog/267275在高峰期时候发表的,结果被火速沉底了。。。汗好了,不小心有说了好多废话,言归正传。=============数据结构设计是门…

    2022年6月2日
    40
  • memset库函数「建议收藏」

    memset库函数「建议收藏」头文件:#include定义函数:void*memset(void*s,intc,size_tn);函数说明:memset()会将参数s所指的内存区域前n个字节以参数c填入,然后

    2022年8月5日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号