Stop a Windows service lazarus / 21-General ---------------------------------------------------------------------- badmintonfan · 2022-11-20 06:39 I try to stop a windows service with the below code,but  Services.StopService('Spooler',false) always release a error message,anyone know what wrong with it Services := TServiceManager.Create(nil);   try       Services.Acces := SC_MANAGER_CONNECT;       Services.Connect;       Services.GetServiceStatus('Spooler', ServiceStatus);       svc_act := (ServiceStatus.dwCurrentState = SERVICE_RUNNING);       if svc_act then       Services.StopService('Spooler',false);       Services.Disconnect;       finally     Services.Free;   end; ---------------------------------------------------------------------- paweld · 2022-11-20 07:09 You must run application with administrative privilages ---------------------------------------------------------------------- Thaddy · 2022-11-20 09:49 Did you examine the example in the standard package fcl-extra? Also, Michael van Canneyt wrote an article about how to handle this: https://www.freepascal.org/~michael/articles/daemons/daemons.pdf that also handles Windows services. It may indeed be that you will need elevated rights on more modern windows and especially win64. You can do that by including an appropriately written manifest, either as a resource or as a separate file. You definitely do not have to run everything as administrator. That is good for debugging but not otherwise. Simply create a proper manifest resource. ---------------------------------------------------------------------- badmintonfan · 2022-11-21 04:02 Quote from: paweld on November 20, 2022, 08:09:30 amYou must run application with administrative privilages Yes,I run it with administrator,and got the same error ---------------------------------------------------------------------- badmintonfan · 2022-11-21 04:10 Quote from: Thaddy on November 20, 2022, 10:49:44 amDid you examine the example in the standard package fcl-extra? Also, Michael van Canneyt wrote an article about how to handle this: https://www.freepascal.org/~michael/articles/daemons/daemons.pdf that also handles Windows services. It may indeed be that you will need elevated rights on more modern windows and especially win64. You can do that by including an appropriately written manifest, either as a resource or as a separate file. You definitely do not have to run everything as administrator. That is good for debugging but not otherwise. Simply create a proper manifest resource. Thanks,I'll study the example ---------------------------------------------------------------------- dbannon · 2022-11-21 07:44 Armin wrote a quite detailed tutorial on Services and Daemons, I suspect his focus was more on Windows. Might be helpful - https://wiki.freepascal.org/Daemons_and_Services There were some examples added to Lazarus's Examples list but probably only visible if you are using main/trunk (where the Examples system has changed). Davo ---------------------------------------------------------------------- superc · 2022-11-21 09:38 Quote from: dbannon on November 21, 2022, 08:44:44 amArmin wrote a quite detailed tutorial on Services and Daemons, I suspect his focus was more on Windows. Might be helpful - https://wiki.freepascal.org/Daemons_and_Services There were some examples added to Lazarus's Examples list but probably only visible if you are using main/trunk (where the Examples system has changed). Davo Wow! really useful and interesting, top !!!