On Thu, Feb 4, 2016 at 5:41 PM, Richard Mace <richard.m...@gmail.com> wrote:
> What's the best way of shutting down a service that is a service, having > the same effect as the user clicking stop. Basically, I want my service to monitor a condition, which if met, it will > stop itself. XMLRAD stop a program registered as a service running following code, var SCMHandle, SvcHandle: THandle; Status: TServiceStatus; begin Result := False; SCMHandle := 0; try SCMHandle := OpenSCManagerA(nil, nil, SC_MANAGER_CREATE_SERVICE); if SCMHandle = 0 then begin SystemLogLastError('OpenSCManager'); Exit; end; SvcHandle := OpenServiceA(SCMHandle, PChar('MyService'), SERVICE_ALL_ACCESS); if SvcHandle = 0 then begin SystemLogLastError('OpenService'); Exit; end; if not ControlService(SvcHandle, SERVICE_CONTROL_STOP, Status) then begin SystemLog(tlError, 'Error to ControlService STOP'); Exit; end; CloseServiceHandle(SvcHandle); finally if SCMHandle <> 0 then CloseServiceHandle(SCMHandle); end;
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus