Skip to content
Snippets Groups Projects
Commit d8d403b2 authored by fireice-uk's avatar fireice-uk
Browse files

Non-manifest UAC elevation

parent 2b9bcc2d
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment