0

I have written a Qt application that downloads and then executes an MSI file. The execution is done via QProcess and is using the information provided in this question.

Whenever I run it using QProcess an exception is thrown:

Exception thrown: read access violation

which seems to be a rights management problem. However I don't know where the problem is exactly and how to fix it. Here is an example code snippet:

QProcess *process = new QProcess(this);
QString program = "file.msi";
QString folder = "C:\\Users\\user\\Downloads\\";
process->start(program, QStringList() << folder);
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161
Cherple
  • 725
  • 3
  • 10
  • 24
  • Show a brief example of the code you are using for this. We can't solve bugs in code we can't see. – drescherjm Aug 14 '17 at 13:46
  • I've given a link and its exactly as shown. – Cherple Aug 14 '17 at 16:38
  • There should not this issue using QProcess. You likely have a bug in your code or a dll conflict. We can not help with either if we can not reproduce. I can assure you that I use QProcess in several of my applications and none of them do this. – drescherjm Aug 14 '17 at 16:41

1 Answers1

2

The problem comes from the fact that an MSI file is an installation file thus it requires administrator privileges.

There are two options:

  • try using QDesktopServices::openUrl(QUrl("file:///<path to your MSI file>"), QUrl::TolerantMode)); (as suggested here) instead of using QProcess.
  • Use the Windows runas by calling QProcess::startDetached("runas /user:<localmachinename>\user msiFileName"); where you replace the respective strings with your own (for that you should check the documentation of runas since this has nothing to do with Qt but with the command line arguments of runas.

In addition you can run your Qt application with administrator privileges. In order to save the user the rouble of doing it manually you can use this to tell Windows what the default execution of your Qt application is supposed to be. This is something I would advise against because your application may introduce a security breach in the system that you can be held liable for.

rbaleksandar
  • 8,713
  • 7
  • 76
  • 161