Page 1 of 1

Services Xbase++

Posted: Mon Jan 02, 2023 4:27 am
by MIGUELON
Hi everyone and happy new year
My question is: can I stop a windows service and start it again from Xbase++
I want to stop the Advantage engine.
Greetings and thanks for your attention
Miguel

Re: Services Xbase++

Posted: Mon Jan 02, 2023 4:51 am
by Tom
Hi, Miguel.

Happy new year!

Xbase++ provides the ServiceController-class, which, for instance, lists all running services with "? ServiceController():QueryAllServiceNames()". It should be able to control any service by using ":AddController()" and methods like ":Start()" or ":Stop()" afterwards, if the :AddController()-method gets all needed parameters and user data.

Re: Services Xbase++

Posted: Mon Jan 02, 2023 5:22 am
by MIGUELON
Ooooo. Thank you very much Tom you made my whole day :) :D

Re: Services Xbase++

Posted: Mon Jan 02, 2023 5:25 am
by Tom
Add:

After you added a ServiceController:

Code: Select all

oCtrl := ServiceController()
oCtrl:AddController("Advantage",<cPathToAdvantage>,...)
you can check the status of the service:

Code: Select all

? oCtrl:GetUpdatedControl("Advantage"):currentState
And you can find out what you can do with the service:

Code: Select all

? oCtrl:GetUpdatedControl("Advantage"):controlsAccepted
The answer should be at least {"SERVICE_ACCEPT_STOP", "SERVICE_ACCEPT_SHUTDOWN"}. If so, you may stop the service from inside your app, and "SERVICE_ACCEPT_START" should be available afterwards.

Re: Services Xbase++

Posted: Mon Jan 02, 2023 7:31 am
by MIGUELON
CLASS Logger
EXPORTED:
INLINE METHOD write( cMsg )
? cMsg
RETURN SELF
ENDCLASS

PROCEDURE ServiciosControl( cParam )
LOCAL cLocation, oLog, oCtrl, cServiceName
oLog:=Logger():new()
oCtrl := ServiceController()
oCtrl:AddController("Advantage",CurDrive()+":\"+CurDir()+"\Program Files\Advantage 10.10\Server\ads.exe","Administrador","ParaXXXion27",oLog)
mensaje(oCtrl:GetUpdatedControl("Advantage"):controlsAccepted,100)
mensaje({1,oCtrl:pause("Advantage")},100)
mensaje({2,oCtrl:stop("Advantage")},100)
mensaje({3,oCtrl:uninstall("Advantage")},100)

Hi Tom I can't get the service to stop.
As you say oCtrl:GetUpdatedControl("Advantage"):controlsAccepted
it returns "SERVICE_ACCEPT_STOP", "SERVICE_ACCEPT_SHUTDOWN"
But it does not listen to :stop() or :Pause() as you see in the code that I sent you.
Is there something I do wrong?
Thank you

Re: Services Xbase++

Posted: Tue Jan 03, 2023 12:10 am
by Tom
Hi, Miguel.

I can't see an error and I get the same results here. Seems like the service doesn't stop although it should. Maybe a case for the Alaska support.

Re: Services Xbase++

Posted: Tue Jan 03, 2023 2:24 am
by MIGUELON
Anyway thank you very much for your help TOM
I will use net stop and net start