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
|
#pragma once
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
#include "verutil.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ReleaseRegKey(h) if (h) { ::RegCloseKey(h); h = NULL; }
typedef enum REG_KEY_BITNESS
{
REG_KEY_DEFAULT = 0,
REG_KEY_32BIT = 1,
REG_KEY_64BIT = 2
} REG_KEY_BITNESS;
typedef LSTATUS (APIENTRY *PFN_REGCREATEKEYEXW)(
__in HKEY hKey,
__in LPCWSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPWSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
typedef LSTATUS (APIENTRY *PFN_REGOPENKEYEXW)(
__in HKEY hKey,
__in_opt LPCWSTR lpSubKey,
__reserved DWORD ulOptions,
__in REGSAM samDesired,
__out PHKEY phkResult
);
typedef LSTATUS (APIENTRY *PFN_REGDELETEKEYEXW)(
__in HKEY hKey,
__in LPCWSTR lpSubKey,
__in REGSAM samDesired,
__reserved DWORD Reserved
);
typedef LSTATUS (APIENTRY *PFN_REGDELETEKEYW)(
__in HKEY hKey,
__in LPCWSTR lpSubKey
);
typedef LSTATUS (APIENTRY *PFN_REGENUMKEYEXW)(
__in HKEY hKey,
__in DWORD dwIndex,
__out LPWSTR lpName,
__inout LPDWORD lpcName,
__reserved LPDWORD lpReserved,
__inout_opt LPWSTR lpClass,
__inout_opt LPDWORD lpcClass,
__out_opt PFILETIME lpftLastWriteTime
);
typedef LSTATUS (APIENTRY *PFN_REGENUMVALUEW)(
__in HKEY hKey,
__in DWORD dwIndex,
__out LPWSTR lpValueName,
__inout LPDWORD lpcchValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_opt LPBYTE lpData,
__out_opt LPDWORD lpcbData
);
typedef LSTATUS (APIENTRY *PFN_REGQUERYINFOKEYW)(
__in HKEY hKey,
__out_opt LPWSTR lpClass,
__inout_opt LPDWORD lpcClass,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpcSubKeys,
__out_opt LPDWORD lpcMaxSubKeyLen,
__out_opt LPDWORD lpcMaxClassLen,
__out_opt LPDWORD lpcValues,
__out_opt LPDWORD lpcMaxValueNameLen,
__out_opt LPDWORD lpcMaxValueLen,
__out_opt LPDWORD lpcbSecurityDescriptor,
__out_opt PFILETIME lpftLastWriteTime
);
typedef LSTATUS (APIENTRY *PFN_REGQUERYVALUEEXW)(
__in HKEY hKey,
__in_opt LPCWSTR lpValueName,
__reserved LPDWORD lpReserved,
__out_opt LPDWORD lpType,
__out_bcount_part_opt(*lpcbData, *lpcbData) __out_data_source(REGISTRY) LPBYTE lpData,
__inout_opt LPDWORD lpcbData
);
typedef LSTATUS (APIENTRY *PFN_REGSETVALUEEXW)(
__in HKEY hKey,
__in_opt LPCWSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in_bcount_opt(cbData) CONST BYTE* lpData,
__in DWORD cbData
);
typedef LSTATUS (APIENTRY *PFN_REGDELETEVALUEW)(
__in HKEY hKey,
__in_opt LPCWSTR lpValueName
);
typedef LSTATUS(APIENTRY *PFN_REGGETVALUEW)(
__in HKEY hkey,
__in_opt LPCWSTR lpSubKey,
__in_opt LPCWSTR lpValue,
__in DWORD dwFlags,
__out_opt LPDWORD pdwType,
__out_bcount_part_opt(*pcbData, *pcbData) __out_data_source(REGISTRY) PVOID pvData,
__inout_opt LPDWORD pcbData
);
/********************************************************************
RegInitialize - initializes regutil
*********************************************************************/
HRESULT DAPI RegInitialize();
/********************************************************************
RegUninitialize - uninitializes regutil
*********************************************************************/
void DAPI RegUninitialize();
/********************************************************************
RegFunctionOverride - overrides the registry functions. Typically used
for unit testing.
*********************************************************************/
void DAPI RegFunctionOverride(
__in_opt PFN_REGCREATEKEYEXW pfnRegCreateKeyExW,
__in_opt PFN_REGOPENKEYEXW pfnRegOpenKeyExW,
__in_opt PFN_REGDELETEKEYEXW pfnRegDeleteKeyExW,
__in_opt PFN_REGENUMKEYEXW pfnRegEnumKeyExW,
__in_opt PFN_REGENUMVALUEW pfnRegEnumValueW,
__in_opt PFN_REGQUERYINFOKEYW pfnRegQueryInfoKeyW,
__in_opt PFN_REGQUERYVALUEEXW pfnRegQueryValueExW,
__in_opt PFN_REGSETVALUEEXW pfnRegSetValueExW,
__in_opt PFN_REGDELETEVALUEW pfnRegDeleteValueW,
__in_opt PFN_REGGETVALUEW pfnRegGetValueW
);
/********************************************************************
RegFunctionForceFallback - ignore functions only available in newer versions of Windows.
Typically used for unit testing.
*********************************************************************/
void DAPI RegFunctionForceFallback();
/********************************************************************
RegCreate - creates a registry key.
*********************************************************************/
HRESULT DAPI RegCreate(
__in HKEY hkRoot,
__in_z LPCWSTR wzSubKey,
__in DWORD dwAccess,
__out HKEY* phk
);
/********************************************************************
RegCreateEx - creates a registry key with extra options.
*********************************************************************/
HRESULT DAPI RegCreateEx(
__in HKEY hkRoot,
__in_z LPCWSTR wzSubKey,
__in DWORD dwAccess,
__in REG_KEY_BITNESS kbKeyBitness,
__in BOOL fVolatile,
__in_opt SECURITY_ATTRIBUTES* pSecurityAttributes,
__out HKEY* phk,
__out_opt BOOL* pfCreated
);
/********************************************************************
RegOpen - opens a registry key.
*********************************************************************/
HRESULT DAPI RegOpen(
__in HKEY hkRoot,
__in_z LPCWSTR wzSubKey,
__in DWORD dwAccess,
__out HKEY* phk
);
/********************************************************************
RegOpenEx - opens a registry key.
*********************************************************************/
HRESULT DAPI RegOpenEx(
__in HKEY hkRoot,
__in_z LPCWSTR wzSubKey,
__in DWORD dwAccess,
__in REG_KEY_BITNESS kbKeyBitness,
__out HKEY* phk
);
/********************************************************************
RegDelete - deletes a registry key (and optionally it's whole tree).
*********************************************************************/
HRESULT DAPI RegDelete(
__in HKEY hkRoot,
__in_z LPCWSTR wzSubKey,
__in REG_KEY_BITNESS kbKeyBitness,
__in BOOL fDeleteTree
);
/********************************************************************
RegKeyEnum - enumerates child registry keys.
*********************************************************************/
HRESULT DAPI RegKeyEnum(
__in HKEY hk,
__in DWORD dwIndex,
__deref_out_z LPWSTR* psczKey
);
/********************************************************************
RegValueEnum - enumerates registry values.
*********************************************************************/
HRESULT DAPI RegValueEnum(
__in HKEY hk,
__in DWORD dwIndex,
__deref_out_z LPWSTR* psczName,
__out_opt DWORD *pdwType
);
/********************************************************************
RegGetType - reads a registry key value type.
*********************************************************************/
HRESULT DAPI RegGetType(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__out DWORD *pdwType
);
/********************************************************************
RegReadBinary - reads a registry key value.
If fExpand is TRUE and the value is REG_EXPAND_SZ then it will be expanded.
NOTE: caller is responsible for freeing *ppbBuffer
*********************************************************************/
HRESULT DAPI RegReadValue(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in BOOL fExpand,
__deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer,
__inout SIZE_T* pcbBuffer,
__out DWORD* pdwType
);
/********************************************************************
RegReadBinary - reads a registry key binary value.
NOTE: caller is responsible for freeing *ppbBuffer
*********************************************************************/
HRESULT DAPI RegReadBinary(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer,
__out SIZE_T *pcbBuffer
);
/********************************************************************
RegReadString - reads a registry key value as a string.
*********************************************************************/
HRESULT DAPI RegReadString(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__deref_out_z LPWSTR* psczValue
);
/********************************************************************
RegReadUnexpandedString - reads a registry key value as a string without expanding it.
*********************************************************************/
HRESULT DAPI RegReadUnexpandedString(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__inout BOOL* pfNeedsExpansion,
__deref_out_z LPWSTR* psczValue
);
/********************************************************************
RegReadStringArray - reads a registry key value REG_MULTI_SZ value as a string array.
*********************************************************************/
HRESULT DAPI RegReadStringArray(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings,
__out DWORD *pcStrings
);
/********************************************************************
RegReadVersion - reads a registry key value as a version.
*********************************************************************/
HRESULT DAPI RegReadVersion(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__out DWORD64* pdw64Version
);
/********************************************************************
RegReadWixVersion - reads a registry key value as a WiX version.
*********************************************************************/
HRESULT DAPI RegReadWixVersion(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__out VERUTIL_VERSION** ppVersion
);
/********************************************************************
RegReadNone - reads a NONE registry key value.
*********************************************************************/
HRESULT DAPI RegReadNone(
__in HKEY hk,
__in_z_opt LPCWSTR wzName
);
/********************************************************************
RegReadNumber - reads a DWORD registry key value as a number.
*********************************************************************/
HRESULT DAPI RegReadNumber(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__out DWORD* pdwValue
);
/********************************************************************
RegReadQword - reads a QWORD registry key value as a number.
*********************************************************************/
HRESULT DAPI RegReadQword(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__out DWORD64* pqwValue
);
/********************************************************************
RegWriteBinary - writes a registry key value as a binary.
*********************************************************************/
HRESULT DAPI RegWriteBinary(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in_bcount(cbBuffer) const BYTE *pbBuffer,
__in DWORD cbBuffer
);
/********************************************************************
RegWriteExpandString - writes a registry key value as an expand string.
Note: if wzValue is NULL the value will be removed.
*********************************************************************/
HRESULT DAPI RegWriteExpandString(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in_z_opt LPCWSTR wzValue
);
/********************************************************************
RegWriteString - writes a registry key value as a string.
Note: if wzValue is NULL the value will be removed.
*********************************************************************/
HRESULT DAPI RegWriteString(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in_z_opt LPCWSTR wzValue
);
/********************************************************************
RegWriteStringFormatted - writes a registry key value as a formatted string.
*********************************************************************/
HRESULT DAPIV RegWriteStringFormatted(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in __format_string LPCWSTR szFormat,
...
);
/********************************************************************
RegWriteStringArray - writes an array of strings as a REG_MULTI_SZ value
*********************************************************************/
HRESULT DAPI RegWriteStringArray(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in_ecount(cStrings) LPWSTR* rgwzStrings,
__in DWORD cStrings
);
/********************************************************************
RegWriteNone - writes a registry key value as none.
*********************************************************************/
HRESULT DAPI RegWriteNone(
__in HKEY hk,
__in_z_opt LPCWSTR wzName
);
/********************************************************************
RegWriteNumber - writes a registry key value as a number.
*********************************************************************/
HRESULT DAPI RegWriteNumber(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in DWORD dwValue
);
/********************************************************************
RegWriteQword - writes a registry key value as a Qword.
*********************************************************************/
HRESULT DAPI RegWriteQword(
__in HKEY hk,
__in_z_opt LPCWSTR wzName,
__in DWORD64 qwValue
);
/********************************************************************
RegQueryKey - queries the key for the number of subkeys and values.
*********************************************************************/
HRESULT DAPI RegQueryKey(
__in HKEY hk,
__out_opt DWORD* pcSubKeys,
__out_opt DWORD* pcValues
);
/********************************************************************
RegKeyReadNumber - reads a DWORD registry key value as a number from
a specified subkey.
*********************************************************************/
HRESULT DAPI RegKeyReadNumber(
__in HKEY hk,
__in_z LPCWSTR wzSubKey,
__in_z_opt LPCWSTR wzName,
__in REG_KEY_BITNESS kbKeyBitness,
__out DWORD* pdwValue
);
/********************************************************************
RegValueExists - determines whether a named value exists in a
specified subkey.
*********************************************************************/
BOOL DAPI RegValueExists(
__in HKEY hk,
__in_z LPCWSTR wzSubKey,
__in_z_opt LPCWSTR wzName,
__in REG_KEY_BITNESS kbKeyBitness
);
/********************************************************************
RegTranslateKeyBitness - Converts from REG_KEY_BITNESS values to
REGSAM-compatible values.
*********************************************************************/
REGSAM DAPI RegTranslateKeyBitness(
__in REG_KEY_BITNESS kbKeyBitness
);
#ifdef __cplusplus
}
#endif
|