Le 11/12/2013 14:38, Michael Van Canneyt a écrit :
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).
Ok Michael, works up to there (SMgr.Refresh works too)
but when doing:
h := SMgr.GetServiceHandle(SERVICE_NAME, SERVICE_ALL_ACCESS);
I get the windows exception 1006 !!?
I do not use the IDE anymore but I launch the program in an
administrator command line window
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
now I get error 1060:
Which fails if you do not refresh the list of services.
Michael.
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce
que la protection avast! Antivirus est active.
http://www.avast.com
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus