How to start and pass Arguments to windows service.
-
wrote on 22 Jan 2020, 06:31 last edited by
I have created my own windows service.
How to start and pass arguments to created windows service through Qt application. -
I have created my own windows service.
How to start and pass arguments to created windows service through Qt application.wrote on 22 Jan 2020, 08:39 last edited by@Shankar-B
It seems Qt (beign aimed at platform-independence) does not come with in-built support for interacting with Windows services.I would refer you to https://stackoverflow.com/questions/46484616/how-to-start-stop-windows-service-using-qt (and https://github.com/qtproject/qt-solutions) as a possible starting point. Otherwise you could use
QProcess
to spawnnet start/stop
commands (ugly) or the Win API for native support (https://docs.microsoft.com/en-us/windows/win32/services/service-functions). -
wrote on 22 Jan 2020, 08:40 last edited by
Using the search engine google I found
https://github.com/qtproject/qt-solutions/blob/master/qtservice/examples/controller/main.cpp
Which looks like a good implementation of a service control manager client -
@Shankar-B
It seems Qt (beign aimed at platform-independence) does not come with in-built support for interacting with Windows services.I would refer you to https://stackoverflow.com/questions/46484616/how-to-start-stop-windows-service-using-qt (and https://github.com/qtproject/qt-solutions) as a possible starting point. Otherwise you could use
QProcess
to spawnnet start/stop
commands (ugly) or the Win API for native support (https://docs.microsoft.com/en-us/windows/win32/services/service-functions).wrote on 22 Jan 2020, 09:38 last edited by@JonB
SC.EXE is an Even more powerful command line tool and with it one can also install services. You may want to read this on arguments:
https://serverfault.com/questions/143367/how-to-start-a-service-with-certain-start-parameters-on-windows -
@JonB
SC.EXE is an Even more powerful command line tool and with it one can also install services. You may want to read this on arguments:
https://serverfault.com/questions/143367/how-to-start-a-service-with-certain-start-parameters-on-windows -
@HoMa
I am aware ofSC.EXE
. Having written Windows services and applications which call them, I would always prefer to use an API from code over an OS command, be thatSC
orNET ...
. -
@JonB No doubt! However, the API is not as trivial as starting a process. So if one is not so much interested in the details, the tools might be easier to use.
wrote on 22 Jan 2020, 12:03 last edited by JonB@HoMa
Fair enough. Then @Shankar-B should be aware that if usingQProcess
he really ought write all the usual code for checking return results and reading from stdout/err, as the OS command could easily fail and user will not be aware/know why.
1/7