<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 4, 2016 at 5:41 PM, Richard Mace <span dir="ltr"><<a href="mailto:richard.mace@gmail.com" target="_blank">richard.mace@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">What's the best way of shutting down a service that is a service, having the same effect as the user clicking stop. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Basically, I want my service to monitor a condition, which if met, it will stop itself.
</blockquote><div><br></div><div>XMLRAD stop a program registered as a service running following code,<br></div><div><br>var<br>  SCMHandle, SvcHandle: THandle;<br>  Status: TServiceStatus;<br>begin<br>  Result := False;<br>  SCMHandle := 0;<br>  try<br>      SCMHandle := OpenSCManagerA(nil, nil, SC_MANAGER_CREATE_SERVICE);<br>      if SCMHandle = 0 then<br>      begin<br>        SystemLogLastError('OpenSCManager');<br>        Exit;<br>      end;<br>      SvcHandle := OpenServiceA(SCMHandle, PChar('MyService'), SERVICE_ALL_ACCESS);<br>      if SvcHandle = 0 then<br>      begin<br>        SystemLogLastError('OpenService');<br>        Exit;<br>      end;<br>      if not ControlService(SvcHandle, SERVICE_CONTROL_STOP, Status) then<br>      begin<br>        SystemLog(tlError, 'Error to ControlService STOP');<br>        Exit;<br>      end;<br>      CloseServiceHandle(SvcHandle);<br>  finally<br>    if SCMHandle <> 0 then<br>      CloseServiceHandle(SCMHandle);<br>  end;<br><br></div></div></div></div>