日期:2014-05-20  浏览次数:20780 次

如何使用C#编写的服务程序管理其他系统服务?
如何在C#编写的服务程序中管理(启动、暂停、停止)其他系统服务?这是我写的程序:
  protected   override   void   OnStart(string[]   args)
                {
                        Thread   Th   =   new   Thread(this.Running);
                        Th.Start();

                }


                private   void   Running()
                {
                      sc=new   System.ServiceProcess.ServiceController( "W3SVC ");
                      while   (true)
                      {
                              try
                              {
                                      TcpClient   tc   =   new   TcpClient();
                                      tc.Connect( "localhost ",   80);
                                      tc.Close();
                                      tc   =   null;
                              }
                              catch
                              {
                                      string   scStatus   =   sc.Status.ToString();
                                      switch   (scStatus.ToUpper())
                                      {
                                              case   "PAUSED ":
                                                      sc.Continue();
                                                      break;
                                              case   "STOPPED ":