diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-13 00:36:59 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-13 00:39:55 +0200 |
| commit | 190ff781eaee33e7a61aab44fc4133718cc0515b (patch) | |
| tree | 469cedfc87734589a4e9a0102f69324b9edb8f16 /src/process.cpp | |
| parent | cmake: upgrade minimum version (diff) | |
| download | privilege-check-190ff781eaee33e7a61aab44fc4133718cc0515b.tar.gz privilege-check-190ff781eaee33e7a61aab44fc4133718cc0515b.zip | |
add .clang-format
Diffstat (limited to 'src/process.cpp')
| -rw-r--r-- | src/process.cpp | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/src/process.cpp b/src/process.cpp index a2eddc0..b71bff0 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -3,60 +3,54 @@ // For details, see https://github.com/egor-tensin/privilege-check. // Distributed under the MIT License. +#include "process.hpp" + #include "cmd_line.hpp" #include "error.hpp" -#include "process.hpp" +/* clang-format off */ #include <windows.h> #include <shellapi.h> +/* clang-format on */ #include <array> #include <string> -namespace process -{ - std::wstring get_executable_path() - { - static constexpr DWORD max_path = MAX_PATH; +namespace process { - std::array<wchar_t, max_path> buf; +std::wstring get_executable_path() { + static constexpr DWORD max_path = MAX_PATH; - const auto ret = GetModuleFileNameW(NULL, buf.data(), max_path); + std::array<wchar_t, max_path> buf; - if (ret != ERROR_SUCCESS) - error::raise("GetModuleFileNameW"); + const auto ret = GetModuleFileNameW(NULL, buf.data(), max_path); - return buf.data(); - } + if (ret != ERROR_SUCCESS) + error::raise("GetModuleFileNameW"); - void runas( - const CommandLine& cmd_line, - HWND hwnd, - int nShow) - { - const auto exe_path = cmd_line.has_argv0() - ? cmd_line.get_argv0() - : get_executable_path(); + return buf.data(); +} - 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; +void runas(const CommandLine& cmd_line, HWND hwnd, int nShow) { + const auto exe_path = cmd_line.has_argv0() ? cmd_line.get_argv0() : get_executable_path(); - if (!ShellExecuteExW(&info)) - error::raise("ShellExecuteExW"); - } + 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; - void runas_self( - HWND hwnd, - int nShow) - { - runas(CommandLine::query(), hwnd, nShow); - } + if (!ShellExecuteExW(&info)) + error::raise("ShellExecuteExW"); } + +void runas_self(HWND hwnd, int nShow) { + runas(CommandLine::query(), hwnd, nShow); +} + +} // namespace process |
