summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUnknown <fireice-uk@users.noreply.github.com>2017-12-25 17:30:52 +0000
committerUnknown <fireice-uk@users.noreply.github.com>2017-12-25 17:30:52 +0000
commit5e5888bff84eb98932df1852ef57ff6ebfc0be56 (patch)
tree7d07678a99fdafada80d229fab950bd4b6482cd2
parent038a4eb34d40abac8d0242f9ca881b0dac344723 (diff)
downloadxmr-stak-5e5888bff84eb98932df1852ef57ff6ebfc0be56.zip
xmr-stak-5e5888bff84eb98932df1852ef57ff6ebfc0be56.tar.gz
fix windows build
-rw-r--r--xmrstak/misc/uac.cpp67
-rw-r--r--xmrstak/misc/uac.hpp64
2 files changed, 70 insertions, 61 deletions
diff --git a/xmrstak/misc/uac.cpp b/xmrstak/misc/uac.cpp
new file mode 100644
index 0000000..4fb5b0c
--- /dev/null
+++ b/xmrstak/misc/uac.cpp
@@ -0,0 +1,67 @@
+#pragma once
+
+#ifdef _WIN32
+#include "xmrstak/misc/console.hpp"
+#include "xmrstak/params.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 std::string& 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.c_str();
+ 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;
+}
+
+VOID RequestElevation()
+{
+ if(IsElevated())
+ return;
+
+ if(!xmrstak::params::inst().allowUAC)
+ {
+ printer::inst()->print_msg(L0, "The miner needs to run as administrator, but you passed --noUAC option. Please remove it or set use_slow_memory to always.");
+ win_exit();
+ return;
+ }
+
+ SelfElevate(xmrstak::params::inst().minerArg0, xmrstak::params::inst().minerArgs);
+}
+#endif
diff --git a/xmrstak/misc/uac.hpp b/xmrstak/misc/uac.hpp
index 4fb5b0c..82cdf42 100644
--- a/xmrstak/misc/uac.hpp
+++ b/xmrstak/misc/uac.hpp
@@ -1,67 +1,9 @@
#pragma once
#ifdef _WIN32
-#include "xmrstak/misc/console.hpp"
-#include "xmrstak/params.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 std::string& 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.c_str();
- 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;
-}
-
-VOID RequestElevation()
-{
- if(IsElevated())
- return;
-
- if(!xmrstak::params::inst().allowUAC)
- {
- printer::inst()->print_msg(L0, "The miner needs to run as administrator, but you passed --noUAC option. Please remove it or set use_slow_memory to always.");
- win_exit();
- return;
- }
- SelfElevate(xmrstak::params::inst().minerArg0, xmrstak::params::inst().minerArgs);
-}
+BOOL IsElevated();
+BOOL SelfElevate(const std::string& my_path, const std::string& params);
+VOID RequestElevation();
#endif
OpenPOWER on IntegriCloud