乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      delphi編程啟動服務(wù)停止服務(wù)新建服務(wù)的方法

       和諧世界 2023-07-22 發(fā)布于福建

      本文主要講解了如何使用delphi新建服務(wù),停止系統(tǒng)服務(wù),以及獲取服務(wù)狀態(tài)和新建系統(tǒng)服務(wù)器的方法,以下是關(guān)鍵代碼

      unit Servicescontrol;
         
      interface  
        uses Windows,Messages,SysUtils,Winsvc,Dialogs;
         
        function  StartServices(Const  SvrName:String):Boolean;
        function  StopServices(Const  SvrName:String):Boolean;
        function  QueryServiceStatu(Const SvrName:   String):String;
        function  CreateServices(Const SvrName,FilePath:String):Boolean;  
        function  DeleteServices(Const SvrName: String):Boolean;  
         
        implementation  

         
        //開啟服務(wù)  
        function StartServices(Const   SvrName:   String):   Boolean;
        var  
            a,b:SC_HANDLE;  
              c:PChar;  
        begin  
              Result:=False;  
         
              a:=OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);  
         
              if a <=0 then  Exit;  
         
              b:=OpenService(a,PChar(SvrName),SERVICE_ALL_ACCESS);  
         
              if b <=0  then  Exit;  
                  try  
                    Result:=StartService(b,0,c);  
                    CloseServiceHandle(b);  
                    CloseServiceHandle(a);  
              except  
                    CloseServiceHandle(b);  
                    CloseServiceHandle(a);  
                    Exit;  
              end;  
        end;  
         
         
        //停止服務(wù)  
        function   StopServices(Const   SvrName:   String):   Boolean;
        var
              a,b:   SC_HANDLE;  
              d:   TServiceStatus;  
        begin  
              Result := False;  
         
              a :=OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);  
         
              if a <=0 then Exit;  
         
              b:=OpenService(a,PChar(SvrName),SERVICE_ALL_ACCESS);  
         
              if b <=0  then  Exit;  
                  try  
                    Result:=ControlService(b,SERVICE_CONTROL_STOP,d);  
                     CloseServiceHandle(a);  
                    CloseServiceHandle(b);  
              except  
                    CloseServiceHandle(a);  
                    CloseServiceHandle(b);  
                    Exit;  
              end;  
        end;  
         
         
        //查詢當(dāng)前服務(wù)的狀態(tài)  
        function  QueryServiceStatu(Const   SvrName:   String):   String;  
        var  
              a,b:   SC_HANDLE;  
              d:   TServiceStatus;  
        begin  
              Result := '未安裝';  
         
              a := OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);  
         
              if a <=0 then  Exit;  
         
              b := OpenService(a,PChar(SvrName),SERVICE_ALL_ACCESS);  
         
              if  b  <= 0  then  Exit;  
                  try  
                    QueryServiceStatus(b,d);  
                           if   d.dwCurrentState     =   SERVICE_RUNNING   then            
                          Result   :=   '啟動'       //Run  
                    else   if   d.dwCurrentState     =   SERVICE_RUNNING   then  
                          Result   :=   'Wait'       //Runing  
                    else   if   d.dwCurrentState     =   SERVICE_START_PENDING then  
                          Result   :=   'Wait'       //Pause  
                    else   if   d.dwCurrentState     =   SERVICE_STOP_PENDING     then  
                          Result   :=   '停止'       //Pause  
                    else   if   d.dwCurrentState     =   SERVICE_PAUSED   then  
                          Result   :=   '暫停'       //Pause  
                    else   if   d.dwCurrentState     =   SERVICE_STOPPED   then  
                          Result   :=   '停止'     //Stop  
                    else   if   d.dwCurrentState     =   SERVICE_CONTINUE_PENDING     then  
                          Result   :=   'Wait'       //Pause  
                    else   if   d.dwCurrentState     =   SERVICE_PAUSE_PENDING   then  
                          Result   :=   'Wait';       //Pause  
         
                    CloseServiceHandle(a);  
                    CloseServiceHandle(b);  
              except  
                    CloseServiceHandle(a);  
                    CloseServiceHandle(b);  
                    Exit;  
              end;  
        end;  
         
         
        {建立服務(wù)}  
        function  CreateServices(Const SvrName,FilePath:   String):   Boolean;  
        var  
              a,b:SC_HANDLE;  
        begin  
              Result:=False;  
                  if  FilePath   =''   then   Exit;  
         
              a   :=   OpenSCManager(nil,nil,SC_MANAGER_CREATE_SERVICE);  
         
              if   a   <=   0   then   Exit;  
              try  
                    b   :=   CreateService(a,PChar(SvrName),  
                     PChar(SvrName),  
                     SERVICE_ALL_ACCESS,  
                     SERVICE_INTERACTIVE_PROCESS   or   SERVICE_WIN32_OWN_PROCESS,  
                     SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,  
                     PChar(FilePath),nil,nil,nil,nil,nil);  
                        if   b   <=   0   then   begin  
                          ShowMessage(   SysErrorMessage(   GetlastError   ));  
                          Exit;  
                    end;  
                        CloseServiceHandle(a);  
                    CloseServiceHandle(b);  
                     
                    Result   :=   True;  
              except  
                    CloseServiceHandle(a);  
                    CloseServiceHandle(b);  
                    Exit;  
              end;  
        end;  
         
         
        {卸載服務(wù)}  
        function   DeleteServices(Const   SvrName:   String):   Boolean;  
        var  
              a,b:SC_HANDLE;  
        begin  
              Result:=False;  
                  a := OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);  
                  if a <= 0 then  Exit;  
                  b :=OpenService(a,PChar(SvrName),STANDARD_RIGHTS_REQUIRED);  
                  if b <= 0 then Exit;  
                  try  
                    Result := DeleteService(b);  
         
                    if not Result then  
                          ShowMessage(SysErrorMessage(GetlastError));  
                     CloseServiceHandle(b);  
                    CloseServiceHandle(a);  
                  except  
                    CloseServiceHandle(b);  
                    CloseServiceHandle(a);  
                    Exit;  
              end;  
        end;  
        end.

      調(diào)用方法:

         {啟動服務(wù)}
             StartServices(服務(wù)名);
         {停止服務(wù)}
             StopServices(服務(wù)名);
         {新建服務(wù)}
             CreateServices(服務(wù)名,exe文件路徑);
         {刪除服務(wù)}
               DeleteServices(服務(wù)名);
         {獲取服務(wù)狀態(tài)}
               string:=QueryServiceStatu(服務(wù)名);

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多