Cherple Cherple - 1 year ago 101
C++ Question

Executing a MSI file from a Qt application

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);

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download