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

來源:互聯網
上載者:User

標籤:blog   http   ar   color   sp   on   art   log   bs   

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

Windows服務之啟動、停止、暫停、繼續
2011-11-09 15:07:37    我來說兩句 
收藏   我要投稿   [字型:小大]

 

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);

           }

 

     }

 

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

 

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.