-
Notifications
You must be signed in to change notification settings - Fork 4
/
registry.c
46 lines (42 loc) · 1.19 KB
/
registry.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
#include "registry.h"
BOOLEAN RegistryDoesKeyExist(PCWSTR Key) {
HKEY temp;
return !(RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_READ, &temp));
}
BOOLEAN RegistryCreateKey(PCWSTR Key) {
DWORD dwDisposition;
HKEY hKey;
DWORD Ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, Key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (Ret != ERROR_SUCCESS) {
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
BOOLEAN RegistryWriteDword32(PCWSTR Key, PCWSTR ValueName, DWORD32 Value) {
HKEY hKey;
DWORD Ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_WRITE, &hKey);
if (Ret == ERROR_SUCCESS) {
if (RegSetValueEx(hKey, ValueName, 0, REG_DWORD, (BYTE*)(&Value), sizeof(Value))) {
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
return FALSE;
}
BOOLEAN RegistryWriteString(PCWSTR Key, PCWSTR ValueName, PCWSTR Value) {
DWORD Ret;
HKEY hKey;
Ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_WRITE, &hKey);
if (Ret == ERROR_SUCCESS) {
if (RegSetValueEx(hKey, ValueName, 0, REG_SZ, (LPBYTE)(Value), ((((DWORD)lstrlen(Value) + 1)) * 2))) {
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;
}
return FALSE;
}