hao_2468

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

          闲话不说,直接上代码:

using System.ServiceProcess;//这个必须要添加的,windows服务的方法都是在这个里面

             ServiceController sc = new ServiceController(“服务的名称”);//

                    if (sc.Status == ServiceControllerStatus.Running)
                    {
                       sc.Stop();

                    }
                    if (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        sc.Start();

                    }

     就这么多的代码,很简单。

另外还可以得到服务器中所有的windows服务的方法:

ServiceController[] services = ServiceController.GetServices();//先得到所有的服务
            if (services.Length > 0)
            {
                foreach (ServiceController item in services)
                {  //这个里面怎么操作就看你自己的了。

                }
             }

本文链接地址:http://www.coo3.com/archives/181.html 转载请保留

posted on 2011-04-17 22:46  hao_2468  阅读(501)  评论(0编辑  收藏  举报