How can I disable a service via Delphi?

后端 未结 5 2000
离开以前
离开以前 2021-01-01 21:43

I use a routine that can start and stop services via Delphi but I also need to be able to disable them, is it possible?

5条回答
  •  我在风中等你
    2021-01-01 22:22

    You can use file JclSvcCtrl.pas from JEDI Components Library (JCL). I have written a pseudo example that you could use. However, be aware that I didn't test it. But in this way it should work (error checks omitted):

    M := TJclSCManager.Create;
    M.Refresh(true);  //Not sure if true is needed or not (refresh all services)
    For i := 0 to M.ServiceCount -1 do
    begin
      S := M.Services[i]; //TJclNtService
      if CompareText(S.ServiceName, 'bla') then
      begin
        S.Stop;
        S.StartType := sstDisabled;   
        S.Commit;
        break;
      end;
    end;
    

提交回复
热议问题