diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | xmrstak/cli/cli-miner.cpp | 11 | ||||
-rw-r--r-- | xmrstak/misc/uac.hpp | 44 |
3 files changed, 54 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0da4f06..3c7a585 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -401,10 +401,6 @@ set(LIBRARY_OUTPUT_PATH "bin") target_link_libraries(xmr-stak ${LIBS} xmr-stak-c xmr-stak-backend) -if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - set_property(TARGET xmr-stak PROPERTY LINK_FLAGS "/level='requireAdministrator' /uiAccess='false'") -endif() - ################################################################################ # Install ################################################################################ diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index ff31d2c..fbd5039 100644 --- a/xmrstak/cli/cli-miner.cpp +++ b/xmrstak/cli/cli-miner.cpp @@ -33,7 +33,11 @@ #include "xmrstak/version.hpp" #ifndef CONF_NO_HTTPD -# include "xmrstak/http//httpd.hpp" +# include "xmrstak/http/httpd.hpp" +#endif + +#ifdef _WIN32 +# include "xmrstak/misc/uac.hpp" #endif #include <stdlib.h> @@ -88,6 +92,11 @@ void help() int main(int argc, char *argv[]) { +#ifdef _WIN32 + if (!IsElevated() && SelfElevate(argv[0])) + return 0; +#endif + #ifndef CONF_NO_TLS SSL_library_init(); SSL_load_error_strings(); 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; +} |