diff options
Diffstat (limited to 'xmrstak/misc')
-rw-r--r-- | xmrstak/misc/executor.cpp | 4 | ||||
-rw-r--r-- | xmrstak/misc/uac.hpp | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp index f2bdad4..ec9ac12 100644 --- a/xmrstak/misc/executor.cpp +++ b/xmrstak/misc/executor.cpp @@ -911,8 +911,8 @@ void executor::http_json_report(std::string& out) if(iPoolCallTimes.size() > 0) fAvgResTime = double(iConnSec) / iPoolCallTimes.size(); + char buffer[2048]; res_error.reserve((vMineResults.size() - 1) * 128); - char buffer[256]; for(size_t i=1; i < vMineResults.size(); i++) { using namespace std::chrono; @@ -933,7 +933,7 @@ void executor::http_json_report(std::string& out) iPoolPing = iPoolCallTimes[n_calls/2]; } - cn_error.reserve(vSocketLog.size() * 128); + cn_error.reserve(vSocketLog.size() * 256); for(size_t i=0; i < vSocketLog.size(); i++) { using namespace std::chrono; diff --git a/xmrstak/misc/uac.hpp b/xmrstak/misc/uac.hpp new file mode 100644 index 0000000..fdf3be9 --- /dev/null +++ b/xmrstak/misc/uac.hpp @@ -0,0 +1,44 @@ +#pragma once +#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) +{ + if (IsElevated()) + return FALSE; + + SHELLEXECUTEINFO shExecInfo = { 0 }; + shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + shExecInfo.fMask = NULL; + shExecInfo.hwnd = NULL; + shExecInfo.lpVerb = "runas"; + shExecInfo.lpFile = my_path; + shExecInfo.lpParameters = NULL; + shExecInfo.lpDirectory = NULL; + shExecInfo.nShow = SW_SHOW; + shExecInfo.hInstApp = NULL; + + if (!ShellExecuteEx(&shExecInfo)) + return FALSE; + + // Hide our window and loiter in the background to make scripting easier + // ShowWindow(GetConsoleWindow(), SW_HIDE); + // WaitForSingleObject(shExecInfo.hProcess, INFINITE); + + return TRUE; +} |