程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> Windows服務之啟動、停止、暫停、繼續

Windows服務之啟動、停止、暫停、繼續

編輯:關於C語言

 

SC_HANDLE   scm,sHandle;

   SERVICE_STATUS   ServiceStatus;

    scm=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);

    if   (scm!=NULL)

      {

//啟動service

        sHandle=OpenService(scm, "GwbnService",SERVICE_START);

        if(sHandle!=NULL)

          {

            StartService(sHandle,0,NULL))//開始Service

          }  

//停止Service

          sHandle=OpenService(scm, "GwbnService",SERVICE_STOP|SERVICE_QUERY_STATUS);

          if(sHandle!=NULL)

              QueryServiceStatus(sHandle,&ServiceStatus);

          if(ServiceStatus.dwCurrentState   ==   SERVICE_RUNNING   ||   ServiceStatus.dwCurrentState   ==   SERVICE_PAUSED)

            {

              ControlService(sHandle,SERVICE_CONTROL_STOP,&ServiceStatus);

            }

//暫停Service

          sHandle=OpenService(scm, "GwbnService",SERVICE_PAUSE_CONTINUE|SERVICE_QUERY_STATUS);

          if(sHandle!=NULL)

          QueryServiceStatus(sHandle,&ServiceStatus);

          if(ServiceStatus.dwCurrentState   ==   SERVICE_RUNNING)

            {

              ControlService(sHandle,SERVICE_CONTROL_PAUSE,&ServiceStatus);

            }

//繼續Service

          sHandle=OpenService(scm, "GwbnService",SERVICE_PAUSE_CONTINUE|SERVICE_QUERY_STATUS);

          if(sHandle!=NULL)

          QueryServiceStatus(sHandle,&ServiceStatus);

          if(ServiceStatus.dwCurrentState   ==   SERVICE_PAUSED)

            {

              ControlService(sHandle,SERVICE_CONTROL_CONTINUE,&ServiceStatus);

            }

 

      }

 

注意:服務有服務名稱和顯示名稱之分,這裡需要的是服務名稱

 

 

摘自:Awey_001的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved