diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-11 14:30:12 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-11 14:30:12 +0300 |
commit | 52559c87c3ac5fba05f62bff7cf8294a4b24c9c4 (patch) | |
tree | 8e87e54e8eda91fc0ee55906855dc3ecef548f8b /src/process.hpp | |
parent | hardening (diff) | |
download | privilege-check-52559c87c3ac5fba05f62bff7cf8294a4b24c9c4.tar.gz privilege-check-52559c87c3ac5fba05f62bff7cf8294a4b24c9c4.zip |
inherit parent's parameters in new processes
Command line parameters, that is.
Diffstat (limited to '')
-rw-r--r-- | src/process.hpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/process.hpp b/src/process.hpp index 8279c3c..6fbaf8a 100644 --- a/src/process.hpp +++ b/src/process.hpp @@ -5,6 +5,7 @@ #pragma once +#include "cmd_line.hpp" #include "error.hpp" #include <Windows.h> @@ -29,17 +30,41 @@ namespace process return buf.data(); } - void runas(const std::wstring& exe_path, HWND hwnd = NULL, int nShow = SW_NORMAL) + std::wstring get_command_line() { + return GetCommandLine(); + } + + void runas( + const CommandLine& cmd_line, + HWND hwnd = NULL, + int nShow = SW_NORMAL) + { + static constexpr auto sep = L' '; + + const auto exe_path = cmd_line.has_argv0() + ? cmd_line.get_argv0() + : get_executable_path(); + SHELLEXECUTEINFOW info; ZeroMemory(&info, sizeof(info)); info.cbSize = sizeof(info); info.lpVerb = L"runas"; info.lpFile = exe_path.c_str(); + const auto args = cmd_line.join_args(); + if (!args.empty()) + info.lpParameters = args.c_str(); info.hwnd = hwnd; info.nShow = nShow; if (!ShellExecuteExW(&info)) error::raise("ShellExecuteExW"); } + + void runas_self( + HWND hwnd = NULL, + int nShow = SW_NORMAL) + { + runas(CommandLine::query(), hwnd, nShow); + } } |