mirror of
https://github.com/jwinterm/xmr-stak.git
synced 2026-10-22 06:28:36 +02:00
Non-manifest UAC elevation
This commit is contained in:
@@ -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
|
||||
################################################################################
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user