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. Application updater
Forum Updated to NodeBB v4.3 + New Features

Application updater

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 3.1k Views 1 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.
  • U Offline
    U Offline
    unmanner
    wrote on last edited by
    #1

    Hello!

    I write a simple application autoupdater.

    Updater is located in: C:\Program Files (x86)\Corp\Prod\updater.exe

    It started and downloaded new executable file to: C:\Program Files (x86)\Corp\Prod\my_qt_application.exe

    But it fails to save with "No permissions" error.

    How I can ride this? How I can ask user to take an administrators permissions?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should rather ask this question on a Microsoft forum, you'll have more chance to get a useful answer there.

      As a side note, are you sure you want to develop your own solution ? There already exists several frameworks to do that, KDAB's KDTools and WinSparkle comes to mind.

      Hope it helps

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

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #3

        Hi,

        starting with Vista it's tricky for for normal apps to write files in C:\Program Files or C:\Program Files (x86), only installers are allowed to do that.

        Maybe you can try saving your executable in C:\Users\JohnDoe\AppData\Roaming instead, like Minecraft or WoW do.

        Rgrds Henry

        1 Reply Last reply
        0
        • U Offline
          U Offline
          unmanner
          wrote on last edited by
          #4

          KDTools - seems have very bad support, and I found many compilation errors ..

          WinSparkle - not providing update mechanism, only forward clients to the web site.

          I need update my exe file only, and need a most simple solution.

          [quote author="SGaist" date="1375561276"]Hi,

          You should rather ask this question on a Microsoft forum, you'll have more chance to get a useful answer there.

          As a side note, are you sure you want to develop your own solution ? There already exists several frameworks to do that, KDAB's KDTools and WinSparkle comes to mind.

          Hope it helps[/quote]

          [quote author="hskoglund" date="1375562663"]Hi,

          starting with Vista it's tricky for for normal apps to write files in C:\Program Files or C:\Program Files (x86), only installers are allowed to do that.

          Maybe you can try saving your executable in C:\Users\JohnDoe\AppData\Roaming instead, like Minecraft or WoW do.

          Rgrds Henry
          [/quote]

          I will try to do this.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            unmanner
            wrote on last edited by
            #5

            Hi hskoglund,

            I have the same error whet I store my executables in "User's personal data folder"..

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi, You can use this to check whether you are running with elevated permissions:
              @
              bool isElevated()
              {
              bool result = false;
              HANDLE hToken = NULL;

              if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
              {
                  TOKEN_ELEVATION elevation;
                  DWORD dwSize;
                  if(GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize))
                      result = elevation.TokenIsElevated != 0;
              
                  CloseHandle(hToken);
              }
              return result;
              

              }
              @
              and if not, restart your updater asking user for elevation:
              @
              void restartElevated()
              {
              wchar_t fileName[MAX_PATH];
              wchar_t workingDir[MAX_PATH];
              qApp->applicationFilePath().toWCharArray(fileName);
              QDir::currentPath().toWCharArray(workingDir);

              SHELLEXECUTEINFO shex = {0};
              shex.cbSize = sizeof(SHELLEXECUTEINFO);
              shex.lpVerb = L"runas";
              shex.lpFile = fileName;
              shex.lpDirectory = workingDir;
              shex.nShow = SW_NORMAL;
              
              ::ShellExecuteEx(&shex);
              qApp->closeAllWindows(); //or however you want to exit
              

              }
              @
              To use these you need to link to shell32 and advapi32.
              Just remember to check first if the update is really available and don't bother user if you're not gonna need the extended permissions.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hey Chris Kawa, thanks for the information !

                IIRC you've already provided several windows related neat tips and tricks like that one, did you consider making a Wiki page with them ? :)

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

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  you may find "this thread":https://qt-project.org/forums/viewthread/28600 also interesting.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    unmanner
                    wrote on last edited by
                    #9

                    Hi Chris Kawa,

                    could you please help me again? I tried the solution and it works but sometimes the following error appears:!http://i020.radikal.ru/1308/71/dc886dd13fe4.png(error)!

                    I translate: "Unable to find "D:/Dropbox/...", Check file name and try again."

                    Seems something wrong with '\0'?

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      unmanner
                      wrote on last edited by
                      #10

                      I add the following lines:

                      @fileName[QApplication::applicationFilePath().length()] = '\0';
                      workingDir[QDir::currentPath().length()] = '\0';@

                      now it works fine, thanks! :)

                      1 Reply Last reply
                      0
                      • Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Yeah, sorry. I mixed and matched some scraps from my old code and forgot to zero out the arrays.
                        Glad you fixed it.

                        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