-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestartGuard.c
48 lines (41 loc) · 1.07 KB
/
RestartGuard.c
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
#include <windows.h>
void main()
{
HANDLE mutex;
mutex = CreateMutex(NULL, TRUE, "RestartGuard.DoubleBootLock");
if (GetLastError() == ERROR_ALREADY_EXISTS)
return;
while (1) {
SYSTEMTIME systemTime;
DWORD activeHoursEnd, activeHoursStart = 0;
HKEY hKey = {0};
GetLocalTime(&systemTime);
if (systemTime.wHour < 6)
activeHoursStart = 24;
activeHoursStart += systemTime.wHour - 6;
activeHoursEnd = systemTime.wHour + 6;
if (activeHoursEnd >= 24)
activeHoursEnd -= 24;
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\WindowsUpdate\\UX\\Settings\\",
0, KEY_WRITE, &hKey);
if (GetLastError() != ERROR_SUCCESS)
break;
RegSetValueEx(hKey,
"ActiveHoursStart",
0,
REG_DWORD,
(CONST BYTE *)&activeHoursStart,
sizeof(activeHoursStart));
RegSetValueEx(hKey,
"ActiveHoursEnd",
0,
REG_DWORD,
(CONST BYTE *)&activeHoursEnd,
sizeof(activeHoursEnd));
RegCloseKey(hKey);
Sleep((60 - systemTime.wMinute) * 60 * 1000);
}
CloseHandle(mutex);
return;
}