Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt service with gui
Forum Updated to NodeBB v4.3 + New Features

Qt service with gui

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 7 Posters 2.4k Views 7 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    franco.amato
    wrote on 6 Jul 2024, 00:41 last edited by
    #1

    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?

    P J 2 Replies Last reply 6 Jul 2024, 02:18
    0
    • F franco.amato
      6 Jul 2024, 00:41

      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?

      P Offline
      P Offline
      Pl45m4
      wrote on 6 Jul 2024, 02:18 last edited by
      #2

      @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.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • F Offline
        F Offline
        franco.amato
        wrote on 6 Jul 2024, 04:50 last edited by
        #3

        Can I have a help with the global design?

        A 1 Reply Last reply 6 Jul 2024, 10:12
        0
        • F franco.amato
          6 Jul 2024, 00:41

          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?

          J Offline
          J Offline
          JonB
          wrote on 6 Jul 2024, 07:24 last edited by
          #4

          @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 for windows service with ui and have a look through the various questions/answers. I am not sure any of them will work, at least nowadays.

          F 1 Reply Last reply 6 Jul 2024, 13:30
          0
          • F franco.amato
            6 Jul 2024, 04:50

            Can I have a help with the global design?

            A Offline
            A Offline
            artwaw
            wrote on 6 Jul 2024, 10:12 last edited by
            #5

            @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.

            For more information please re-read.

            Kind Regards,
            Artur

            J 1 Reply Last reply 6 Jul 2024, 11:59
            3
            • A artwaw
              6 Jul 2024, 10:12

              @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.

              J Offline
              J Offline
              JonB
              wrote on 6 Jul 2024, 11:59 last edited by
              #6

              @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.

              A 1 Reply Last reply 6 Jul 2024, 14:37
              0
              • J JonB
                6 Jul 2024, 07:24

                @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 for windows service with ui and have a look through the various questions/answers. I am not sure any of them will work, at least nowadays.

                F Offline
                F Offline
                franco.amato
                wrote on 6 Jul 2024, 13:30 last edited by
                #7

                @JonB T Don't you think that I already performed a google search before posting here?

                J 1 Reply Last reply 6 Jul 2024, 13:59
                0
                • F franco.amato
                  6 Jul 2024, 13:30

                  @JonB T Don't you think that I already performed a google search before posting here?

                  J Offline
                  J Offline
                  JonB
                  wrote on 6 Jul 2024, 13:59 last edited by JonB 7 Jun 2024, 14:00
                  #8

                  @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.

                  F 1 Reply Last reply 6 Jul 2024, 15:46
                  0
                  • J JonB
                    6 Jul 2024, 11:59

                    @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.

                    A Offline
                    A Offline
                    artwaw
                    wrote on 6 Jul 2024, 14:37 last edited by
                    #9

                    @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.

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    J 1 Reply Last reply 6 Jul 2024, 14:50
                    0
                    • A artwaw
                      6 Jul 2024, 14:37

                      @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.

                      J Offline
                      J Offline
                      JonB
                      wrote on 6 Jul 2024, 14:50 last edited by
                      #10

                      @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.

                      A 1 Reply Last reply 6 Jul 2024, 15:34
                      0
                      • J JonB
                        6 Jul 2024, 14:50

                        @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.

                        A Offline
                        A Offline
                        artwaw
                        wrote on 6 Jul 2024, 15:34 last edited by
                        #11

                        @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.

                        For more information please re-read.

                        Kind Regards,
                        Artur

                        1 Reply Last reply
                        0
                        • J JonB
                          6 Jul 2024, 13:59

                          @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.

                          F Offline
                          F Offline
                          franco.amato
                          wrote on 6 Jul 2024, 15:46 last edited by
                          #12

                          @JonB no is not what I asked. You should re read my first post.

                          J 1 Reply Last reply 6 Jul 2024, 19:08
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 6 Jul 2024, 16:28 last edited by
                            #13

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            F 1 Reply Last reply 6 Jul 2024, 20:03
                            2
                            • F franco.amato
                              6 Jul 2024, 15:46

                              @JonB no is not what I asked. You should re read my first post.

                              J Offline
                              J Offline
                              JonB
                              wrote on 6 Jul 2024, 19:08 last edited by JonB 7 Jun 2024, 19:09
                              #14

                              @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.

                              F 1 Reply Last reply 6 Jul 2024, 19:37
                              1
                              • J JonB
                                6 Jul 2024, 19:08

                                @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.

                                F Offline
                                F Offline
                                franco.amato
                                wrote on 6 Jul 2024, 19:37 last edited by
                                #15

                                @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

                                J 1 Reply Last reply 6 Jul 2024, 19:44
                                0
                                • F franco.amato
                                  6 Jul 2024, 19:37

                                  @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

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 6 Jul 2024, 19:44 last edited by JonB 7 Jun 2024, 19:46
                                  #16

                                  @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.

                                  1 Reply Last reply
                                  1
                                  • SGaistS SGaist
                                    6 Jul 2024, 16:28

                                    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.

                                    F Offline
                                    F Offline
                                    franco.amato
                                    wrote on 6 Jul 2024, 20:03 last edited by
                                    #17

                                    @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." ?

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 6 Jul 2024, 20:06 last edited by
                                      #18
                                      // rest of the code
                                      int result = app.exec();
                                      QProcess::startDetached("your_application");
                                      return result;
                                      

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      F 1 Reply Last reply 6 Jul 2024, 20:21
                                      0
                                      • SGaistS SGaist
                                        6 Jul 2024, 20:06
                                        // rest of the code
                                        int result = app.exec();
                                        QProcess::startDetached("your_application");
                                        return result;
                                        
                                        F Offline
                                        F Offline
                                        franco.amato
                                        wrote on 6 Jul 2024, 20:21 last edited by
                                        #19

                                        @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

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 7 Jul 2024, 07:56 last edited by
                                          #20

                                          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.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          F 1 Reply Last reply 7 Jul 2024, 14:03
                                          1

                                          1/25

                                          6 Jul 2024, 00:41

                                          • Login

                                          • Login or register to search.
                                          1 out of 25
                                          • First post
                                            1/25
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved