summaryrefslogtreecommitdiffstats
path: root/xmrstak/misc
diff options
context:
space:
mode:
authorpsychocrypt <psychocrypt@users.noreply.github.com>2017-10-05 22:15:32 +0200
committerGitHub <noreply@github.com>2017-10-05 22:15:32 +0200
commite96a761d5a748ab06749a18db5e16d87739d7716 (patch)
tree5619ff90e4701dd22a39cac4cee27a217b00f54c /xmrstak/misc
parent34a87c64a19cbdd9f73eb0142b9e6f3f573e726e (diff)
parentf6b310dc86ec437c6df0f0f036f763bbdf010cba (diff)
downloadxmr-stak-e96a761d5a748ab06749a18db5e16d87739d7716.zip
xmr-stak-e96a761d5a748ab06749a18db5e16d87739d7716.tar.gz
Merge pull request #12 from fireice-uk/topic-large-pages-win
Fix large pages on Windows and make them more user-friendly
Diffstat (limited to 'xmrstak/misc')
-rw-r--r--xmrstak/misc/uac.hpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/xmrstak/misc/uac.hpp b/xmrstak/misc/uac.hpp
new file mode 100644
index 0000000..fdf3be9
--- /dev/null
+++ b/xmrstak/misc/uac.hpp
@@ -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;
+}
OpenPOWER on IntegriCloud