Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QProcess::startDetached blocked by UAC (running an updater)

Tags:

process

uac

qt

I have an update function in my app - it downloads and verifies the installer (a setup.exe, created with NSIS). To actually kick off the update, I have simply been doing:

QString path = .. absolute path to the downloaded file ...
QProcess::startDetached(path, QStringList());

This works fine on XP - but on Vista and Win7, nothing happens once the download completes. If I browse to the downloaded update and run it manually, it works fine. I assume what's happening is that UAC is blocking the installer at CreateProcess time, but this is where my knowledge runs out.

Additional complication - when I'm running a debug build from the command line, the steps above work - I get the UAC prompt and can run the installer. It's the release builds, started form the start menu/shortcut, which have the issue - I assume there's a difference in the auth token when running from a command shell.

like image 267
James Turner Avatar asked Dec 24 '10 14:12

James Turner


2 Answers

You can also use

QDesktopServices::openUrl(QUrl::fromLocalFile(path));

Might be surprising and counterintuitive, but it works and is more cross-platform

like image 174
sierdzio Avatar answered Nov 28 '22 11:11

sierdzio


If you are not admin and you call CreateProcess() on a .exe with a "Vista" manifest (or no manifest, but a .exe that windows detects as an installer (This includes NSIS)) the call fails, you need to use ShellExecute[Ex](). ShellExecute will trigger UAC prompt if required...

like image 39
Anders Avatar answered Nov 28 '22 10:11

Anders