My auto updater requires admin privileges to run since its modifying files in the programs folder. This all works fine.
However, when the update is done I want my updater.exe
to start myApplication.exe
but without admin privileges.
The code I currently use to start myApplication.exe from updater.exe:
bool started = QDesktopServices::openUrl(QUrl::fromLocalFile(exeFileName));
if (started)
{
QApplication::quit();
}
The problem is that when myApplication.exe
is started as admin it messes up my local paths, for example:
QString addin_path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
Points to the admin users folder. And not the actual user who is running the application.
Any ideas here?
update
Based on Merlin069's answer I'm testing the following:
TCHAR username[UNLEN + 1];
DWORD size = UNLEN + 1;
GetUserName((TCHAR*)username, &size);
qDebug() << QHostInfo::localHostName();
QProcess::startDetached("runas \"/user:<" + QHostInfo::localHostName() + ">\"" + username + ""\" \"" + exeFileName + "\");