diff options
author | psychocrypt <psychocryptHPC@gmail.com> | 2017-12-26 23:37:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-26 23:37:38 +0100 |
commit | 85edb88f2919eaba4a44fad372229a144fffa868 (patch) | |
tree | 2e39df6dc5c41e2e359f62bd79a9cf5846966236 /xmrstak/misc/uac.hpp | |
parent | 756466de67907ab4bcfdd1b0235c14b585f62347 (diff) | |
parent | b216f39a52d87e48b2399da5e3272a9a464ac359 (diff) | |
download | xmr-stak-85edb88f2919eaba4a44fad372229a144fffa868.zip xmr-stak-85edb88f2919eaba4a44fad372229a144fffa868.tar.gz |
Merge pull request #702 from fireice-uk/topic-on-demand-elevation
On-demand elevation
Diffstat (limited to 'xmrstak/misc/uac.hpp')
-rw-r--r-- | xmrstak/misc/uac.hpp | 49 |
1 files changed, 4 insertions, 45 deletions
diff --git a/xmrstak/misc/uac.hpp b/xmrstak/misc/uac.hpp index 55c5f1a..33c79ae 100644 --- a/xmrstak/misc/uac.hpp +++ b/xmrstak/misc/uac.hpp @@ -1,51 +1,10 @@ #pragma once #ifdef _WIN32 -#include "xmrstak/misc/console.hpp" - #include <string> -#include <windows.h> - -BOOL IsElevated() -{ - BOOL fRet = FALSE; - HANDLE hToken = NULL; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) - { - TOKEN_ELEVATION Elevation; - DWORD cbSize = sizeof(TOKEN_ELEVATION); - if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) - fRet = Elevation.TokenIsElevated; - } - if (hToken) - CloseHandle(hToken); - return fRet; -} - -BOOL SelfElevate(const char* my_path, const std::string& params) -{ - if (IsElevated()) - return FALSE; - - SHELLEXECUTEINFO shExecInfo = { 0 }; - shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); - shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; - shExecInfo.hwnd = NULL; - shExecInfo.lpVerb = "runas"; - shExecInfo.lpFile = my_path; - shExecInfo.lpParameters = params.c_str(); - shExecInfo.lpDirectory = NULL; - shExecInfo.nShow = SW_SHOW; - shExecInfo.hInstApp = NULL; - - if (!ShellExecuteEx(&shExecInfo)) - return FALSE; - - // Loiter in the background to make scripting easier - printer::inst()->print_msg(L0, "This window has been opened because xmr-stak needed to run as administrator. It can be safely closed now."); - WaitForSingleObject(shExecInfo.hProcess, INFINITE); - std::exit(0); - return TRUE; -} +BOOL IsElevated(); +BOOL SelfElevate(const std::string& my_path, const std::string& params); +VOID RequestElevation(); +BOOL IsWindows10OrNewer(); #endif |