-
Notifications
You must be signed in to change notification settings - Fork 0
/
BootSetup.cpp
47 lines (40 loc) · 1.3 KB
/
BootSetup.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
#include "stdafx.h"
#include "BootSetup.h"
#include <shellapi.h>
int BootSetup::GetSystemFirmwareType()
{
Grass7API::Privilege::ModifyPrivilege(SE_SYSTEM_ENVIRONMENT_NAME, TRUE, GetCurrentProcess());
if (GetFirmwareEnvironmentVariableW(L"", _T("{00000000-0000-0000-0000-000000000000}"), NULL, 0) == 0) {
if (GetLastError() == ERROR_INVALID_FUNCTION) {
return 1; // BIOS
}
else if (GetLastError() == ERROR_NOACCESS) {
return 2; // UEFI
}
}
return 0; // ERROR
}
void BootSetup::SetupSystemBoot()
{
wchar_t WindowsFolder[MAX_PATH];
wcsncpy_s(WindowsFolder, ImageInstallObjects.destDrive.c_str(), sizeof(WindowsFolder));
#pragma warning(suppress : 6054; suppress : 4129)
wcsncat_s(WindowsFolder, L"\Windows", sizeof(WindowsFolder));
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"open";
ShExecInfo.lpFile = L"bcdboot";
ShExecInfo.lpParameters = WindowsFolder;
ShExecInfo.lpDirectory = ImageInstallObjects.installSources.c_str();
if (MainObjects.Debug) {
ShExecInfo.nShow = SW_SHOW;
} else {
ShExecInfo.nShow = SW_HIDE;
}
ShExecInfo.hInstApp = NULL;
ShellExecuteExW(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
CloseHandle(ShExecInfo.hProcess);
}