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. Run as administrator
Qt 6.11 is out! See what's new in the release blog

Run as administrator

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.0k Views 2 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.
  • M Offline
    M Offline
    MartinD
    wrote on last edited by
    #1

    Depending on context, I will need to launch single exe file from Qt application with and without administrator rights on Windows. Is this possible?

    K 1 Reply Last reply
    0
    • M MartinD

      Depending on context, I will need to launch single exe file from Qt application with and without administrator rights on Windows. Is this possible?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @MartinD

      This thread has a siimilar topic and provides already hints.

      Vote the answer(s) that helped you to solve your issue(s)

      JonBJ 1 Reply Last reply
      0
      • K koahnig

        @MartinD

        This thread has a siimilar topic and provides already hints.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @koahnig
        The thread you quote is to do with how to run a single instance of a Qt application. How is that connected to the OP's question about ability to run "elevated under Windows"?

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          The easy way is just to use a tool.
          Like
          http://nircmd.nirsoft.net/elevate.html
          nircmd elevate notepad.exe C:\Windows\System32\Drivers\etc\HOSTS

          and you can just use QProcess to start nircmd.

          This assumes i read it right.
          From a Qt program, you want to start OTHER app, with and without admin rights

          JonBJ 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi
            The easy way is just to use a tool.
            Like
            http://nircmd.nirsoft.net/elevate.html
            nircmd elevate notepad.exe C:\Windows\System32\Drivers\etc\HOSTS

            and you can just use QProcess to start nircmd.

            This assumes i read it right.
            From a Qt program, you want to start OTHER app, with and without admin rights

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @mrjj
            Hmm, again, I (kind of) thought the OP was referring to running a single Qt app elevated & not. But you're interpretation is probably correct :)

            mrjjM 1 Reply Last reply
            0
            • JonBJ JonB

              @mrjj
              Hmm, again, I (kind of) thought the OP was referring to running a single Qt app elevated & not. But you're interpretation is probably correct :)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JonB
              well the " launch single exe file" made me think App starts other App, but
              its not that i would bet beer on it :)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MartinD
                wrote on last edited by
                #7

                Sorry for confusions. I used this code in my app to elevate privilege when launching an app:

                SHELLEXECUTEINFO Shex;
                            ZeroMemory( &Shex, sizeof( SHELLEXECUTEINFO ) );
                            Shex.cbSize = sizeof( SHELLEXECUTEINFO );
                            Shex.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
                            Shex.lpVerb = L"runas";
                            Shex.lpFile = f.c_str();
                            Shex.lpParameters = args.c_str();
                            Shex.nShow = SW_SHOWNORMAL;
                
                            if (!ShellExecuteEx(&Shex)) {
                                return;
                            }
                
                mrjjM 1 Reply Last reply
                0
                • M MartinD

                  Sorry for confusions. I used this code in my app to elevate privilege when launching an app:

                  SHELLEXECUTEINFO Shex;
                              ZeroMemory( &Shex, sizeof( SHELLEXECUTEINFO ) );
                              Shex.cbSize = sizeof( SHELLEXECUTEINFO );
                              Shex.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
                              Shex.lpVerb = L"runas";
                              Shex.lpFile = f.c_str();
                              Shex.lpParameters = args.c_str();
                              Shex.nShow = SW_SHOWNORMAL;
                  
                              if (!ShellExecuteEx(&Shex)) {
                                  return;
                              }
                  
                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @MartinD
                  Hi
                  Ah, using run as. ( you should have mentioned this from start :)

                  Im not sure what question is about then.

                  Are you asking how to use ShellExecuteEx
                  both as elevated and as not?

                  As far as i recall, you should replace lpVerb with "open"
                  to have it NOT ask.

                  1 Reply Last reply
                  0

                  • Login

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