summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfireice-uk <fireice-uk@users.noreply.github.com>2017-10-04 22:11:31 +0100
committerfireice-uk <fireice-uk@users.noreply.github.com>2017-10-04 22:11:31 +0100
commitd8d403b2ace66ba05c9c6ff9da35361920fde908 (patch)
treebaa3259691ff3dd4b179398b260f12479fdf2a88
parent2b9bcc2dfd835d3c0a6a7de3f5f224c9afd5434b (diff)
downloadxmr-stak-d8d403b2ace66ba05c9c6ff9da35361920fde908.zip
xmr-stak-d8d403b2ace66ba05c9c6ff9da35361920fde908.tar.gz
Non-manifest UAC elevation
-rw-r--r--CMakeLists.txt4
-rw-r--r--xmrstak/cli/cli-miner.cpp11
-rw-r--r--xmrstak/misc/uac.hpp44
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;
+}
OpenPOWER on IntegriCloud