23 std::ostringstream oss;
24 oss <<
"-NoProfile -ExecutionPolicy Bypass -Command \"" << psCommand <<
"\"";
25 const std::string argStr = oss.str();
28 auto toWide = [](
const std::string& s) -> std::wstring
31 return std::wstring();
32 int needed = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (
int)s.size(),
nullptr, 0);
33 std::wstring ws(needed, L
'\0');
34 MultiByteToWideChar(CP_UTF8, 0, s.c_str(), (
int)s.size(), ws.data(), needed);
38 const std::wstring wExe = L
"powershell.exe";
39 const std::wstring wArgs = toWide(argStr);
41 SHELLEXECUTEINFOW sei{};
42 sei.cbSize =
sizeof(sei);
43 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
45 sei.lpVerb = L
"runas";
46 sei.lpFile = wExe.c_str();
47 sei.lpParameters = wArgs.c_str();
50 if (!ShellExecuteExW(&sei))
57 WaitForSingleObject(sei.hProcess, INFINITE);
58 CloseHandle(sei.hProcess);