[Lazarus] Win services

Michael Van Canneyt michael at freepascal.org
Wed Dec 11 14:38:53 CET 2013



On Wed, 11 Dec 2013, Antonio Fortuny wrote:

> Hi Folks.
>
> I'am in trouble when attempting to stop a Windows service using the 
> TServiceManager component.
> The program runs into a Vista-32 box,
> the Lazarus IDE runs in an administrator user console: it has been started as 
> d:...\Lazarus my_project.lpi
> When I run the program and do a step by step execution all looks good until 
> the StopService line is reachad:
> The service name should be the display name, right ?
>
>  SMgr := TServiceManager.Create(nil);
>  try
>    SMgr.Access := SC_MANAGER_ALL_ACCESS;

You should set refreshonconnect:=true (or something similar).

>    SMgr.Connect;

Or call refresh here.

Refresh will re-fetch the list of services from the windows service manager.
It needs this list for the next call:

> *SMgr.StopService(SERVICE_NAME, False); *// there are no dependants

Which fails if you do not refresh the list of services.

Michael.




More information about the Lazarus mailing list