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?
Open the service with OpenService
, and then disable it by passing Service_Disabled
as the dwStartType
parameter for ChangeServiceConfig
. Specify a null pointer or Service_No_Change
for the rest of the parameters since you're not interested in changing them.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With