forked from programmerjake/preyproject-lock-screen
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpersistent.cpp
643 lines (559 loc) · 21 KB
/
persistent.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
#define NTDDI_VERSION (0x06020000)
#define _WIN32_WINNT (0x0602)
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif !defined(UNICODE) && defined(_UNICODE)
#define UNICODE
#endif
#define NOMINMAX
#include <windows.h>
#include <wtsapi32.h>
#include <tchar.h>
#include <sddl.h>
#include <iostream>
#include "get_option.h"
#define REGISTRY_SETTINGS_LOCATION "Software\\Prey\\lock-screen"
#ifndef ERROR_ELEVATION_REQUIRED
#define ERROR_ELEVATION_REQUIRED (740)
#endif // ERROR_ELEVATION_REQUIRED
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
#ifdef UNICODE
typedef std::wstring tstring;
typedef std::wostringstream tostringstream;
typedef std::wistringstream tistringstream;
typedef wget_option tget_option;
#define Tcout (::std::wcout)
#define Tcerr (::std::wcerr)
#else
typedef std::string tstring;
typedef std::ostringstream tostringstream;
typedef std::istringstream tistringstream;
typedef get_option tget_option;
#define Tcout (::std::cout)
#define Tcerr (::std::cerr)
#endif // UNICODE
bool verbose = true;
struct PersistentSystemOptions final
{
bool hasLockComputer;
bool hasSwitchUser;
bool hasLogOff;
bool hasChangePassword;
bool hasTaskManager;
bool hasPower;
bool hasFilterKeysHotkey;
bool hasMouseKeysHotkey;
bool hasStickyKeysHotkey;
bool hasToggleKeysHotkey;
bool hasHighContrastHotkey;
bool hasFastBootHotKey;
PersistentSystemOptions(bool enabled = true)
: hasLockComputer(enabled),
hasSwitchUser(enabled),
hasLogOff(enabled),
hasChangePassword(enabled),
hasTaskManager(enabled),
hasPower(enabled),
hasFilterKeysHotkey(enabled),
hasMouseKeysHotkey(enabled),
hasStickyKeysHotkey(enabled),
hasToggleKeysHotkey(enabled),
hasFastBootHotKey(enabled),
hasHighContrastHotkey(enabled)
{
}
static PersistentSystemOptions AllDisabled()
{
return PersistentSystemOptions(false);
}
static PersistentSystemOptions AllEnabled()
{
return PersistentSystemOptions(true);
}
static PersistentSystemOptions ReadSystemSettings();
bool WriteSystemSettings() const;
static PersistentSystemOptions ReadFromStorage();
bool WriteToStorage() const;
std::ostream &Dump(std::ostream &os) const
{
os << "hasLockComputer = " << (hasLockComputer ? "true\n" : "false\n");
os << "hasSwitchUser = " << (hasSwitchUser ? "true\n" : "false\n");
os << "hasLogOff = " << (hasLogOff ? "true\n" : "false\n");
os << "hasChangePassword = " << (hasChangePassword ? "true\n" : "false\n");
os << "hasTaskManager = " << (hasTaskManager ? "true\n" : "false\n");
os << "hasPower = " << (hasPower ? "true\n" : "false\n");
os << "hasFilterKeysHotkey = " << (hasFilterKeysHotkey ? "true\n" : "false\n");
os << "hasMouseKeysHotkey = " << (hasMouseKeysHotkey ? "true\n" : "false\n");
os << "hasStickyKeysHotkey = " << (hasStickyKeysHotkey ? "true\n" : "false\n");
os << "hasToggleKeysHotkey = " << (hasToggleKeysHotkey ? "true\n" : "false\n");
os << "hasHighContrastHotkey = " << (hasHighContrastHotkey ? "true\n" : "false\n");
os << "hasFastBootHotkey = " << (hasFastBootHotKey ? "true\n" : "false\n");
return os;
}
std::wostream &Dump(std::wostream &os) const
{
os << L"hasLockComputer = " << (hasLockComputer ? L"true\n" : L"false\n");
os << L"hasSwitchUser = " << (hasSwitchUser ? L"true\n" : L"false\n");
os << L"hasLogOff = " << (hasLogOff ? L"true\n" : L"false\n");
os << L"hasChangePassword = " << (hasChangePassword ? L"true\n" : L"false\n");
os << L"hasTaskManager = " << (hasTaskManager ? L"true\n" : L"false\n");
os << L"hasPower = " << (hasPower ? L"true\n" : L"false\n");
os << L"hasFilterKeysHotkey = " << (hasFilterKeysHotkey ? L"true\n" : L"false\n");
os << L"hasMouseKeysHotkey = " << (hasMouseKeysHotkey ? L"true\n" : L"false\n");
os << L"hasStickyKeysHotkey = " << (hasStickyKeysHotkey ? L"true\n" : L"false\n");
os << L"hasToggleKeysHotkey = " << (hasToggleKeysHotkey ? L"true\n" : L"false\n");
os << L"hasHighContrastHotkey = " << (hasHighContrastHotkey ? L"true\n" : L"false\n");
os << L"hasFastBootHotkey = " << (hasFastBootHotKey ? L"true\n" : L"false\n");
return os;
}
private:
static bool ReadRegistryKey(HKEY baseHive, tstring path, tstring name, bool defaultValue);
static bool WriteRegistryKey(HKEY baseHive, tstring path, tstring name, bool value);
static bool ReadFilterKeysHotkey();
static bool WriteFilterKeysHotkey(bool value);
static bool ReadMouseKeysHotkey();
static bool WriteMouseKeysHotkey(bool value);
static bool ReadStickyKeysHotkey();
static bool WriteStickyKeysHotkey(bool value);
static bool ReadToggleKeysHotkey();
static bool WriteToggleKeysHotkey(bool value);
static bool ReadHighContrastHotkey();
static bool WriteHighContrastHotkey(bool value);
static bool ReadFastBootHotkey();
static bool WriteFastBootHotkey(bool value);
};
bool getActiveConsoleId(LPDWORD id) {
PWTS_SESSION_INFO sessioninfo;
DWORD count;
if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &sessioninfo, &count))
return FALSE;
// Ok, now find the active session
DWORD i;
for (i = 0; i < count; i++) {
if (sessioninfo[i].State == WTSActive) {
*id = sessioninfo[i].SessionId;
break;
}
}
WTSFreeMemory(&sessioninfo);
return TRUE;
}
char* getSid() {
DWORD sessionid;
DWORD usersize = 0;
char* username;
bool error = false;
if (!getActiveConsoleId(&sessionid)) {
//error("WTSEnumerateSessions failed: %ld", GetLastError());
error = true;
} else {
//info("WTSEnumerateSessions got active session: %d", sessionid);
}
if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, sessionid, WTSUserName, &username, &usersize)) {
//error("WTSQuerySessionInformation failed: %ld", GetLastError());
error = true;
} else {
//info("WTSQuerySessionInformation got user: %s", username);
}
PSID sid = NULL;
DWORD sid_size = 0;
char* domain = NULL;
DWORD domain_size = 0;
SID_NAME_USE use;
// First, we need to get the buffer size needed to store the SID
if(!LookupAccountName(NULL, username, sid, &sid_size, domain, &domain_size, &use)) {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
//error("LookupAccountName error while getting buffer size: %ld", GetLastError());
error = true;
}
}
try {
sid = (PSID) LocalAlloc(LMEM_FIXED, sid_size);
domain = (char*) malloc(domain_size * sizeof(char));
if ( !sid || !domain ) {
throw(0);
}
if (!LookupAccountName(NULL, username, sid, &sid_size, domain, &domain_size, &use)) {
//error("LookupAccountName error while getting buffer size: %ld", GetLastError());
throw(0);
}
} catch (int) {
LocalFree(sid);
sid = NULL;
//error("LookupAccountName error while getting actual data: %ld", GetLastError());
error = true;
}
char* string_sid;
if(!ConvertSidToStringSid(sid, &string_sid)) {
//error("Could not convert to string from SID");
error = true;
}
// do something with error
return string_sid;
}
PersistentSystemOptions PersistentSystemOptions::ReadSystemSettings()
{
char *sid = getSid();
std::string system = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
std::string explorer = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
std::string power = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power";
PersistentSystemOptions retval;
retval.hasChangePassword = !ReadRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableChangePassword"), false);
retval.hasLockComputer = !ReadRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableLockWorkstation"), false);
retval.hasLogOff = !ReadRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoLogoff"), false);
retval.hasSwitchUser = !ReadRegistryKey(HKEY_LOCAL_MACHINE, _T(sid + system), _T("HideFastUserSwitching"), false);
retval.hasTaskManager = !ReadRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableTaskMgr"), false);
retval.hasPower = !ReadRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoClose"), false);
retval.hasFilterKeysHotkey = ReadFilterKeysHotkey();
retval.hasMouseKeysHotkey = ReadMouseKeysHotkey();
retval.hasStickyKeysHotkey = ReadStickyKeysHotkey();
retval.hasToggleKeysHotkey = ReadToggleKeysHotkey();
retval.hasHighContrastHotkey = ReadHighContrastHotkey();
retval.hasFastBootHotKey = !ReadRegistryKey(HKEY_LOCAL_MACHINE, _T(sid + power), _T("HiberbootEnabled"), false);
return retval;
}
bool PersistentSystemOptions::WriteSystemSettings() const
{
bool allWorked = true;
char* sid = getSid();
std::string system = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
std::string explorer = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer";
std::string power = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power";
if(!WriteRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableChangePassword"), !hasChangePassword)) {
allWorked = false;
Tcout << _T("Error DisableChangePassword") << std::endl;
}
if(!WriteRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoLogoff"), !hasLogOff)) {
allWorked = false;
Tcout << _T("Error NoLogoff") << std::endl;
}
#ifndef DEBUG
if(!WriteRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableTaskMgr"), !hasTaskManager)) {
allWorked = false;
Tcout << _T("Error DisableTaskMgr") << std::endl;
}
#endif // DEBUG
if(!WriteRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoClose"), !hasPower)) {
allWorked = false;
Tcout << _T("Error NoClose") << std::endl;
}
if(!WriteFilterKeysHotkey(hasFilterKeysHotkey)) {
allWorked = false;
Tcout << _T("Error FilterKeysHotkey") << std::endl;
}
if(!WriteMouseKeysHotkey(hasMouseKeysHotkey)) {
allWorked = false;
Tcout << _T("Error MouseKeysHotkey") << std::endl;
}
if(!WriteStickyKeysHotkey(hasStickyKeysHotkey)) {
allWorked = false;
Tcout << _T("Error StickyKeysHotkey") << std::endl;
}
if(!WriteToggleKeysHotkey(hasToggleKeysHotkey)) {
allWorked = false;
Tcout << _T("Error ToggleKeysHotkey") << std::endl;
}
if(!WriteHighContrastHotkey(hasHighContrastHotkey)) {
allWorked = false;
Tcout << _T("Error HighContrastHotkey") << std::endl;
}
return allWorked;
}
bool PersistentSystemOptions::ReadRegistryKey(HKEY baseHive, tstring path, tstring name, bool defaultValue)
{
HKEY key;
if(ERROR_SUCCESS != RegOpenKeyEx(baseHive, path.c_str(), 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY | STANDARD_RIGHTS_READ, &key))
{
return defaultValue;
}
DWORD type;
DWORD value;
DWORD valueSize = sizeof(value);
if(ERROR_SUCCESS != RegQueryValueEx(key, name.c_str(), NULL, &type, (LPBYTE)&value, (LPDWORD)&valueSize))
{
RegCloseKey(key);
return defaultValue;
}
RegCloseKey(key);
if(type != REG_DWORD)
{
return defaultValue;
}
return value != 0;
}
bool PersistentSystemOptions::WriteRegistryKey(HKEY baseHive, tstring path, tstring name, bool value)
{
HKEY key;
if(ERROR_SUCCESS != RegCreateKeyEx(baseHive, path.c_str(), 0, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE | KEY_WOW64_64KEY | STANDARD_RIGHTS_WRITE | WRITE_OWNER, NULL, &key, NULL))
{
return false;
}
DWORD finalValue = value ? 1 : 0;
if(ERROR_SUCCESS != RegSetValueEx(key, name.c_str(), 0, REG_DWORD, (LPCBYTE)&finalValue, sizeof(finalValue)))
{
RegCloseKey(key);
return false;
}
RegCloseKey(key);
return true;
}
bool PersistentSystemOptions::ReadFilterKeysHotkey()
{
FILTERKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(settings), (PVOID)&settings, 0))
return true;
if(settings.dwFlags & FKF_HOTKEYACTIVE)
return true;
return false;
}
bool PersistentSystemOptions::WriteFilterKeysHotkey(bool value)
{
FILTERKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETFILTERKEYS, sizeof(settings), (PVOID)&settings, 0))
return false;
const DWORD flag = FKF_HOTKEYACTIVE;
settings.dwFlags &= ~flag;
if(value)
settings.dwFlags |= flag;
if(!SystemParametersInfo(SPI_SETFILTERKEYS, sizeof(settings), (PVOID)&settings, SPIF_SENDCHANGE))
return false;
return true;
}
bool PersistentSystemOptions::ReadMouseKeysHotkey()
{
MOUSEKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETMOUSEKEYS, sizeof(settings), (PVOID)&settings, 0))
return true;
if(settings.dwFlags & MKF_HOTKEYACTIVE)
return true;
return false;
}
bool PersistentSystemOptions::WriteMouseKeysHotkey(bool value)
{
MOUSEKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETMOUSEKEYS, sizeof(settings), (PVOID)&settings, 0))
return false;
const DWORD flag = MKF_HOTKEYACTIVE;
settings.dwFlags &= ~flag;
if(value)
settings.dwFlags |= flag;
if(!SystemParametersInfo(SPI_SETMOUSEKEYS, sizeof(settings), (PVOID)&settings, SPIF_SENDCHANGE))
return false;
return true;
}
bool PersistentSystemOptions::ReadStickyKeysHotkey()
{
STICKYKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(settings), (PVOID)&settings, 0))
return true;
if(settings.dwFlags & SKF_HOTKEYACTIVE)
return true;
return false;
}
bool PersistentSystemOptions::WriteStickyKeysHotkey(bool value)
{
STICKYKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(settings), (PVOID)&settings, 0))
return false;
const DWORD flag = SKF_HOTKEYACTIVE;
settings.dwFlags &= ~flag;
if(value)
settings.dwFlags |= flag;
if(!SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(settings), (PVOID)&settings, SPIF_SENDCHANGE))
return false;
return true;
}
bool PersistentSystemOptions::ReadToggleKeysHotkey()
{
TOGGLEKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(settings), (PVOID)&settings, 0))
return true;
if(settings.dwFlags & TKF_HOTKEYACTIVE)
return true;
return false;
}
bool PersistentSystemOptions::WriteToggleKeysHotkey(bool value)
{
TOGGLEKEYS settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETTOGGLEKEYS, sizeof(settings), (PVOID)&settings, 0))
return false;
const DWORD flag = TKF_HOTKEYACTIVE;
settings.dwFlags &= ~flag;
if(value)
settings.dwFlags |= flag;
if(!SystemParametersInfo(SPI_SETTOGGLEKEYS, sizeof(settings), (PVOID)&settings, SPIF_SENDCHANGE))
return false;
return true;
}
bool PersistentSystemOptions::ReadHighContrastHotkey()
{
HIGHCONTRAST settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(settings), (PVOID)&settings, 0))
return true;
if(settings.dwFlags & HCF_HOTKEYACTIVE)
return true;
return false;
}
bool PersistentSystemOptions::WriteHighContrastHotkey(bool value)
{
HIGHCONTRAST settings;
settings.cbSize = sizeof(settings);
if(!SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(settings), (PVOID)&settings, 0))
return false;
const DWORD flag = HCF_HOTKEYACTIVE;
settings.dwFlags &= ~flag;
if(value)
settings.dwFlags |= flag;
if(!SystemParametersInfo(SPI_SETHIGHCONTRAST, sizeof(settings), (PVOID)&settings, SPIF_SENDCHANGE))
return false;
return true;
}
PersistentSystemOptions PersistentSystemOptions::ReadFromStorage()
{
char* sid = getSid();
std::string options = "\\PersistentSystemOptions";
std::string sep = "\\";
std::string dest = sid + sep + REGISTRY_SETTINGS_LOCATION + options;
PersistentSystemOptions retval;
retval.hasChangePassword = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasChangePassword"), true);
retval.hasLockComputer = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasLockComputer"), true);
retval.hasLogOff = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasLogOff"), true);
retval.hasSwitchUser = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasSwitchUser"), true);
retval.hasTaskManager = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasTaskManager"), true);
retval.hasPower = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasPower"), true);
retval.hasFilterKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasFilterKeysHotkey"), true);
retval.hasMouseKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasMouseKeysHotkey"), true);
retval.hasStickyKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasStickyKeysHotkey"), true);
retval.hasToggleKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasToggleKeysHotkey"), true);
retval.hasHighContrastHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasHighContrastHotkey"), true);
retval.hasFastBootHotKey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasFastBootHotkey"), true);
return retval;
}
bool PersistentSystemOptions::WriteToStorage() const
{
char* sid = getSid();
std::string options = "\\PersistentSystemOptions";
std::string sep = "\\";
std::string dest = sid + sep + REGISTRY_SETTINGS_LOCATION + options;
bool allWorked = true;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasChangePassword"), hasChangePassword))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasLockComputer"), hasLockComputer))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasLogOff"), hasLogOff))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasSwitchUser"), hasSwitchUser))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasTaskManager"), hasTaskManager))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasPower"), hasPower))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasFilterKeysHotkey"), hasFilterKeysHotkey))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasMouseKeysHotkey"), hasMouseKeysHotkey))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasStickyKeysHotkey"), hasStickyKeysHotkey))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasToggleKeysHotkey"), hasToggleKeysHotkey))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasHighContrastHotkey"), hasHighContrastHotkey))
allWorked = false;
if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasFastBootHotkey"), !hasFastBootHotKey))
allWorked = false;
return allWorked;
}
PersistentSystemOptions persistentSystemOptions;
int action_block() {
ShowWindow(FindWindow("Shell_TrayWnd",""), SW_HIDE);
bool succeded = PersistentSystemOptions::AllDisabled().WriteSystemSettings();
if(verbose)
{
if(succeded)
Tcout << _T("Disabled persistent system options.") << std::endl;
else
Tcout << _T("Reseting persistent system options failed.") << std::endl;
}
if(!succeded)
return 1;
return 0;
}
int action_unblock() {
ShowWindow(FindWindow("Shell_TrayWnd",""), SW_SHOW);
bool succeded = PersistentSystemOptions::AllEnabled().WriteSystemSettings();
if(verbose)
{
if(succeded)
Tcout << _T("Disabled persistent system options.") << std::endl;
else
Tcout << _T("Reseting persistent system options failed.") << std::endl;
}
if(!succeded)
return 1;
return 0;
}
int action_dump() {
persistentSystemOptions = PersistentSystemOptions::ReadSystemSettings();
persistentSystemOptions.Dump(Tcout);
return 0;
}
int action_force_unblock() {
ShowWindow(FindWindow("Shell_TrayWnd",""), SW_SHOW);
bool succeded = PersistentSystemOptions::AllEnabled().WriteSystemSettings();
if(verbose)
{
if(succeded)
Tcout << _T("Reset persistent system options.") << std::endl;
else
Tcout << _T("Reseting persistent system options failed.") << std::endl;
}
if(!succeded)
return 1;
return 0;
}
int action_save() {
persistentSystemOptions = PersistentSystemOptions::ReadSystemSettings();
if(verbose)
{
Tcout << _T("Read persistent system options:") << std::endl;
persistentSystemOptions.Dump(Tcout);
}
bool succeded = persistentSystemOptions.WriteToStorage();
if(verbose)
{
if(succeded)
Tcout << _T("Saved persistent system options.") << std::endl;
else
Tcout << _T("Saving persistent system options failed.") << std::endl;
}
if(!succeded)
return 1;
return 0;
}
int action_load() {
persistentSystemOptions = PersistentSystemOptions::ReadFromStorage();
if(verbose)
{
Tcout << _T("Read persistent system options from storage:") << std::endl;
persistentSystemOptions.Dump(Tcout);
}
}
int action_write_settings() {
if(!persistentSystemOptions.WriteSystemSettings())
{
if(verbose)
{
Tcout << _T("Writing persistent system options failed.");
}
return 1;
}
return 0;
}