通过asp.net程序来控制自己开发的windows服务
- public ActionResult ListService()
- { //获取已经保存好的windows服务名称
- IList<Model.ReportServicesInfoEnt> List =GetServiceNameList;
- ServiceController serviceObject = null;
- foreach (Model.ReportServicesInfoEnt e in List)
- {
- FileInfo fi= GetWindowsServiceInstallPath(e.ServiceName);
- if (fi != null)
- {
- e.FilePath = fi.FullName;
- serviceObject = GetServiceObject(e.ServiceName);
- if (serviceObject != null)
- {
- e.StatusName = serviceObject.Status.ToString();
- }
- }
- }
- ViewData["Count"] = Count;
- ViewData["ReportServicesInfoEnt"] = List;
- return View();
- }
- #region 服务操作
- /// <summary>
- /// 服务操作
- /// </summary>
- /// <param name="serviceName"></param>
- /// <param name="Type">5表示启动,10表示重启,15表示停止</param>
- /// <returns></returns>
- public ActionResult SetService(string serviceName, int SetType)
- {
- var msg = "";
- switch (SetType)
- {
- case :
- msg = "启动";
- break;
- case :
- msg = "重启";
- break;
- case :
- msg = "停止";
- break;
- }
- var ret = new
- {
- Success = true,
- Message = msg + "完成"
- };
- return Json(ret, JsonRequestBehavior.AllowGet);
- }
- /// <summary>
- /// 获取windows服务实例
- /// </summary>
- /// <param name="ServiceName"></param>
- /// <returns></returns>
- private ServiceController GetServiceObject(string ServiceName)
- {
- return new ServiceController(ServiceName);
- }
- /// <summary>
- /// 获取服务注册表信息
- /// </summary>
- /// <param name="ServiceName"></param>
- /// <returns></returns>
- private FileInfo GetWindowsServiceInstallPath(string ServiceName)
- {
- string key = @"SYSTEM\CurrentControlSet\Services\" + ServiceName;
- if (Registry.LocalMachine.OpenSubKey(key) == null)
- {
- return null;
- }
- else
- {
- string path = Registry.LocalMachine.OpenSubKey(key).GetValue("ImagePath").ToString();
- path = path.Replace("\"", string.Empty);
- FileInfo fi = new System.IO.FileInfo(path);
- return fi;
- }
- }
- /// <summary>
- /// 重启
- /// </summary>
- /// <param name="sc"></param>
- private void ReStarService(ServiceController sc)
- {
- this.StopService(sc);
- this.StarService(sc);
- }
- /// <summary>
- /// 停止服务
- /// </summary>
- /// <param name="sc"></param>
- private void StopService(ServiceController sc)
- {
- if ((sc.Status == ServiceControllerStatus.Paused) || (sc.Status == ServiceControllerStatus.Running))
- {
- sc.Stop();
- }
- }
- /// <summary>
- /// 开始服务
- /// </summary>
- /// <param name="sc"></param>
- private void StarService(ServiceController sc)
- {
- if ((sc.Status == ServiceControllerStatus.Paused) || (sc.Status == ServiceControllerStatus.Stopped))
- {
- sc.Start();
- }
- }
- #endregion
通过asp.net程序来控制自己开发的windows服务的更多相关文章
- C# 开发的windows服务 不能调试——讨论整理
CSDN的标题:C# 开发的windows服务 不能调试 System.Diagnostics.Debugger.Launch();在想加断点的地方加入这行,是进入断点的,可以进行调试,我的是xp系统 ...
- 在ASP.NET Core中使用Apworks开发数据服务:对HAL的支持
HAL,全称为Hypertext Application Language,它是一种简单的数据格式,它能以一种简单.统一的形式,在API中引入超链接特性,使得API的可发现性(discoverable ...
- .net开发windows服务
最近一个月都异常的繁忙,项目进度非常的紧,回头看看自己的blog,整整一个5月都没有一篇文章,非常惭愧,现在补几篇文章,介绍一下我最近关注的技术.这篇文章将介绍Windows服务程序的开发.摘要:本文 ...
- C#开发可以可视化操作的windows服务
使用C#开发自定义windows服务是一件十分简单的事.那么什么时候,我们需要自己开发windows服务呢,就是当我们需要计算机定期或者一 直执行我们开发的某些程序的时候.我经常看到许多人开发的win ...
- 【C#】开发可以可视化操作的windows服务
使用C#开发自定义windows服务是一件十分简单的事.那么什么时候,我们需要自己开发windows服务呢,就是当我们需要计算机定期或者一直执行我们开发的某些程序的时候.这里我以一个WCF的监听服务为 ...
- C#开发人员能够可视化操作windows服务
使用C#开发自己的定义windows服务是一个很简单的事.因此,当.我们需要发展自己windows它的服务.这是当我们需要有定期的计算机或运行某些程序的时候,我们开发.在这里,我有WCF监听案例,因为 ...
- Topshelf 一个简化Windows服务开发的宿主服务框架
Topshelf是 基于.net框架开发的宿主服务框架.该框架简化了服务的创建,开发人员只需要使用 Topshelf编写一个控制台程序,就能安装为Windows服务.之所以这样原因非常简单:调试一个控 ...
- 利用Topshelf把.NET Core Generic Host管理的应用程序部署为Windows服务
背景 2019第一篇文章. 此文源于前公司在迁移项目到.NET Core的过程中,希望使用Generic Host来管理定时任务程序时,没法部署到Windows服务的问题,而且官方也没给出解决方案,只 ...
- C#开发windows服务如何调试——资料整理
原文标题:C# Windows服务程序如何进行调试 原文地址:https://jingyan.baidu.com/article/456c463b18e1b00a583144b3.html 第一种: ...
随机推荐
- Byte measurements
- hdu 5120 Intersection
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...
- 【POJ】【2449】Remmarguts' Date
K短路/A* 经(luo)典(ti) K短路题目= = K短路学习:http://www.cnblogs.com/Hilda/p/3226692.html 流程: 先把所有边逆向,做一遍dijkstr ...
- Java compiler level does not match the version of the instal
一.问题描述 新建了一个项目,workspace默认jdk编译版本是1.7的,新建项目使用的是jdk1.5的版本,肯定会报@override错误.这个时候,修改项目的compilor即可. 这时候,你 ...
- Leetcode#166 Fraction to Recurring Decimal
原题地址 计算循环小数 先把负数转化成正数,然后计算,最后添加符号 当被除数重复出现的时候,说明开始循环了,所以用一个map保存所有遇到的被除数 需要考虑溢出问题,这也是本题最恶心的地方,看看通过率吧 ...
- 数据导出为excel表格
---恢复内容开始--- 方式一: 通过request和response中携带的数据导出表格,导出的结果会将页面中展示的内容全部导出.代码如下: //调出保存框,下载页面所有内容 String fil ...
- mongo 1067错误
对mongo进行错误的操作导致mongo服务异常关闭,当重启mongo服务时出现1067错误此时在data目录下产生mongod.lock文件,可以讲此文件删除,然后重启就可以了 Please mak ...
- Sqli-labs less 34
Less-34 本关是post型的注入漏洞,同样的也是将post过来的内容进行了 ' \ 的处理.由上面的例子可以看到我们的方法就是将过滤函数添加的 \ 给吃掉.而get型的方式我们是以url形式提交 ...
- 使用命令行编译、打包、运行WordCount--不用eclipse
1)首先创建WordCount1023文件夹,然后在此目录下使用编辑器,例如vim编写WordCount源文件,并保存为WordCount.java文件 /** * Licensed under th ...
- linux 上传/下载文件到windows工具
一般来说,linux服务器大多是通过ssh客户端来进行远程的登陆和管理的,使用ssh登陆linux主机以后,如何能够快速的和本地机器进行文件的交互呢,也就是上传和下载文件到服务器和本地: 与ssh ...