Stop UAC popup for elevated ctx

This commit is contained in:
fireice-uk
2017-12-21 20:49:01 +00:00
parent a71b1aea05
commit c4391ac6f3
2 changed files with 16 additions and 43 deletions
+3 -37
View File
@@ -52,6 +52,7 @@
#ifdef _WIN32
# define strcasecmp _stricmp
# include <windows.h>
# include "xmrstak/misc/uac.hpp"
#endif // _WIN32
void do_benchmark();
@@ -309,41 +310,6 @@ void do_guided_config()
std::cout<<"Configuration stored in file '"<<params::inst().configFile<<"'"<<std::endl;
}
#ifdef _WIN32
/** start the miner as administrator
*
* This function based on the stackoverflow post
* - source: https://stackoverflow.com/a/4893508
* - author: Cody Gray
* - date: Feb 4 '11
*/
void UACDialog(const std::string& binaryName, std::string& args)
{
args += " --noUAC";
SHELLEXECUTEINFO shExInfo = {0};
shExInfo.cbSize = sizeof(shExInfo);
shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExInfo.hwnd = 0;
shExInfo.lpVerb = "runas";
shExInfo.lpFile = binaryName.c_str();
// disable UAC dialog (else the miner will go into a infinite loop)
shExInfo.lpParameters = args.c_str();
shExInfo.lpDirectory = 0;
shExInfo.nShow = SW_SHOW;
shExInfo.hInstApp = 0;
if(ShellExecuteEx(&shExInfo))
{
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(shExInfo.hProcess, INFINITE);
CloseHandle(shExInfo.hProcess);
// do not start the miner twice
std::exit(0);
}
}
#endif
int main(int argc, char *argv[])
{
#ifndef CONF_NO_TLS
@@ -551,7 +517,7 @@ int main(int argc, char *argv[])
}
#ifdef _WIN32
if(uacDialog)
if(uacDialog && !IsElevated())
{
std::string minerArgs;
for(int i = 1; i < argc; i++)
@@ -560,7 +526,7 @@ int main(int argc, char *argv[])
minerArgs += argv[i];
}
UACDialog(argv[0], minerArgs);
SelfElevate(argv[0], minerArgs);
}
#endif
+13 -6
View File
@@ -1,4 +1,9 @@
#pragma once
#ifdef _WIN32
#include "xmrstak/misc/console.hpp"
#include <string>
#include <windows.h>
BOOL IsElevated()
@@ -17,18 +22,18 @@ BOOL IsElevated()
return fRet;
}
BOOL SelfElevate(const char* my_path)
BOOL SelfElevate(const char* my_path, const std::string& params)
{
if (IsElevated())
return FALSE;
SHELLEXECUTEINFO shExecInfo = { 0 };
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = NULL;
shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = "runas";
shExecInfo.lpFile = my_path;
shExecInfo.lpParameters = NULL;
shExecInfo.lpParameters = params.c_str();
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_SHOW;
shExecInfo.hInstApp = NULL;
@@ -36,9 +41,11 @@ BOOL SelfElevate(const char* my_path)
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);
// 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;
}
#endif