Qt service with gui
-
wrote on 6 Jul 2024, 00:41 last edited by
I need my application to not be closed by a user who does not have administrative rights and I thought, therefore, of transforming it into a Windows service using the QtService located here: [https://skycoder42.github.io/QtService/index.html]
I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one. Unfortunately In my application I have to display the webcam content in a QtWidget and so I need a Gui. I'm wondering if the Windows service is the correct solution to solve my need and if it is, is it possible to show a gui? -
I need my application to not be closed by a user who does not have administrative rights and I thought, therefore, of transforming it into a Windows service using the QtService located here: [https://skycoder42.github.io/QtService/index.html]
I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one. Unfortunately In my application I have to display the webcam content in a QtWidget and so I need a Gui. I'm wondering if the Windows service is the correct solution to solve my need and if it is, is it possible to show a gui?wrote on 6 Jul 2024, 02:18 last edited by@franco-amato
Just a thought:
Most Anti-Virus Software is also running as a system service on Windows, so some unprivileged malware running under the same user can't stop the AntiVirus before it's being detected.
They also have a GUI, but the background (detection) service is probably another process compared to the User GUI. -
wrote on 6 Jul 2024, 04:50 last edited by
Can I have a help with the global design?
-
I need my application to not be closed by a user who does not have administrative rights and I thought, therefore, of transforming it into a Windows service using the QtService located here: [https://skycoder42.github.io/QtService/index.html]
I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one. Unfortunately In my application I have to display the webcam content in a QtWidget and so I need a Gui. I'm wondering if the Windows service is the correct solution to solve my need and if it is, is it possible to show a gui?wrote on 6 Jul 2024, 07:24 last edited by@franco-amato
Cannot imagine what your use case is. But a Windows Service cannot normally have a UI. Rather than my guessing whether any of them work, you might Google forwindows service with ui
and have a look through the various questions/answers. I am not sure any of them will work, at least nowadays. -
Can I have a help with the global design?
wrote on 6 Jul 2024, 10:12 last edited by@franco-amato Usually design goes like this:
you have one process running as a service, with privileges. The other one is with GUI and what not, doing actual work.
While I am not sure how one can prevent gui process from being closed, the work of a service in this case would be to monitor/being notified about the closure and if that's the case, respawn the gui and possibly notify some API that the incident happened. -
@franco-amato Usually design goes like this:
you have one process running as a service, with privileges. The other one is with GUI and what not, doing actual work.
While I am not sure how one can prevent gui process from being closed, the work of a service in this case would be to monitor/being notified about the closure and if that's the case, respawn the gui and possibly notify some API that the incident happened.wrote on 6 Jul 2024, 11:59 last edited by@artwaw said in Qt service with gui:
respawn the gui
I think that will be "tricky" from a service. For example, it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.
-
@franco-amato
Cannot imagine what your use case is. But a Windows Service cannot normally have a UI. Rather than my guessing whether any of them work, you might Google forwindows service with ui
and have a look through the various questions/answers. I am not sure any of them will work, at least nowadays.wrote on 6 Jul 2024, 13:30 last edited by@JonB T Don't you think that I already performed a google search before posting here?
-
@JonB T Don't you think that I already performed a google search before posting here?
wrote on 6 Jul 2024, 13:59 last edited by JonB 7 Jun 2024, 14:00@franco-amato
Not particularly, no. A lot of posters here don't, in fact probably most. And if they do they usually say so and what they came across. You asked if it is possible to show a GUI from a Windows service, and I suggested it is not, so far as I know. -
@artwaw said in Qt service with gui:
respawn the gui
I think that will be "tricky" from a service. For example, it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.
wrote on 6 Jul 2024, 14:37 last edited by@JonB said in Qt service with gui:
it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.
Yeah BUT :) I assumed gui runs as an identifiable process, at least that's what I think OP implied here. You can monitor that from the service, right?
The usual convenience (i.e. antivirus brought up previously) is that monitored gui runs for every user. And having a process running with privileges in the background I suppose you are able to discern which of your monitored processes runs under which user.
To be honest I don't think it is a nice way of implementing any solution but that's the only way that comes to mind right now.
-
@JonB said in Qt service with gui:
it doesn't have access to the desktop and it doesn't run as the desktop/logged on user.
Yeah BUT :) I assumed gui runs as an identifiable process, at least that's what I think OP implied here. You can monitor that from the service, right?
The usual convenience (i.e. antivirus brought up previously) is that monitored gui runs for every user. And having a process running with privileges in the background I suppose you are able to discern which of your monitored processes runs under which user.
To be honest I don't think it is a nice way of implementing any solution but that's the only way that comes to mind right now.
wrote on 6 Jul 2024, 14:50 last edited by@artwaw
You can "monitor" a process from a service, but I don't see how that relates to what the OP is wanting.The example for anti-virus just seems to be: the non-UI part of the AV runs as a service (with privileges), the user chooses to fire up a user-process UI which happens to communicate with it. The UI process is fully user-level, nothing special about it, so far as I know. I don't think that is what the OP is asking for. But we shall see.
-
@artwaw
You can "monitor" a process from a service, but I don't see how that relates to what the OP is wanting.The example for anti-virus just seems to be: the non-UI part of the AV runs as a service (with privileges), the user chooses to fire up a user-process UI which happens to communicate with it. The UI process is fully user-level, nothing special about it, so far as I know. I don't think that is what the OP is asking for. But we shall see.
wrote on 6 Jul 2024, 15:34 last edited by@JonB That's essentially what I wanted to say about the design, yes. And that would be my advice on how to implement functionality - using two processes: a monitor and a user-space gui. Unless Windows allows service to span a privileged process that a user can't interfere with but that's not a knowledge I possess.
-
@franco-amato
Not particularly, no. A lot of posters here don't, in fact probably most. And if they do they usually say so and what they came across. You asked if it is possible to show a GUI from a Windows service, and I suggested it is not, so far as I know.wrote on 6 Jul 2024, 15:46 last edited by@JonB no is not what I asked. You should re read my first post.
-
Hi,
One possible cheat is that you use a QProcess to start a new instance of your application if somebody stops it.
From a design point of view, you can forbid your user to close the application by handling the close event yourself. A starting point might be the QSystemTrayIcon example.
Note that this does not protect your application from getting killed but you can still handle the usual interruption signals.
The system service + client application combo is still worth exploring as you can have the service providing the core functionality and the application being merely a front-end. -
@JonB no is not what I asked. You should re read my first post.
wrote on 6 Jul 2024, 19:08 last edited by JonB 7 Jun 2024, 19:09@franco-amato said in Qt service with gui:
You should re read my first post.
I have read it many times, thanks. Best of luck showing a UI from a Windows service.
-
@franco-amato said in Qt service with gui:
You should re read my first post.
I have read it many times, thanks. Best of luck showing a UI from a Windows service.
wrote on 6 Jul 2024, 19:37 last edited by@JonB said in Qt service with gui:
@franco-amato said in Qt service with gui:
You should re read my first post.
I have read it many times, thanks. Best of luck showing a UI from a Windows service.
If you had read it you would have seen that I stated the following: "I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one". What I asked is whether the path of service is the right path or if there are other solutions to achieve my need
-
@JonB said in Qt service with gui:
@franco-amato said in Qt service with gui:
You should re read my first post.
I have read it many times, thanks. Best of luck showing a UI from a Windows service.
If you had read it you would have seen that I stated the following: "I know that a Windows service usually doesn't have a GUI and I'm not sure it can have one". What I asked is whether the path of service is the right path or if there are other solutions to achieve my need
wrote on 6 Jul 2024, 19:44 last edited by JonB 7 Jun 2024, 19:46@franco-amato said in Qt service with gui:
If you had read it
Thanks again. It's always nice to try to help people, just what we like to hear.
I read your post carefully, as I said. All I ever answered was that I think you will find it difficult to run a UI from a service. You asked if that was the "right path", I suggested it is not. Sorry if you didn't want to hear that. Why don't you leave me out now, thanks.
-
Hi,
One possible cheat is that you use a QProcess to start a new instance of your application if somebody stops it.
From a design point of view, you can forbid your user to close the application by handling the close event yourself. A starting point might be the QSystemTrayIcon example.
Note that this does not protect your application from getting killed but you can still handle the usual interruption signals.
The system service + client application combo is still worth exploring as you can have the service providing the core functionality and the application being merely a front-end.wrote on 6 Jul 2024, 20:03 last edited by@SGaist Can you help with a small example regarding this "One possible cheat is that you use a QProcess to start a new instance of your application if somebody stops it." ?
-
// rest of the code int result = app.exec(); QProcess::startDetached("your_application"); return result;
-
// rest of the code int result = app.exec(); QProcess::startDetached("your_application"); return result;
wrote on 6 Jul 2024, 20:21 last edited by@SGaist said in Qt service with gui:
// rest of the code int result = app.exec(); QProcess::startDetached("your_application"); return result;
It worked but now I am not able to stop it anymore :)) and I am the admin
-
You will have to implement some checks to determine who stopped the application.
Note that you also need to implement graceful shutdown for when you stop/restart your machine.
1/25