Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-12

Win services

18 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Antonio Fortuny

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

Reply by email

Michael Van Canneyt
to Antonio Fortuny
Antonio Fortuny wrote 14 lines
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.

Reply by email

Antonio Fortuny
to Michael Van Canneyt

Le 11/12/2013 14:38, Michael Van Canneyt a ?crit :

Show quoted text 20 lines
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

Show quoted text 10 lines
> 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:

Show quoted text 11 lines
Which fails if you do not refresh the list of services. Michael. -- _______________________________________________ Lazarus mailing list 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

Reply by email

Michael Van Canneyt
to Antonio Fortuny
Antonio Fortuny wrote 26 lines
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 don't know what that means.

Maybe you don't have permission to get a file handle on this service.

I use this component succesfully since many years in commercial code. I would be very surprised to find out that it is an error in the code. (but it is not excluded)

Michael.

Reply by email

Reinier Olislagers
to Michael Van Canneyt
Michael Van Canneyt wrote 22 lines
On Wed, 11 Dec 2013, Antonio Fortuny wrote: > > Le 11/12/2013 14:38, Michael Van Canneyt a ?crit : >> >> >> On Wed, 11 Dec 2013, Antonio Fortuny wrote: >>> 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 don't know what that means. Maybe you don't have permission to get a file handle on this service.

Regarding permissions: random guess: do you need a manifest file with proper elevation? Have you set that in project options? (Don't know if Vista actually requires this & you mentioned you were already running as admin, but who knows)

Reply by email

Antonio Fortuny
to Antonio Fortuny: Hi Folks. I'am in trouble when attempting to stop a Windows service using the…

Sorry all, it is my fault.
In fact, when I use the commande
net start servicenape
servicenape stands for the display name and it works every day. This time I tried:
sc stop my_service
with the same name and I receive a Windows error telling me that service has not been started, but I'm pretty sure it is (that's what services.msc tells me)
Until, making a typing error I typed
sc stop _service
which did work !!!!
In fact, what sc and the TServiceCompoent expect as the service name to be is the NAME property of the item in the DataModule of the daemon mapper (_service in this case) and not its display name. That's it.
Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) could be adapted to be more precise.
Now my program works fine with the services manager. I guess it will much easier to manage all this in Linux.

Thanks anyway.

Antonio.

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

Reply by email

Reinier Olislagers
to Antonio Fortuny
Antonio Fortuny wrote
Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) could be adapted to be more precise.

Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!)

<rant>All well and good that only a select few persons ever take the trouble to ever write documentation in whatever form - be it text, fpdoc or wiki, these ridiculous "maybe somebody else should update the documentation" remarks after getting a lot of help are just... ridiculous.</rant>

Reply by email

Antonio Fortuny
to Reinier Olislagers

Le 11/12/2013 16:23, Reinier Olislagers a ?crit :

Show quoted text 11 lines
On 11/12/2013 16:17, Antonio Fortuny wrote: > Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) could be > adapted to be more precise. Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!) <rant>All well and good that only a select few persons ever take the trouble to ever write documentation in whatever form - be it text, fpdoc or wiki, these ridiculous "maybe somebody else should update the documentation" remarks after getting a lot of help are just... ridiculous.</rant>

I'd be glad to post some comments into the wiki page if you could take some time to explain to me how to proceed. This only takes time once. I guess that someone should read tha changes before they are published. In a more general way I'd also be glad to help maintaining Lazarus & FPC as far as I get the "how to proceed" from some of you. Visiting another page could be helpfull as well.

Antonio.

Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/91e95b4d/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: ggaejbci.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/91e95b4d/attachment.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: eaffacdb.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/91e95b4d/attachment-0001.jpg>

Reply by email

Reinier Olislagers
to Antonio Fortuny
Antonio Fortuny wrote
Le 11/12/2013 16:23, Reinier Olislagers a ?crit : > On 11/12/2013 16:17, Antonio Fortuny wrote: some time to explain to me how to proceed.

Are you serious? Basically log in, hit "edit" and away you go.

Reply by email

Antonio Fortuny
to Reinier Olislagers: Are you serious? Basically log in, hit "edit" and away you go.

Le 11/12/2013 16:33, Reinier Olislagers a ?crit :

Show quoted text 5 lines
On 11/12/2013 16:31, Antonio Fortuny wrote: > Le 11/12/2013 16:23, Reinier Olislagers a ?crit : >> On 11/12/2013 16:17, Antonio Fortuny wrote: > some time to explain to me how to proceed. Are you serious?

Always

Basically log in, hit "edit" and away you go.

Got it

Show quoted text 8 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Sita Software *Antonio Fortuny* Senior Software engineer 220, avenue de la Libert? L-4602 Niederkorn Tel.: +352 58 00 93 - 93 www.sitasoftware.lu <http://www.sitasoftware.lu> Your IT Partner --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/e33761da/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: jcfcigji.jpg Type: image/jpeg Size: 2306 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/e33761da/attachment-0002.jpg> -------------- next part -------------- A non-text attachment was scrubbed... Name: jaehhdhc.jpg Type: image/jpeg Size: 921 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/e33761da/attachment-0003.jpg>

Reply by email

Frederic Da Vitoria
to Reinier Olislagers: I'd suggest you just write what you know. If there are errors, they're easily corrected.…

2013/12/11 Reinier Olislagers

Show quoted text 9 lines
On 11/12/2013 16:31, Antonio Fortuny wrote: > > Le 11/12/2013 16:23, Reinier Olislagers a ?crit : >> On 11/12/2013 16:17, Antonio Fortuny wrote: > I guess that someone should read tha changes before they are published. I'd suggest you just write what you know. If there are errors, they're easily corrected. That's the idea of a wiki.

For my information, are there some users who check the wiki modifications globally, or should unsure users post here when they edit the wiki?

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131211/24ec223b/attachment.html>

Reply by email

Reinier Olislagers
to Frederic Da Vitoria
Frederic Da Vitoria wrote 17 lines
2013/12/11 Reinier Olislagers < <mailto:>> On 11/12/2013 16:31, Antonio Fortuny wrote: > > Le 11/12/2013 16:23, Reinier Olislagers a ?crit : >> On 11/12/2013 16:17, Antonio Fortuny wrote: > I guess that someone should read tha changes before they are published. I'd suggest you just write what you know. If there are errors, they're easily corrected. That's the idea of a wiki. For my information, are there some users who check the wiki modifications globally, or should unsure users post here when they edit the wiki?

If you're unsure, you can always mark it in the text you're adding. If you're really unsure, you can edit the Talk page of a page and add your suggested changes etc.

Reply by email

Antonio Fortuny
to Reinier Olislagers: Are you serious? Basically log in, hit "edit" and away you go.

Le 11/12/2013 16:33, Reinier Olislagers a ?crit :

Show quoted text 5 lines
On 11/12/2013 16:31, Antonio Fortuny wrote: > Le 11/12/2013 16:23, Reinier Olislagers a ?crit : >> On 11/12/2013 16:17, Antonio Fortuny wrote: > some time to explain to me how to proceed. Are you serious?

Yep. I didn't have a login name, now I've one and edit works. It's gonna be late for today, I'll insert a comment tomorrow about this topic involving the service name.
Looks not too complicated. I think I could manage to make some changes

Antonio

Show quoted text 10 lines
Basically log in, hit "edit" and away you go. -- _______________________________________________ Lazarus mailing list 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

Reply by email

Antonio Fortuny
to Reinier Olislagers: Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!) <rant>All well and good that…

Le 11/12/2013 16:23, Reinier Olislagers a ?crit :

Show quoted text 10 lines
On 11/12/2013 16:17, Antonio Fortuny wrote: > Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) could be > adapted to be more precise. Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!) <rant>All well and good that only a select few persons ever take the trouble to ever write documentation in whatever form - be it text, fpdoc or wiki, these ridiculous "maybe somebody else should update the documentation" remarks after getting a lot of help are just... ridiculous.</rant>

Just done

Antonio.

Show quoted text 8 lines
-- _______________________________________________ Lazarus mailing list 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

Reply by email

Reinier Olislagers
to Antonio Fortuny
Antonio Fortuny wrote 14 lines
Le 11/12/2013 16:23, Reinier Olislagers a ?crit : > On 11/12/2013 16:17, Antonio Fortuny wrote: >> Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) could be >> adapted to be more precise. > Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!) > > <rant>All well and good that only a select few persons ever take the > trouble to ever write documentation in whatever form - be it text, fpdoc > or wiki, these ridiculous "maybe somebody else should update the > documentation" remarks after getting a lot of help are just... > ridiculous.</rant> Just done Antonio.

Thanks a lot, Antonio, I really appreciate it!

Reply by email

Martin Frb
to Reinier Olislagers

todays report, both entry have an msisdn that failed in the past too. So expected to fail

Reinier Olislagers wrote 23 lines
On 12/12/2013 09:28, Antonio Fortuny wrote: > Le 11/12/2013 16:23, Reinier Olislagers a ?crit : >> On 11/12/2013 16:17, Antonio Fortuny wrote: >>> Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) could be >>> adapted to be more precise. >> Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!) >> >> <rant>All well and good that only a select few persons ever take the >> trouble to ever write documentation in whatever form - be it text, fpdoc >> or wiki, these ridiculous "maybe somebody else should update the >> documentation" remarks after getting a lot of help are just... >> ridiculous.</rant> > Just done > > Antonio. Thanks a lot, Antonio, I really appreciate it! -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Martin Frb
to Martin Frb

Sorry, ignore, sent to wrong address.

Martin Frb wrote 30 lines
todays report, both entry have an msisdn that failed in the past too. So expected to fail On 12/12/2013 11:10, Reinier Olislagers wrote: > On 12/12/2013 09:28, Antonio Fortuny wrote: >> Le 11/12/2013 16:23, Reinier Olislagers a ?crit : >>> On 11/12/2013 16:17, Antonio Fortuny wrote: >>>> Maybe the wiki page (http://wiki.freepascal.org/ServiceManager) >>>> could be >>>> adapted to be more precise. >>> Looking forward to *your* updates. (hint, HINT, *HINT*!!!!!) >>> >>> <rant>All well and good that only a select few persons ever take the >>> trouble to ever write documentation in whatever form - be it text, >>> fpdoc >>> or wiki, these ridiculous "maybe somebody else should update the >>> documentation" remarks after getting a lot of help are just... >>> ridiculous.</rant> >> Just done >> >> Antonio. > Thanks a lot, Antonio, I really appreciate it! > > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email