Qt Installer Framework and Administrator privileges [SOLVED]



  • Does anybody know how to make the installation package with Administrator privileges?
    (In other words how to elevate my installer to Admin level)
    I'm using Qt Installer Framework 1.4 (QtIFW1.4)



  • There is only the following parameter in configuration file which I thought might be useful but seemingly it's not related to make the installation file have the Admin privileges.

    @
    <AdminTargetDir>@rootDir@/testinstall</AdminTargetDir>
    @



  • After lots of searching finally I found a solution. Unfortunately this is not documented in version 1.4

    Add the following line to your component's package xml file:
    @<RequiresAdminRights>true</RequiresAdminRights>@

    And use this line in your script file:
    @component.addElevatedOperation("Execute", "someCommand");@
    instead of
    @component.addOperation("Execute", "someCommand");@


  • Lifetime Qt Champion

    Hi,

    You should check the "bug report system":http://bugreports.qt-project.org to see if someone already reported this missing documentation, if not you could consider opening a new report



  • Not in "bug report system":http://bugreports.qt-project.org/ but someone has mentioned it "here":https://qt.gitorious.org/installer-framework/installer-framework/commit/aa9d0b6cbe8c215ab4610aa6349250c08b4d09b3
    I think I'll go ahead and create a report for this.



  • Sorry, my mistake, "this link":https://qt.gitorious.org/installer-framework/installer-framework/commit/aa9d0b6cbe8c215ab4610aa6349250c08b4d09b3 is a commit. So I assume it means in the next version this'll be solved (in other words it is solved already. No need for any reports) :)


  • Lifetime Qt Champion

    Exactly what I was about to say :)

    Happy coding !



  • Hi, I am currently trying to run part of my install with admin rights. Adding the fix you have suggested does prompt the user to allow the install but when it executes the batch file which installs a driver onto the user’s machine the batch file is not run as admin. Any clues why that's the case? Thanks in advance ;)



  • To be precise, this is how I solved my problem because I was working on Windows and if you are also on Windows, I suggest you also do this and skip all the complications:
    @
    Component.prototype.createOperations = function()
    {
    try
    {
    // call the base create operations function
    component.createOperations();
    if (installer.value("os") === "win")
    {
    component.addOperation("Execute", "cmd /C "@TargetDir@\SomeFolder\SomeFile.exe"");
    }
    } catch (e)
    {
    print(e);
    }
    }
    @
    You don't need to add admin rights for this to work.
    Just let the command prompt do the job for you :)



  • Hi again, Thanks for your reply. I have added the operation call below as you have in your script but it causes a syntax error in the command window when trying to build the installer.

    @Component.prototype.createOperations = function()
    {
    try
    {
    // call the base create operations function
    component.createOperations();
    if (installer.value("os") === "win")
    {
    component.addOperation("CreateShortcut",
    "@TargetDir@/%1.exe", "@StartMenuDir@/%1.lnk");

            component.addOperation("Execute", "cmd /C", 
                                   "@TargetDir@\\USB_Install.bat");
        }
    }
    catch (e)
    {
    

    print(e);
    }
    }@

    perhaps you can see where I'm going wrong?



  • Yes it's obvious where you're going wrong. If you look at my code above I've sent it all inside a single command without separating the parameters. AND WITH DOUBLE QUOTES FOR THE PATH PARAMETER!
    Like this:
    @
    component.addOperation("Execute", "cmd /C "@TargetDir@\USB_Install.bat"");
    @
    Please pay attention to every single character in this code.

    Or, you can do it the way you were going to do, but again, don't forget the double quotes.
    Like this:
    @
    component.addOperation("Execute", "cmd", "/C", ""@TargetDir@\USB_Install.bat"");
    @



  • My apologies, I did actually write it using the syntax above at first but 'tinkered' with it a little when it was not working. I must have then copy pasted the wrong(changed) code into this post window.

    I still cannot get the drivers to install using either of the script calls. Using the first syntax the software does install but the drivers do not, there are no error messages and the install log states-

    backup com.exi.root operation: Execute

    • arguments: cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat"
      Done
      perform com.exi.root operation: Execute
    • arguments: cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat"
      ElevatedExecuteOperation setNativeArguments to start: "cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat""
      cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat"" started, arguments: "
      Done

    so it is calling the command correctly from the script yes?

    The second script call gives an error message-

    "Error during installation process(com.exi.root):
    Execution faild(Unexpected exit code: 1): "cmd /C "C:
    \Users\Bobby\SFC4000\USB_Install.bat""

    I'm sure I'm just doing something stupid but i just can't see it. Thanks for your help.



  • Oh, I see. I also noticed it now, you are trying to run a bat file. Did you set workingDirectory parameter to the folder in which your bat file exists?

    My only suggestion would be to go for all of the solutions above at once. :)

    Add this to your package
    @
    <RequiresAdminRights>true</RequiresAdminRights>
    @

    And call elevated version of the function like this (Also set working directory)
    @
    component.addElevatedOperation("Execute", "cmd /C "@TargetDir@\USB_Install.bat"", "workingDirectory=@TargetDir@");
    @

    If this also doesn't work then you can share the contents of your bat file.
    Maybe that way I can understand a little bit more about the issue you're facing.



  • Thank you very much for your help. It's much appreciated. Unfortunately it is still not working. However it does not produce a different error-

    "Execute" as admin: true
    backup com.exi.root operation: Execute

    • arguments: cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat", workingDirectory=C:\Users\Bobby\SFC4000
      Done
      perform com.exi.root operation: Execute
    • arguments: cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat", workingDirectory=C:\Users\Bobby\SFC4000
      ElevatedExecuteOperation setWorkingDirectory: "C:\Users\Bobby\SFC4000"
      ElevatedExecuteOperation setNativeArguments to start: "cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat""
      cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat"" started, arguments: "
      Done
      Operation 'Execute' with arguments: 'cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat"; workingDirectory=C:\Users\Bobby\SFC4000' failed: Execution failed: Could not start: "cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat""(Process failed to start: The parameter is incorrect.)
      created warning message box installationErrorWithRetry: 'Installer Error', Error during installation process (com.exi.root):
      Execution failed: Could not start: "cmd /C "C:\Users\Bobby\SFC4000\USB_Install.bat""(Process failed to start: The parameter is incorrect.)

    I don't think it is the actual batch file that's the problem as it runs fine when called directly from the administrator command prompt but it is show below anyway.

    @
    @echo off

    rundll32.exe libusb0.dll,usb_install_driver_np_rundll sfc3000.inf
    @



  • I can see a very familiar error message there:
    "Process failed to start: The parameter is incorrect"

    Try this and share the results if you can.

    Press WIN + R to open "Run" program
    Enter the following line as a command and see what happens:
    cmd /C “C:\Users\Bobby\SFC4000\USB_Install.bat”

    As far as I know, if it runs using Run application then it will surely run using your installer too.
    If it doesn't run using Run application then you shouldn't mess around with installer much and try to correct your batch script.

    What about this, don't turn off echo and insert a pause at the of your batch script. Like this:
    @
    rundll32.exe libusb0.dll,usb_install_driver_np_rundll sfc3000.inf
    pause
    @



  • Also share the result you see in the command window



  • ECHO is on.

    It was originally calling the batch file from the system32 directory so I added a call to cd and now change it to the .bat's current dir and slightly modified the folder layout and updated the batch file accordingly. This is was cmd window prints out

    C:\Windows\system32>cd C:\Users\Bobby\SFC4000\

    C:\Users\Bobby\SFC4000>cd ".\Driver\exi"

    C:\Users\Bobby\SFC4000\Driver\exi>rundll32.exe libusb0.dll,usb_install_driver_np
    _rundll sfc3000.inf

    C:\Users\Bobby\SFC4000\Driver\exi>pause
    Press any key to continue . . .



  • Sorry I didn't get it. Is this the output for Installer running your batch or is this the result for Run application???
    There are no errors here, if you're saying that it ran just fine when you tried it with Run then it seems we're stuck at this point!
    My advice would be to check the scripts again one more time and if you are 100% sure that it just isn't working for you then try another installer creator (like inno setup) for the time being. Until new release for QTIFW comes out.



  • That was the output in the command window when using your win+r instructions.

    Its OK now though I finally have it working!! I applied all of the changes that you suggested and also changed the installer compatibility settings in it's properties so that it's run as administrator. I probably would have got it working much sooner if i hadn't spent an hour or so trying to install the 32bit drivers on my 64bit machine DUHHHH! But hey, we live and learn.

    Thanks for your help really appreciate it :)



  • :) Wow. Ok. Glad to hear you made it work finally.



  • Hi, sorry to bring this post back to life, but I'm having problems executing a bundled installer from the installscript.qs in my QtInstaller application.

    What I do is install the .msi to the @TargetDir@ and then try to launch it with

    @component.addOperation("Execute", "msiexec.exe /i", ""@TargetDir@\MyUsbDriver.msi"");@

    (I used the double quotes for the target dir because my installer application can accept paths with spaces, I'm installing on wnidows)

    I keep on getting error messages stating:

    bq. Execution Failed: Could not start: "C:\Program Files\MyApp\MyUsbDriver.msi" (Process failed to start: The parameter is incorrect)
    (I used the double quotes for the target dir because my installer application can accept paths with spaces, I'm installing on wnidows)

    Any ideas on how to correctly launch the .msi file?



  • [quote author="amahta" date="1390477421"]To be precise, this is how I solved my problem because I was working on Windows and if you are also on Windows, I suggest you also do this and skip all the complications:
    @
    Component.prototype.createOperations = function()
    {
    try
    {
    // call the base create operations function
    component.createOperations();
    if (installer.value("os") === "win")
    {
    component.addOperation("Execute", "cmd /C "@TargetDir@\SomeFolder\SomeFile.exe"");
    }
    } catch (e)
    {
    print(e);
    }
    }
    @
    You don't need to add admin rights for this to work.
    Just let the command prompt do the job for you :)[/quote]

    This should work for you. Pass your msi file using "msiexec" command to "cmd"



  • Using

    @component.addOperation("Execute", "cmd /C", "msiexec.exe /i", ""@TargetDir@\MyUsbDriver.msi"");
    @

    gives me the same execution error stated above.

    Running the command from cmd starts the driver installation though. So it's got to be something in the installscript.qs.

    Any ideas?



  • I have a related issue and am struggling to get it going for quite sometime. I have even raised a jira on Qt Installer Framework https://bugreports.qt-project.org/browse/QTIFW-497 but did not get a reply/comment yet. Any pointers would be of great help.



  • [quote author="nwoki" date="1398777153"]Using

    @component.addOperation("Execute", "cmd /C", "msiexec.exe /i", ""@TargetDir@\MyUsbDriver.msi"");
    @

    gives me the same execution error stated above.

    Running the command from cmd starts the driver installation though. So it's got to be something in the installscript.qs.

    Any ideas?[/quote]

    Hi, I have a similar issue to this thread, and closer to that quoted above. I've looked everywhere and can find threads about executing exe's, etc AFTER installation of my own app, but need to know how to install a prerequisite for my app. This is common functionality in other installers but I can't seem to find info on it for QT Installer Framework.
    I.E., I need to first run vcredist_x86.exe or my program will not work. Better yet would be detecting if they already have that or not (other advanced installer I've seen do this) and launch accordingly, but even as simple launch before we install ours would work ok too. Can this be done?



  • Forgot to post my answer. This is how i resolved my problem. Basically, every parameter must be seperated as follows

    @ component.addOperation("Execute"
    , "msiexec"
    , "/i"
    , "@TargetDir@\Driver.msi"
    , "UNDOEXECUTE"
    , "msiexec"
    , "/qb"
    , "/x"
    , "@TargetDir@\Driver.msi");@



  • Hello Everyone,

    I hate to warm this up, but i am encountering the same problems.
    I need to install some drivers along with my software, which need admin rights for installment.

    All together i added:
    @<RequiresAdminRights>true</RequiresAdminRights> @
    to the package.xml
    and
    @function Component()
    {
    }

    Component.prototype.createOperations = function()
    {
    try
    {
    installer.gainAdminRights();
    component.createOperations();
    if (installer.value("os") === "win")
    {
    // component.addElevatedOperation("Execute", "cmd", "/C", ""@TargetDir@\CP210xVCPInstaller_x64.exe"", "workingDirectory=@TargetDir@");
    component.addElevatedOperation("Execute", "{256}", ""@TargetDir@\CP210xVCPInstaller_x64.exe"", "workingDirectory=@TargetDir@");
    }
    } catch (e)
    {
    print(e);
    }
    }@

    This returns the error:
    @Error during installation process (driver_x64):
    Execution failed(Unexpected exit code: 0): ""[Filepath]""@

    The returncode is not the issue. it does not even start the driver installation.
    I tried the cmd version also, but could not get it to work either.

    When i manually start the installer with admin rights, it works fine.

    Any advice? Thanks in advance.



  • Hi all and thanks for the hints.
    I've found a problem related to admin rights so I write here instead of opening a new thread.

    I created a "TestInstaller" that installs a "qt hello world" program to "Program Files (86)/TestInstaller" with admin privileges.

    Then if I uninstall it using admin privileges, the directory "Program Files (86)/TestInstaller" is deleted as it should.

    If I uninstall it NOT using admin privileges, the directory is not deleted and still contains the file "uninstall.exe".

    How can I fix this ?





  • I tried to post a thanks to nwoki the 1 October but the forum was presumably down as I could not.
    Thanks.

    Anyway, I have other problems now: beside the logo not shown, I need to create an installer for a customer and it should NOT have admin rights.
    So I wrote
    <RequiresAdminRights>false</RequiresAdminRights>
    in package.xml, I DON'T call
    installer.gainAdminRights();
    but when I execute the created installer, the admin password is asked.
    Another bug or what ?
    I have a Qt license, shall I contact the support ?



  • @amahta said:

    TargetDir

    Hello All,

    Actually, I have a same problem ( using 2.0.0 version), I want to use this command below:

    component.addElevatedOperation("Execute", "{0,3010}", "@TargetDir@\vcredist\vcredist_x86.exe", "/norestart", "/q");

    But It crashes when installing process. In my package.xml, <RequiresAdminRights>true</RequiresAdminRights> tag is exist.

    Thanks in advance.



  • @Wilmord: It seems to be new bug in IFW 2.0.0. See Bugreport: https://bugreports.qt.io/browse/QTIFW-659



  • Yes. It seems like that. I entered comment it and hope that they will fix soon.
    Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.