[Lazarus] Win services

Antonio Fortuny a.fortuny at sitasoftware.lu
Wed Dec 11 14:17:05 CET 2013


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;
     SMgr.Connect;
*SMgr.StopService(SERVICE_NAME, False); *// there are no dependants
   finally
     SMgr.Free
   end

The pointed line fails with the Windows error exception: *6 invalid 
handle* as if the procedure couldn't catch a valid hendle for the service.
When, in the same admin cosole I type:
net stop *SERVICE_NAME
*the service stopsimmediately without error

Any idea ?

Antonio.

**

---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com






More information about the Lazarus mailing list