-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBoxInit.cpp
50 lines (39 loc) · 1.21 KB
/
RBoxInit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by hx1997 on 2018/3/8.
//
#include <windows.h>
#include "utils/OSVersionUtils.h"
#include "utils/TokenUtils.h"
#include "RBoxMessage.h"
#include "RBoxRun.h"
int CheckOS();
int RestartElevated();
Sandbox *InitRightsBox() {
// Check Windows version since we rely heavily on Vista+ security features
if (CheckOS() != ERROR_SUCCESS)
return nullptr;
// Make sure we run with administrative rights to prevent UAC elevation of sandboxed processes
if (!IsAdmin()) {
IssueMessage("Administrative rights required. Press any key to restart elevated.", MSGTYPE_INFO);
system("pause");
RestartElevated();
return nullptr;
}
return new Sandbox();
}
int CheckOS() {
if (!IsWindowsVistaOrGreater()) {
IssueMessage("Unsupported OS! Exiting...", MSGTYPE_ERROR);
return ERROR_NOT_SUPPORTED;
}
return ERROR_SUCCESS;
}
int RestartElevated() {
WCHAR szModulePath[MAX_PATH];
// Get path to the RightsBox executable itself
if (!GetModuleFileName(nullptr, szModulePath, MAX_PATH))
return -1;
if ((int)ShellExecute(nullptr, L"runas", szModulePath, nullptr, nullptr, SW_SHOWNORMAL) <= 32)
return -1;
return 0;
}