0判断服务状态 using System.ServiceProcess; // ServiceController sc; try { sc = new ServiceController(SERVICE_NAME); } catch(ArgumentException) { return "Invalid service name."; // Note that just because a name is valid does not mea
using System; using System.Security.Principal; using System.ServiceProcess; using System.Windows.Forms; namespace windowsServiceCTRL { public static class ServicesHelper { /// <summary> /// 判断是否安装了某个服务 /// </s
.NET Framework中提供的类库可以很方便的实现对windows服务的安装、卸载、启动、停止、获取运行状态等功能。这些类都在System.ServiceProcess命名空间下。 所以,在开始编写程序之前,需要先引用System.ServiceProcess。 获取Windows服务列表: // 获取服务列表 ServiceController[] s
我有以下方法来启动和停止服务.我从另一个Console应用程序调用此方法进行调试,因为我已经使用了类库(DLL)中的方法. 该应用程序以管理权限启动. public void ServiceStart() { ServiceController service = new ServiceController(); service.ServiceName = "ASP.NET Stat
Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的。所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Windows Service写很深入。 本文介绍了如何用C#创建、安装、启动、监控、卸载简单的Windows Service 的内
vs 服务做成安装包,如何安装以后启动服务,只要在类名为projectinstaller的类中重写commit事件即可 public override void Commit(IDictionary savedState) { base.Commit(savedState); ServiceContr