20#ifndef WINPR_REGISTRY_H
21#define WINPR_REGISTRY_H
23#include <winpr/windows.h>
25#if defined(_WIN32) && !defined(_UWP)
36#include <winpr/winpr.h>
37#include <winpr/wtypes.h>
41#include <winpr/error.h>
45#define OWNER_SECURITY_INFORMATION 0x00000001
46#define GROUP_SECURITY_INFORMATION 0x00000002
47#define DACL_SECURITY_INFORMATION 0x00000004
48#define SACL_SECURITY_INFORMATION 0x00000008
50#define REG_OPTION_RESERVED 0x00000000
51#define REG_OPTION_NON_VOLATILE 0x00000000
52#define REG_OPTION_VOLATILE 0x00000001
53#define REG_OPTION_CREATE_LINK 0x00000002
54#define REG_OPTION_BACKUP_RESTORE 0x00000004
55#define REG_OPTION_OPEN_LINK 0x00000008
57#define REG_CREATED_NEW_KEY 0x00000001
58#define REG_OPENED_EXISTING_KEY 0x00000002
60#define REG_NOTIFY_CHANGE_NAME 0x01
61#define REG_NOTIFY_CHANGE_ATTRIBUTES 0x02
62#define REG_NOTIFY_CHANGE_LAST_SET 0x04
63#define REG_NOTIFY_CHANGE_SECURITY 0x08
65#define KEY_QUERY_VALUE 0x00000001
66#define KEY_SET_VALUE 0x00000002
67#define KEY_CREATE_SUB_KEY 0x00000004
68#define KEY_ENUMERATE_SUB_KEYS 0x00000008
69#define KEY_NOTIFY 0x00000010
70#define KEY_CREATE_LINK 0x00000020
71#define KEY_WOW64_64KEY 0x00000100
72#define KEY_WOW64_32KEY 0x00000200
73#define KEY_WOW64_RES 0x00000300
75#define REG_WHOLE_HIVE_VOLATILE 0x00000001
76#define REG_REFRESH_HIVE 0x00000002
77#define REG_NO_LAZY_FLUSH 0x00000004
78#define REG_FORCE_RESTORE 0x00000008
81 ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & \
84#define KEY_WRITE ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE))
86#define KEY_EXECUTE ((KEY_READ) & (~SYNCHRONIZE))
88#define KEY_ALL_ACCESS \
89 ((STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY | \
90 KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY | KEY_CREATE_LINK) & \
100 REG_DWORD_LITTLE_ENDIAN = REG_DWORD,
101 REG_DWORD_BIG_ENDIAN = 5,
104 REG_RESOURCE_LIST = 8,
105 REG_FULL_RESOURCE_DESCRIPTOR = 9,
106 REG_RESOURCE_REQUIREMENTS_LIST = 10,
108 REG_QWORD_LITTLE_ENDIAN = REG_QWORD
112 typedef HANDLE* PHKEY;
116 typedef ACCESS_MASK REGSAM;
118#define HKEY_CLASSES_ROOT ((HKEY)(LONG_PTR)(LONG)0x80000000)
119#define HKEY_CURRENT_USER ((HKEY)(LONG_PTR)(LONG)0x80000001)
120#define HKEY_LOCAL_MACHINE ((HKEY)(LONG_PTR)(LONG)0x80000002)
121#define HKEY_USERS ((HKEY)(LONG_PTR)(LONG)0x80000003)
122#define HKEY_PERFORMANCE_DATA ((HKEY)(LONG_PTR)(LONG)0x80000004)
123#define HKEY_PERFORMANCE_TEXT ((HKEY)(LONG_PTR)(LONG)0x80000050)
124#define HKEY_PERFORMANCE_NLSTEXT ((HKEY)(LONG_PTR)(LONG)0x80000060)
125#define HKEY_CURRENT_CONFIG ((HKEY)(LONG_PTR)(LONG)0x80000005)
126#define HKEY_DYN_DATA ((HKEY)(LONG_PTR)(LONG)0x80000006)
127#define HKEY_CURRENT_USER_LOCAL_SETTINGS ((HKEY)(LONG_PTR)(LONG)0x80000007)
129#define RRF_RT_REG_NONE 0x00000001
130#define RRF_RT_REG_SZ 0x00000002
131#define RRF_RT_REG_EXPAND_SZ 0x00000004
132#define RRF_RT_REG_BINARY 0x00000008
133#define RRF_RT_REG_DWORD 0x00000010
134#define RRF_RT_REG_MULTI_SZ 0x00000020
135#define RRF_RT_REG_QWORD 0x00000040
137#define RRF_RT_DWORD (RRF_RT_REG_BINARY | RRF_RT_REG_DWORD)
138#define RRF_RT_QWORD (RRF_RT_REG_BINARY | RRF_RT_REG_QWORD)
139#define RRF_RT_ANY 0x0000FFFF
141#define RRF_NOEXPAND 0x10000000
142#define RRF_ZEROONFAILURE 0x20000000
147 LPVOID value_context;
153 typedef struct pvalueA
157 LPVOID pv_value_context;
161 typedef struct pvalueW
165 LPVOID pv_value_context;
171 typedef PPVALUEW PPVALUE;
174typedef PPVALUEA PPVALUE;
177 typedef struct value_entA
181 DWORD_PTR ve_valueptr;
185 typedef struct value_entW
189 DWORD_PTR ve_valueptr;
195 typedef PVALENTW PVALENT;
198typedef PVALENTA PVALENT;
201 WINPR_API LONG RegCloseKey(HKEY hKey);
204 WINPR_API LONG RegCopyTreeW(HKEY hKeySrc, LPCWSTR lpSubKey, HKEY hKeyDest);
207 WINPR_API LONG RegCopyTreeA(HKEY hKeySrc, LPCSTR lpSubKey, HKEY hKeyDest);
210#define RegCopyTree RegCopyTreeW
212#define RegCopyTree RegCopyTreeA
216 WINPR_API LONG RegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass,
217 DWORD dwOptions, REGSAM samDesired,
218 LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
219 LPDWORD lpdwDisposition);
222 WINPR_API LONG RegCreateKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass,
223 DWORD dwOptions, REGSAM samDesired,
224 LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult,
225 LPDWORD lpdwDisposition);
228#define RegCreateKeyEx RegCreateKeyExW
230#define RegCreateKeyEx RegCreateKeyExA
234 WINPR_API LONG RegDeleteKeyExW(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired, DWORD Reserved);
237 WINPR_API LONG RegDeleteKeyExA(HKEY hKey, LPCSTR lpSubKey, REGSAM samDesired, DWORD Reserved);
240#define RegDeleteKeyEx RegDeleteKeyExW
242#define RegDeleteKeyEx RegDeleteKeyExA
246 WINPR_API LONG RegDeleteTreeW(HKEY hKey, LPCWSTR lpSubKey);
249 WINPR_API LONG RegDeleteTreeA(HKEY hKey, LPCSTR lpSubKey);
252#define RegDeleteTree RegDeleteTreeW
254#define RegDeleteTree RegDeleteTreeA
258 WINPR_API LONG RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName);
261 WINPR_API LONG RegDeleteValueA(HKEY hKey, LPCSTR lpValueName);
264#define RegDeleteValue RegDeleteValueW
266#define RegDeleteValue RegDeleteValueA
270 WINPR_API LONG RegDisablePredefinedCacheEx(
void);
273 WINPR_API LONG RegEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcName,
274 LPDWORD lpReserved, LPWSTR lpClass, LPDWORD lpcClass,
275 PFILETIME lpftLastWriteTime);
278 WINPR_API LONG RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcName,
279 LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcClass,
280 PFILETIME lpftLastWriteTime);
283#define RegEnumKeyEx RegEnumKeyExW
285#define RegEnumKeyEx RegEnumKeyExA
289 WINPR_API LONG RegEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName,
290 LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType,
291 LPBYTE lpData, LPDWORD lpcbData);
294 WINPR_API LONG RegEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpValueName,
295 LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType,
296 LPBYTE lpData, LPDWORD lpcbData);
299#define RegEnumValue RegEnumValueW
301#define RegEnumValue RegEnumValueA
305 WINPR_API LONG RegFlushKey(HKEY hKey);
308 WINPR_API LONG RegGetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation,
309 PSECURITY_DESCRIPTOR pSecurityDescriptor,
310 LPDWORD lpcbSecurityDescriptor);
313 WINPR_API LONG RegGetValueW(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags,
314 LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
317 WINPR_API LONG RegGetValueA(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags,
318 LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
321#define RegGetValue RegGetValueW
323#define RegGetValue RegGetValueA
327 WINPR_API LONG RegLoadAppKeyW(LPCWSTR lpFile, PHKEY phkResult, REGSAM samDesired,
328 DWORD dwOptions, DWORD Reserved);
331 WINPR_API LONG RegLoadAppKeyA(LPCSTR lpFile, PHKEY phkResult, REGSAM samDesired,
332 DWORD dwOptions, DWORD Reserved);
335#define RegLoadAppKey RegLoadAppKeyW
337#define RegLoadAppKey RegLoadAppKeyA
341 WINPR_API LONG RegLoadKeyW(HKEY hKey, LPCWSTR lpSubKey, LPCWSTR lpFile);
344 WINPR_API LONG RegLoadKeyA(HKEY hKey, LPCSTR lpSubKey, LPCSTR lpFile);
347#define RegLoadKey RegLoadKeyW
349#define RegLoadKey RegLoadKeyA
353 WINPR_API LONG RegLoadMUIStringW(HKEY hKey, LPCWSTR pszValue, LPWSTR pszOutBuf, DWORD cbOutBuf,
354 LPDWORD pcbData, DWORD Flags, LPCWSTR pszDirectory);
357 WINPR_API LONG RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, LPSTR pszOutBuf, DWORD cbOutBuf,
358 LPDWORD pcbData, DWORD Flags, LPCSTR pszDirectory);
361#define RegLoadMUIString RegLoadMUIStringW
363#define RegLoadMUIString RegLoadMUIStringA
367 WINPR_API LONG RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, DWORD dwNotifyFilter,
368 HANDLE hEvent, BOOL fAsynchronous);
371 WINPR_API LONG RegOpenCurrentUser(REGSAM samDesired, PHKEY phkResult);
374 WINPR_API LONG RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired,
378 WINPR_API LONG RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired,
382#define RegOpenKeyEx RegOpenKeyExW
384#define RegOpenKeyEx RegOpenKeyExA
388 WINPR_API LONG RegOpenUserClassesRoot(HANDLE hToken, DWORD dwOptions, REGSAM samDesired,
392 WINPR_API LONG RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved,
393 LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen,
394 LPDWORD lpcMaxClassLen, LPDWORD lpcValues,
395 LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
396 LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime);
399 WINPR_API LONG RegQueryInfoKeyA(HKEY hKey, LPSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved,
400 LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen,
401 LPDWORD lpcMaxClassLen, LPDWORD lpcValues,
402 LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen,
403 LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime);
406#define RegQueryInfoKey RegQueryInfoKeyW
408#define RegQueryInfoKey RegQueryInfoKeyA
412 WINPR_API LONG RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved,
413 LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
416 WINPR_API LONG RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved,
417 LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
420#define RegQueryValueEx RegQueryValueExW
422#define RegQueryValueEx RegQueryValueExA
426 WINPR_API LONG RegRestoreKeyW(HKEY hKey, LPCWSTR lpFile, DWORD dwFlags);
429 WINPR_API LONG RegRestoreKeyA(HKEY hKey, LPCSTR lpFile, DWORD dwFlags);
432#define RegRestoreKey RegRestoreKeyW
434#define RegRestoreKey RegRestoreKeyA
438 WINPR_API LONG RegSaveKeyExW(HKEY hKey, LPCWSTR lpFile,
439 LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD Flags);
442 WINPR_API LONG RegSaveKeyExA(HKEY hKey, LPCSTR lpFile,
443 LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD Flags);
446#define RegSaveKeyEx RegSaveKeyExW
448#define RegSaveKeyEx RegSaveKeyExA
452 WINPR_API LONG RegSetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation,
453 PSECURITY_DESCRIPTOR pSecurityDescriptor);
456 WINPR_API LONG RegSetValueExW(HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, DWORD dwType,
457 const BYTE* lpData, DWORD cbData);
460 WINPR_API LONG RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType,
461 const BYTE* lpData, DWORD cbData);
464#define RegSetValueEx RegSetValueExW
466#define RegSetValueEx RegSetValueExA
470 WINPR_API LONG RegUnLoadKeyW(HKEY hKey, LPCWSTR lpSubKey);
473 WINPR_API LONG RegUnLoadKeyA(HKEY hKey, LPCSTR lpSubKey);
476#define RegUnLoadKey RegUnLoadKeyW
478#define RegUnLoadKey RegUnLoadKeyA