summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libs/installer/adminauthorization_win.cpp53
-rw-r--r--src/libs/installer/fsengineclient.cpp11
2 files changed, 33 insertions, 31 deletions
diff --git a/src/libs/installer/adminauthorization_win.cpp b/src/libs/installer/adminauthorization_win.cpp
index ce6d20a4e..d9de7c728 100644
--- a/src/libs/installer/adminauthorization_win.cpp
+++ b/src/libs/installer/adminauthorization_win.cpp
@@ -33,13 +33,25 @@
#include "utils.h"
-#include <QtCore/QDebug>
-#include <QtCore/QDir>
-#include <QtCore/QStringList>
-#include <QtCore/QVector>
+#include <QDebug>
+#include <QDir>
#include <windows.h>
+struct DeCoInitializer
+{
+ DeCoInitializer()
+ : neededCoInit(CoInitialize(NULL) == S_OK)
+ {
+ }
+ ~DeCoInitializer()
+ {
+ if (neededCoInit)
+ CoUninitialize();
+ }
+ bool neededCoInit;
+};
+
AdminAuthorization::AdminAuthorization()
{
}
@@ -74,30 +86,21 @@ bool AdminAuthorization::hasAdminRights()
bool AdminAuthorization::execute(QWidget *, const QString &program, const QStringList &arguments)
{
+ DeCoInitializer _;
+
const QString file = QDir::toNativeSeparators(program);
const QString args = QInstaller::createCommandline(QString(), arguments);
- const int len = GetShortPathName((wchar_t *)file.utf16(), 0, 0);
- if (len == 0)
- return false;
- wchar_t *const buffer = new wchar_t[len];
- GetShortPathName((wchar_t *)file.utf16(), buffer, len);
+ SHELLEXECUTEINFOW shellExecuteInfo = { 0 };
+ shellExecuteInfo.nShow = SW_HIDE;
+ shellExecuteInfo.lpVerb = L"runas";
+ shellExecuteInfo.lpFile = (wchar_t *)file.utf16();
+ shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
+ shellExecuteInfo.lpParameters = (wchar_t *)args.utf16();
- SHELLEXECUTEINFOW TempInfo = { 0 };
- TempInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
- TempInfo.fMask = 0;
- TempInfo.hwnd = 0;
- TempInfo.lpVerb = L"runas";
- TempInfo.lpFile = buffer;
- TempInfo.lpParameters = (wchar_t *)args.utf16();
- TempInfo.lpDirectory = 0;
- TempInfo.nShow = SW_NORMAL;
+ qDebug() << QString::fromLatin1("Starting elevated process %1 with arguments: %2.").arg(file, args);
+ ShellExecuteExW(&shellExecuteInfo);
+ qDebug() << "Finished starting elevated process.";
-
- qDebug() << QString::fromLatin1(" starting elevated process %1 %2 with ::ShellExecuteExW( &TempInfo );"
- ).arg(program, arguments.join(QLatin1String(" ")));
- const bool result = ::ShellExecuteEx(&TempInfo);
- qDebug() << QLatin1String("after starting elevated process");
- delete[] buffer;
- return result;
+ return GetLastError() == ERROR_SUCCESS;
}
diff --git a/src/libs/installer/fsengineclient.cpp b/src/libs/installer/fsengineclient.cpp
index 3221b9f29..7e3ceb1d5 100644
--- a/src/libs/installer/fsengineclient.cpp
+++ b/src/libs/installer/fsengineclient.cpp
@@ -783,7 +783,8 @@ void FSEngineClientHandler::Private::maybeStartServer()
if (!serverStarted) {
// something went wrong with authorizing, either user pressed cancel or entered
// wrong password
- const QString fallback = serverCommand + QLatin1String(" ") + serverArguments.join(QLatin1String(" "));
+ const QString fallback = serverCommand + QLatin1String(" ") + serverArguments
+ .join(QLatin1String(" "));
const QMessageBox::Button res =
QInstaller::MessageBoxHandler::critical(QInstaller::MessageBoxHandler::currentBestSuitParent(),
@@ -800,11 +801,9 @@ void FSEngineClientHandler::Private::maybeStartServer()
serverStarted = QProcess::startDetached(serverCommand, serverArguments);
}
- // now wait for the socket to arrive
- QTcpSocket s;
- while (serverStarting && serverStarted) {
- if (FSEngineClientHandler::instance().connect(&s))
- serverStarting = false;
+ if (serverStarted) {
+ QTcpSocket s; // now wait for the socket to arrive
+ serverStarted = FSEngineClientHandler::instance().connect(&s);
}
serverStarting = false;
}