diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-03-22 08:30:17 +0100 |
---|---|---|
committer | Sami Nurmenniemi <sami.nurmenniemi@qt.io> | 2018-04-06 13:21:23 +0000 |
commit | 5d1769c5a2145d760a2444aa0c3b91ce10ac38bb (patch) | |
tree | e06a3181e9d6ece86a964b99b54ea331857e7888 /src/shared | |
parent | e822ffb968ca1e6999de17db5b5d6d36b3825378 (diff) |
winutils: Add possibility to run elevated background processes
In order to add localhost server support for winrt applications, we need
to be able to run elevated applications in the background. As a
preparation for this next patch, the new function is introduced. As
winrtrunner is not supported on OSs other than Windows, it is fine to
omit the implementation of this function on these operating systems for
now.
Change-Id: Iedb74a391e07a2b637f13bef84ad50c746dd8f0a
Reviewed-by: Andre de la Rocha <andre.rocha@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/winutils/utils.cpp | 39 | ||||
-rw-r--r-- | src/shared/winutils/utils.h | 1 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/shared/winutils/utils.cpp b/src/shared/winutils/utils.cpp index 0e0c4e4cc..8f9cc198a 100644 --- a/src/shared/winutils/utils.cpp +++ b/src/shared/winutils/utils.cpp @@ -303,6 +303,36 @@ bool runProcess(const QString &binary, const QStringList &args, return true; } +bool runElevatedBackgroundProcess(const QString &binary, const QStringList &args, Qt::HANDLE *processHandle) +{ + QScopedArrayPointer<wchar_t> binaryW(new wchar_t[binary.size() + 1]); + binary.toWCharArray(binaryW.data()); + binaryW[binary.size()] = 0; + + const QString arguments = args.join(QLatin1Char(' ')); + QScopedArrayPointer<wchar_t> argumentsW(new wchar_t[arguments.size() + 1]); + arguments.toWCharArray(argumentsW.data()); + argumentsW[arguments.size()] = 0; + + SHELLEXECUTEINFO shellExecute = {0}; + shellExecute.cbSize = sizeof(shellExecute); + shellExecute.fMask = SEE_MASK_NOCLOSEPROCESS; + shellExecute.hwnd = 0; + shellExecute.lpVerb = L"runas"; // causes elevation + shellExecute.lpFile = binaryW.data(); + shellExecute.lpParameters = argumentsW.data(); + shellExecute.lpDirectory = 0; + shellExecute.nShow = SW_SHOW; + shellExecute.hInstApp = 0; + + bool ret = ShellExecuteEx(&shellExecute); + + if (processHandle) + *processHandle = shellExecute.hProcess; + + return ret; +} + #else // Q_OS_WIN static inline char *encodeFileName(const QString &f) @@ -432,6 +462,15 @@ bool runProcess(const QString &binary, const QStringList &args, return true; } +bool runElevatedBackgroundProcess(const QString &binary, const QStringList &args, Qt::HANDLE *processHandle) +{ + Q_UNUSED(binary); + Q_UNUSED(args); + Q_UNUSED(processHandle); + Q_UNIMPLEMENTED(); + return false; +} + #endif // !Q_OS_WIN // Find a file in the path using ShellAPI. This can be used to locate DLLs which diff --git a/src/shared/winutils/utils.h b/src/shared/winutils/utils.h index e25a5630b..a5e6f01f7 100644 --- a/src/shared/winutils/utils.h +++ b/src/shared/winutils/utils.h @@ -181,6 +181,7 @@ bool runProcess(const QString &binary, const QStringList &args, const QString &workingDirectory = QString(), unsigned long *exitCode = 0, QByteArray *stdOut = 0, QByteArray *stdErr = 0, QString *errorMessage = 0); +bool runElevatedBackgroundProcess(const QString &binary, const QStringList &args, Qt::HANDLE *processHandle); bool readPeExecutable(const QString &peExecutableFileName, QString *errorMessage, QStringList *dependentLibraries = 0, unsigned *wordSize = 0, |