diff options
Diffstat (limited to 'xmrstak')
-rw-r--r-- | xmrstak/backend/cpu/crypto/cryptonight_common.cpp | 4 | ||||
-rw-r--r-- | xmrstak/cli/cli-miner.cpp | 31 | ||||
-rw-r--r-- | xmrstak/misc/uac.hpp | 20 | ||||
-rw-r--r-- | xmrstak/params.hpp | 4 |
4 files changed, 41 insertions, 18 deletions
diff --git a/xmrstak/backend/cpu/crypto/cryptonight_common.cpp b/xmrstak/backend/cpu/crypto/cryptonight_common.cpp index 8b2207d..583deff 100644 --- a/xmrstak/backend/cpu/crypto/cryptonight_common.cpp +++ b/xmrstak/backend/cpu/crypto/cryptonight_common.cpp @@ -73,6 +73,8 @@ void do_skein_hash(const void* input, size_t len, char* output) { void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash}; #ifdef _WIN32 +#include "xmrstak/misc/uac.hpp" + BOOL bRebootDesirable = FALSE; //If VirtualAlloc fails, suggest a reboot BOOL AddPrivilege(TCHAR* pszPrivilege) @@ -176,6 +178,8 @@ size_t cryptonight_init(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg) if(AddPrivilege(TEXT("SeLockMemoryPrivilege")) == 0) { + RequestElevation(); + if(AddLargePageRights()) { msg->warning = "Added SeLockMemoryPrivilege to the current account. You need to reboot for it to work"; diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index b84b783..4904604 100644 --- a/xmrstak/cli/cli-miner.cpp +++ b/xmrstak/cli/cli-miner.cpp @@ -342,7 +342,14 @@ int main(int argc, char *argv[]) params::inst().executablePrefix += seperator; } - bool uacDialog = true; + params::inst().minerArg0 = argv[0]; + params::inst().minerArgs.reserve(argc * 16); + for(int i = 1; i < argc; i++) + { + params::inst().minerArgs += " "; + params::inst().minerArgs += argv[i]; + } + bool pool_url_set = false; for(size_t i = 1; i < argc-1; i++) { @@ -506,7 +513,7 @@ int main(int argc, char *argv[]) } else if(opName.compare("--noUAC") == 0) { - uacDialog = false; + params::inst().allowUAC = false; } else { @@ -516,20 +523,6 @@ int main(int argc, char *argv[]) } } -#ifdef _WIN32 - if(uacDialog && !IsElevated()) - { - std::string minerArgs; - for(int i = 1; i < argc; i++) - { - minerArgs += " "; - minerArgs += argv[i]; - } - - SelfElevate(argv[0], minerArgs); - } -#endif - // check if we need a guided start if(!configEditor::file_exist(params::inst().configFile)) do_guided_config(); @@ -540,6 +533,12 @@ int main(int argc, char *argv[]) return 1; } +#ifdef _WIN32 + /* For Windows 7 and 8 request elevation at all times unless we are using slow memory */ + if(jconf::inst()->GetSlowMemSetting() != jconf::slow_mem_cfg::always_use && LOBYTE(LOWORD(GetVersion())) < 10) + RequestElevation(); +#endif + if (!BackendConnector::self_test()) { win_exit(); diff --git a/xmrstak/misc/uac.hpp b/xmrstak/misc/uac.hpp index 55c5f1a..4fb5b0c 100644 --- a/xmrstak/misc/uac.hpp +++ b/xmrstak/misc/uac.hpp @@ -2,6 +2,7 @@ #ifdef _WIN32 #include "xmrstak/misc/console.hpp" +#include "xmrstak/params.hpp" #include <string> #include <windows.h> @@ -22,7 +23,7 @@ BOOL IsElevated() return fRet; } -BOOL SelfElevate(const char* my_path, const std::string& params) +BOOL SelfElevate(const std::string& my_path, const std::string& params) { if (IsElevated()) return FALSE; @@ -32,7 +33,7 @@ BOOL SelfElevate(const char* my_path, const std::string& params) shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = "runas"; - shExecInfo.lpFile = my_path; + shExecInfo.lpFile = my_path.c_str(); shExecInfo.lpParameters = params.c_str(); shExecInfo.lpDirectory = NULL; shExecInfo.nShow = SW_SHOW; @@ -48,4 +49,19 @@ BOOL SelfElevate(const char* my_path, const std::string& params) 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/params.hpp b/xmrstak/params.hpp index bc32612..4cc041c 100644 --- a/xmrstak/params.hpp +++ b/xmrstak/params.hpp @@ -38,6 +38,10 @@ struct params std::string configFileNVIDIA; std::string configFileCPU; + bool allowUAC = true; + std::string minerArg0; + std::string minerArgs; + params() : binaryName("xmr-stak"), executablePrefix(""), |