4 * Copyright (C) 1999 Alexandre Julliard
6 * Based on misc/registry.c code
7 * Copyright (C) 1996 Marcus Meissner
8 * Copyright (C) 1998 Matthew Becker
9 * Copyright (C) 1999 Sylvain St-Germain
11 * This file is concerned about handle management and interaction with the Wine server.
12 * Registry file I/O is in misc/registry.c.
22 #include "wine/unicode.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(reg);
30 /* Unicode->Ansi conversion without string delimiters */
31 static LPSTR memcpyWtoA( LPSTR dst, LPCWSTR src, INT n )
34 while (n-- > 0) *p++ = (CHAR)*src++;
38 /* check if value type needs string conversion (Ansi<->Unicode) */
39 static inline int is_string( DWORD type )
41 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
44 /* do a server call without setting the last error code */
45 static inline int reg_server_call( enum request req )
47 unsigned int res = server_call_noerr( req );
48 if (res) res = RtlNtStatusToDosError(res);
52 /******************************************************************************
53 * RegCreateKeyExW [ADVAPI32.131]
56 * hkey [I] Handle of an open key
57 * name [I] Address of subkey name
58 * reserved [I] Reserved - must be 0
59 * class [I] Address of class string
60 * options [I] Special options flag
61 * access [I] Desired security access
62 * sa [I] Address of key security structure
63 * retkey [O] Address of buffer for opened handle
64 * dispos [O] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
67 * in case of failing retkey remains untouched
69 DWORD WINAPI RegCreateKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR class,
70 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
71 LPHKEY retkey, LPDWORD dispos )
73 OBJECT_ATTRIBUTES attr;
74 UNICODE_STRING nameW, classW;
76 if (reserved) return ERROR_INVALID_PARAMETER;
77 if (!(access & KEY_ALL_ACCESS) || (access & ~KEY_ALL_ACCESS)) return ERROR_ACCESS_DENIED;
79 attr.Length = sizeof(attr);
80 attr.RootDirectory = hkey;
81 attr.ObjectName = &nameW;
83 attr.SecurityDescriptor = NULL;
84 attr.SecurityQualityOfService = NULL;
85 RtlInitUnicodeString( &nameW, name );
86 RtlInitUnicodeString( &classW, class );
88 return RtlNtStatusToDosError( NtCreateKey( retkey, access, &attr, 0,
89 &classW, options, dispos ) );
93 /******************************************************************************
94 * RegCreateKeyExA [ADVAPI32.130]
96 DWORD WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR class,
97 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
98 LPHKEY retkey, LPDWORD dispos )
100 OBJECT_ATTRIBUTES attr;
101 UNICODE_STRING nameW, classW;
102 ANSI_STRING nameA, classA;
105 if (reserved) return ERROR_INVALID_PARAMETER;
106 if (!(access & KEY_ALL_ACCESS) || (access & ~KEY_ALL_ACCESS)) return ERROR_ACCESS_DENIED;
108 attr.Length = sizeof(attr);
109 attr.RootDirectory = hkey;
110 attr.ObjectName = &nameW;
112 attr.SecurityDescriptor = NULL;
113 attr.SecurityQualityOfService = NULL;
114 RtlInitAnsiString( &nameA, name );
115 RtlInitAnsiString( &classA, class );
117 /* FIXME: should use Unicode buffer in TEB */
118 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
120 if (!(status = RtlAnsiStringToUnicodeString( &classW, &classA, TRUE )))
122 status = NtCreateKey( retkey, access, &attr, 0, &classW, options, dispos );
123 RtlFreeUnicodeString( &classW );
125 RtlFreeUnicodeString( &nameW );
127 return RtlNtStatusToDosError( status );
131 /******************************************************************************
132 * RegCreateKeyW [ADVAPI32.132]
134 DWORD WINAPI RegCreateKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
136 /* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
137 /* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
138 return RegCreateKeyExW( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
139 KEY_ALL_ACCESS, NULL, retkey, NULL );
143 /******************************************************************************
144 * RegCreateKeyA [ADVAPI32.129]
146 DWORD WINAPI RegCreateKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
148 return RegCreateKeyExA( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
149 KEY_ALL_ACCESS, NULL, retkey, NULL );
154 /******************************************************************************
155 * RegOpenKeyExW [ADVAPI32.150]
157 * Opens the specified key
159 * Unlike RegCreateKeyEx, this does not create the key if it does not exist.
162 * hkey [I] Handle of open key
163 * name [I] Name of subkey to open
164 * reserved [I] Reserved - must be zero
165 * access [I] Security access mask
166 * retkey [O] Handle to open key
169 * Success: ERROR_SUCCESS
170 * Failure: Error code
173 * in case of failing is retkey = 0
175 DWORD WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
177 OBJECT_ATTRIBUTES attr;
178 UNICODE_STRING nameW;
180 attr.Length = sizeof(attr);
181 attr.RootDirectory = hkey;
182 attr.ObjectName = &nameW;
184 attr.SecurityDescriptor = NULL;
185 attr.SecurityQualityOfService = NULL;
186 RtlInitUnicodeString( &nameW, name );
187 return RtlNtStatusToDosError( NtOpenKey( retkey, access, &attr ) );
191 /******************************************************************************
192 * RegOpenKeyExA [ADVAPI32.149]
194 DWORD WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
196 OBJECT_ATTRIBUTES attr;
197 UNICODE_STRING nameW;
201 attr.Length = sizeof(attr);
202 attr.RootDirectory = hkey;
203 attr.ObjectName = &nameW;
205 attr.SecurityDescriptor = NULL;
206 attr.SecurityQualityOfService = NULL;
208 RtlInitAnsiString( &nameA, name );
209 /* FIXME: should use Unicode buffer in TEB */
210 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
212 status = NtOpenKey( retkey, access, &attr );
213 RtlFreeUnicodeString( &nameW );
215 return RtlNtStatusToDosError( status );
219 /******************************************************************************
220 * RegOpenKeyW [ADVAPI32.151]
223 * hkey [I] Handle of open key
224 * name [I] Address of name of subkey to open
225 * retkey [O] Handle to open key
228 * Success: ERROR_SUCCESS
229 * Failure: Error code
232 * in case of failing is retkey = 0
234 DWORD WINAPI RegOpenKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
236 return RegOpenKeyExW( hkey, name, 0, KEY_ALL_ACCESS, retkey );
240 /******************************************************************************
241 * RegOpenKeyA [ADVAPI32.148]
243 DWORD WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
245 return RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, retkey );
249 /******************************************************************************
250 * RegOpenCurrentUser [ADVAPI32]
251 * FIXME: This function is supposed to retrieve a handle to the
252 * HKEY_CURRENT_USER for the user the current thread is impersonating.
253 * Since Wine does not currently allow threads to impersonate other users,
254 * this stub should work fine.
256 DWORD WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey )
258 return RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey );
263 /******************************************************************************
264 * RegEnumKeyExW [ADVAPI32.139]
267 * hkey [I] Handle to key to enumerate
268 * index [I] Index of subkey to enumerate
269 * name [O] Buffer for subkey name
270 * name_len [O] Size of subkey buffer
271 * reserved [I] Reserved
272 * class [O] Buffer for class string
273 * class_len [O] Size of class buffer
274 * ft [O] Time key last written to
276 DWORD WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_len,
277 LPDWORD reserved, LPWSTR class, LPDWORD class_len, FILETIME *ft )
280 char buffer[256], *buf_ptr = buffer;
281 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
284 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
285 name_len ? *name_len : -1, reserved, class, class_len, ft );
287 if (reserved) return ERROR_INVALID_PARAMETER;
289 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
290 buffer, sizeof(buffer), &total_size );
292 while (status == STATUS_BUFFER_OVERFLOW)
294 /* retry with a dynamically allocated buffer */
295 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
296 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
297 return ERROR_NOT_ENOUGH_MEMORY;
298 info = (KEY_NODE_INFORMATION *)buf_ptr;
299 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
300 buf_ptr, total_size, &total_size );
305 DWORD len = info->NameLength / sizeof(WCHAR);
306 DWORD cls_len = info->ClassLength / sizeof(WCHAR);
308 if (ft) *ft = info->LastWriteTime;
310 if (len >= *name_len || (class_len && (cls_len >= *class_len)))
311 status = STATUS_BUFFER_OVERFLOW;
315 memcpy( name, info->Name, info->NameLength );
319 *class_len = cls_len;
322 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
329 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
330 return RtlNtStatusToDosError( status );
334 /******************************************************************************
335 * RegEnumKeyExA [ADVAPI32.138]
337 DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len,
338 LPDWORD reserved, LPSTR class, LPDWORD class_len, FILETIME *ft )
341 char buffer[256], *buf_ptr = buffer;
342 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
345 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
346 name_len ? *name_len : -1, reserved, class, class_len, ft );
348 if (reserved) return ERROR_INVALID_PARAMETER;
350 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
351 buffer, sizeof(buffer), &total_size );
353 while (status == STATUS_BUFFER_OVERFLOW)
355 /* retry with a dynamically allocated buffer */
356 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
357 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
358 return ERROR_NOT_ENOUGH_MEMORY;
359 info = (KEY_NODE_INFORMATION *)buf_ptr;
360 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
361 buf_ptr, total_size, &total_size );
366 DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
367 NULL, 0, NULL, NULL );
368 DWORD cls_len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
369 info->ClassLength / sizeof(WCHAR),
370 NULL, 0, NULL, NULL );
372 if (ft) *ft = info->LastWriteTime;
374 if (len >= *name_len || (class_len && (cls_len >= *class_len)))
375 status = STATUS_BUFFER_OVERFLOW;
379 WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
380 name, len, NULL, NULL );
384 *class_len = cls_len;
387 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
388 info->ClassLength / sizeof(WCHAR),
389 class, cls_len, NULL, NULL );
396 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
397 return RtlNtStatusToDosError( status );
401 /******************************************************************************
402 * RegEnumKeyW [ADVAPI32.140]
404 DWORD WINAPI RegEnumKeyW( HKEY hkey, DWORD index, LPWSTR name, DWORD name_len )
406 return RegEnumKeyExW( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
410 /******************************************************************************
411 * RegEnumKeyA [ADVAPI32.137]
413 DWORD WINAPI RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
415 return RegEnumKeyExA( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
419 /******************************************************************************
420 * RegQueryInfoKeyW [ADVAPI32.153]
423 * hkey [I] Handle to key to query
424 * class [O] Buffer for class string
425 * class_len [O] Size of class string buffer
426 * reserved [I] Reserved
427 * subkeys [O] Buffer for number of subkeys
428 * max_subkey [O] Buffer for longest subkey name length
429 * max_class [O] Buffer for longest class string length
430 * values [O] Buffer for number of value entries
431 * max_value [O] Buffer for longest value name length
432 * max_data [O] Buffer for longest value data length
433 * security [O] Buffer for security descriptor length
434 * modif [O] Modification time
436 * - win95 allows class to be valid and class_len to be NULL
437 * - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
438 * - both allow class to be NULL and class_len to be NULL
439 * (it's hard to test validity, so test !NULL instead)
441 DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWORD reserved,
442 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
443 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
444 LPDWORD security, FILETIME *modif )
447 char buffer[256], *buf_ptr = buffer;
448 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
451 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
452 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
454 if (class && !class_len && !(GetVersion() & 0x80000000 /*NT*/))
455 return ERROR_INVALID_PARAMETER;
457 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
461 /* retry with a dynamically allocated buffer */
462 while (status == STATUS_BUFFER_OVERFLOW)
464 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
465 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
466 return ERROR_NOT_ENOUGH_MEMORY;
467 info = (KEY_FULL_INFORMATION *)buf_ptr;
468 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
473 if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len))
475 status = STATUS_BUFFER_OVERFLOW;
479 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
480 class[info->ClassLength/sizeof(WCHAR)] = 0;
485 if (!status || status == STATUS_BUFFER_OVERFLOW)
487 if (class_len) *class_len = info->ClassLength / sizeof(WCHAR);
488 if (subkeys) *subkeys = info->SubKeys;
489 if (max_subkey) *max_subkey = info->MaxNameLen;
490 if (max_class) *max_class = info->MaxClassLen;
491 if (values) *values = info->Values;
492 if (max_value) *max_value = info->MaxValueNameLen;
493 if (max_data) *max_data = info->MaxValueDataLen;
494 if (modif) *modif = info->LastWriteTime;
497 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
498 return RtlNtStatusToDosError( status );
502 /******************************************************************************
503 * RegQueryInfoKeyA [ADVAPI32.152]
505 DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWORD reserved,
506 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
507 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
508 LPDWORD security, FILETIME *modif )
511 char buffer[256], *buf_ptr = buffer;
512 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
515 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
516 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
518 if (class && !class_len && !(GetVersion() & 0x80000000 /*NT*/))
519 return ERROR_INVALID_PARAMETER;
521 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
523 if (class || class_len)
525 /* retry with a dynamically allocated buffer */
526 while (status == STATUS_BUFFER_OVERFLOW)
528 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
529 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
530 return ERROR_NOT_ENOUGH_MEMORY;
531 info = (KEY_FULL_INFORMATION *)buf_ptr;
532 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
537 DWORD len = WideCharToMultiByte( CP_ACP, 0,
538 (WCHAR *)(buf_ptr + info->ClassOffset),
539 info->ClassLength/sizeof(WCHAR),
540 NULL, 0, NULL, NULL );
543 if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
546 if (class && !status)
548 WideCharToMultiByte( CP_ACP, 0,
549 (WCHAR *)(buf_ptr + info->ClassOffset),
550 info->ClassLength/sizeof(WCHAR),
551 class, len, NULL, NULL );
557 if (!status || status == STATUS_BUFFER_OVERFLOW)
559 if (subkeys) *subkeys = info->SubKeys;
560 if (max_subkey) *max_subkey = info->MaxNameLen;
561 if (max_class) *max_class = info->MaxClassLen;
562 if (values) *values = info->Values;
563 if (max_value) *max_value = info->MaxValueNameLen;
564 if (max_data) *max_data = info->MaxValueDataLen;
565 if (modif) *modif = info->LastWriteTime;
568 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
569 return RtlNtStatusToDosError( status );
573 /******************************************************************************
574 * RegCloseKey [ADVAPI32.126]
576 * Releases the handle of the specified key
579 * hkey [I] Handle of key to close
582 * Success: ERROR_SUCCESS
583 * Failure: Error code
585 DWORD WINAPI RegCloseKey( HKEY hkey )
587 if (!hkey || hkey >= 0x80000000) return ERROR_SUCCESS;
588 return RtlNtStatusToDosError( NtClose( hkey ) );
592 /******************************************************************************
593 * RegDeleteKeyW [ADVAPI32.134]
596 * hkey [I] Handle to open key
597 * name [I] Name of subkey to delete
600 * Success: ERROR_SUCCESS
601 * Failure: Error code
603 DWORD WINAPI RegDeleteKeyW( HKEY hkey, LPCWSTR name )
608 if (!name || !*name) return NtDeleteKey( hkey );
609 if (!(ret = RegOpenKeyExW( hkey, name, 0, 0, &tmp )))
611 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
618 /******************************************************************************
619 * RegDeleteKeyA [ADVAPI32.133]
621 DWORD WINAPI RegDeleteKeyA( HKEY hkey, LPCSTR name )
626 if (!name || !*name) return NtDeleteKey( hkey );
627 if (!(ret = RegOpenKeyExA( hkey, name, 0, 0, &tmp )))
629 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
637 /******************************************************************************
638 * RegSetValueExW [ADVAPI32.170]
640 * Sets the data and type of a value under a register key
643 * hkey [I] Handle of key to set value for
644 * name [I] Name of value to set
645 * reserved [I] Reserved - must be zero
646 * type [I] Flag for value type
647 * data [I] Address of value data
648 * count [I] Size of value data
651 * Success: ERROR_SUCCESS
652 * Failure: Error code
655 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
656 * NT does definitely care (aj)
658 DWORD WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
659 DWORD type, CONST BYTE *data, DWORD count )
661 UNICODE_STRING nameW;
663 if (count && is_string(type))
665 LPCWSTR str = (LPCWSTR)data;
666 /* if user forgot to count terminating null, add it (yes NT does this) */
667 if (str[count / sizeof(WCHAR) - 1] && !str[count / sizeof(WCHAR)])
668 count += sizeof(WCHAR);
671 RtlInitUnicodeString( &nameW, name );
672 return RtlNtStatusToDosError( NtSetValueKey( hkey, &nameW, 0, type, data, count ) );
676 /******************************************************************************
677 * RegSetValueExA [ADVAPI32.169]
679 DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
680 CONST BYTE *data, DWORD count )
682 UNICODE_STRING nameW;
687 if (count && is_string(type))
689 /* if user forgot to count terminating null, add it (yes NT does this) */
690 if (data[count-1] && !data[count]) count++;
693 if (is_string( type )) /* need to convert to Unicode */
695 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, data, count, NULL, 0 );
696 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW*sizeof(WCHAR) )))
697 return ERROR_OUTOFMEMORY;
698 MultiByteToWideChar( CP_ACP, 0, data, count, dataW, lenW );
699 count = lenW * sizeof(WCHAR);
700 data = (BYTE *)dataW;
703 RtlInitAnsiString( &nameA, name );
704 /* FIXME: should use Unicode buffer in TEB */
705 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
707 status = NtSetValueKey( hkey, &nameW, 0, type, data, count );
708 RtlFreeUnicodeString( &nameW );
710 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
711 return RtlNtStatusToDosError( status );
715 /******************************************************************************
716 * RegSetValueW [ADVAPI32.171]
718 DWORD WINAPI RegSetValueW( HKEY hkey, LPCWSTR name, DWORD type, LPCWSTR data, DWORD count )
723 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
725 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
727 if (name && name[0]) /* need to create the subkey */
729 if ((ret = RegCreateKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
732 ret = RegSetValueExW( subkey, NULL, 0, REG_SZ, (LPBYTE)data,
733 (strlenW( data ) + 1) * sizeof(WCHAR) );
734 if (subkey != hkey) RegCloseKey( subkey );
739 /******************************************************************************
740 * RegSetValueA [ADVAPI32.168]
742 DWORD WINAPI RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
747 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_a(name), type, debugstr_a(data), count );
749 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
751 if (name && name[0]) /* need to create the subkey */
753 if ((ret = RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
755 ret = RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
756 if (subkey != hkey) RegCloseKey( subkey );
762 /******************************************************************************
763 * RegQueryValueExW [ADVAPI32.158]
765 * Retrieves type and data for a specified name associated with an open key
768 * hkey [I] Handle of key to query
769 * name [I] Name of value to query
770 * reserved [I] Reserved - must be NULL
771 * type [O] Address of buffer for value type. If NULL, the type
773 * data [O] Address of data buffer. If NULL, the actual data is
775 * count [I/O] Address of data buffer size
778 * ERROR_SUCCESS: Success
779 * ERROR_MORE_DATA: !!! if the specified buffer is not big enough to hold the data
780 * buffer is left untouched. The MS-documentation is wrong (js) !!!
782 DWORD WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDWORD type,
783 LPBYTE data, LPDWORD count )
786 UNICODE_STRING name_str;
788 char buffer[256], *buf_ptr = buffer;
789 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
790 static const int info_size = sizeof(*info) - sizeof(info->Data);
792 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
793 hkey, debugstr_w(name), reserved, type, data, count, count ? *count : 0 );
795 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
797 RtlInitUnicodeString( &name_str, name );
799 if (data) total_size = min( sizeof(buffer), *count + info_size );
800 else total_size = info_size;
802 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
803 buffer, total_size, &total_size );
804 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
808 /* retry with a dynamically allocated buffer */
809 while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
811 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
812 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
813 return ERROR_NOT_ENOUGH_MEMORY;
814 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
815 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
816 buf_ptr, total_size, &total_size );
821 memcpy( data, buf_ptr + info_size, total_size - info_size );
822 /* if the type is REG_SZ and data is not 0-terminated
823 * and there is enough space in the buffer NT appends a \0 */
824 if (total_size - info_size <= *count-sizeof(WCHAR) && is_string(info->Type))
826 WCHAR *ptr = (WCHAR *)(data + total_size - info_size);
827 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
830 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
833 if (type) *type = info->Type;
834 if (count) *count = total_size - info_size;
837 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
838 return RtlNtStatusToDosError(status);
842 /******************************************************************************
843 * RegQueryValueExA [ADVAPI32.157]
846 * the documentation is wrong: if the buffer is too small it remains untouched
848 DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
849 LPBYTE data, LPDWORD count )
853 UNICODE_STRING nameW;
855 char buffer[256], *buf_ptr = buffer;
856 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
857 static const int info_size = sizeof(*info) - sizeof(info->Data);
859 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
860 hkey, debugstr_a(name), reserved, type, data, count, count ? *count : 0 );
862 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
864 RtlInitAnsiString( &nameA, name );
865 /* FIXME: should use Unicode buffer in TEB */
866 if ((status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
867 return RtlNtStatusToDosError(status);
869 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
870 buffer, sizeof(buffer), &total_size );
871 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
873 /* we need to fetch the contents for a string type even if not requested,
874 * because we need to compute the length of the ASCII string. */
875 if (data || is_string(info->Type))
877 /* retry with a dynamically allocated buffer */
878 while (status == STATUS_BUFFER_OVERFLOW)
880 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
881 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
883 status = STATUS_NO_MEMORY;
886 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
887 status = NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
888 buf_ptr, total_size, &total_size );
893 if (is_string(info->Type))
895 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
896 (total_size - info_size) /sizeof(WCHAR),
897 NULL, 0, NULL, NULL );
900 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
903 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
904 (total_size - info_size) /sizeof(WCHAR),
905 data, len, NULL, NULL );
906 /* if the type is REG_SZ and data is not 0-terminated
907 * and there is enough space in the buffer NT appends a \0 */
908 if (len < *count && data[len-1]) data[len] = 0;
911 total_size = len + info_size;
915 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
916 else memcpy( data, buf_ptr + info_size, total_size - info_size );
919 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
922 if (type) *type = info->Type;
923 if (count) *count = total_size - info_size;
926 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
927 RtlFreeUnicodeString( &nameW );
928 return RtlNtStatusToDosError(status);
932 /******************************************************************************
933 * RegQueryValueW [ADVAPI32.159]
935 DWORD WINAPI RegQueryValueW( HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count )
940 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_w(name), data, count ? *count : 0 );
944 if ((ret = RegOpenKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
946 ret = RegQueryValueExW( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
947 if (subkey != hkey) RegCloseKey( subkey );
948 if (ret == ERROR_FILE_NOT_FOUND)
950 /* return empty string if default value not found */
952 if (count) *count = 1;
959 /******************************************************************************
960 * RegQueryValueA [ADVAPI32.156]
962 DWORD WINAPI RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
967 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_a(name), data, count ? *count : 0 );
971 if ((ret = RegOpenKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
973 ret = RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
974 if (subkey != hkey) RegCloseKey( subkey );
975 if (ret == ERROR_FILE_NOT_FOUND)
977 /* return empty string if default value not found */
979 if (count) *count = 1;
986 /******************************************************************************
987 * RegEnumValueW [ADVAPI32.142]
990 * hkey [I] Handle to key to query
991 * index [I] Index of value to query
992 * value [O] Value string
993 * val_count [I/O] Size of value buffer (in wchars)
994 * reserved [I] Reserved
996 * data [O] Value data
997 * count [I/O] Size of data buffer (in bytes)
1000 DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_count,
1001 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1004 struct enum_key_value_request *req = get_req_buffer();
1006 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1007 hkey, index, value, val_count, reserved, type, data, count );
1009 /* NT only checks count, not val_count */
1010 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1015 if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
1017 len = strlenW( req->name ) + 1;
1018 if (len > *val_count) return ERROR_MORE_DATA;
1019 memcpy( value, req->name, len * sizeof(WCHAR) );
1020 *val_count = len - 1;
1024 if (*count < req->len) ret = ERROR_MORE_DATA;
1028 unsigned int max = server_remaining( req->data );
1029 unsigned int pos = 0;
1030 while (pos < req->len)
1032 unsigned int len = min( req->len - pos, max );
1033 memcpy( data + pos, req->data, len );
1034 if ((pos += len) >= req->len) break;
1036 if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
1039 /* if the type is REG_SZ and data is not 0-terminated
1040 * and there is enough space in the buffer NT appends a \0 */
1041 if (req->len && is_string(req->type) &&
1042 (req->len < *count) && ((WCHAR *)data)[req->len-1]) ((WCHAR *)data)[req->len] = 0;
1044 if (type) *type = req->type;
1045 if (count) *count = req->len;
1050 /******************************************************************************
1051 * RegEnumValueA [ADVAPI32.141]
1053 DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
1054 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1056 DWORD ret, len, total_len;
1057 struct enum_key_value_request *req = get_req_buffer();
1059 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1060 hkey, index, value, val_count, reserved, type, data, count );
1062 /* NT only checks count, not val_count */
1063 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1068 if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
1070 len = strlenW( req->name ) + 1;
1071 if (len > *val_count) return ERROR_MORE_DATA;
1072 memcpyWtoA( value, req->name, len );
1073 *val_count = len - 1;
1075 total_len = is_string( req->type ) ? req->len/sizeof(WCHAR) : req->len;
1079 if (*count < total_len) ret = ERROR_MORE_DATA;
1083 unsigned int max = server_remaining( req->data );
1084 unsigned int pos = 0;
1085 while (pos < req->len)
1087 unsigned int len = min( req->len - pos, max );
1088 if (is_string( req->type ))
1089 memcpyWtoA( data + pos/sizeof(WCHAR), (WCHAR *)req->data, len/sizeof(WCHAR) );
1091 memcpy( data + pos, req->data, len );
1092 if ((pos += len) >= req->len) break;
1094 if ((ret = reg_server_call( REQ_ENUM_KEY_VALUE )) != ERROR_SUCCESS) return ret;
1097 /* if the type is REG_SZ and data is not 0-terminated
1098 * and there is enough space in the buffer NT appends a \0 */
1099 if (total_len && is_string(req->type) && (total_len < *count) && data[total_len-1])
1100 data[total_len] = 0;
1103 if (count) *count = total_len;
1104 if (type) *type = req->type;
1110 /******************************************************************************
1111 * RegDeleteValueW [ADVAPI32.136]
1114 * hkey [I] handle to key
1115 * name [I] name of value to delete
1120 DWORD WINAPI RegDeleteValueW( HKEY hkey, LPCWSTR name )
1122 UNICODE_STRING nameW;
1123 RtlInitUnicodeString( &nameW, name );
1124 return RtlNtStatusToDosError( NtDeleteValueKey( hkey, &nameW ) );
1128 /******************************************************************************
1129 * RegDeleteValueA [ADVAPI32.135]
1131 DWORD WINAPI RegDeleteValueA( HKEY hkey, LPCSTR name )
1133 UNICODE_STRING nameW;
1137 RtlInitAnsiString( &nameA, name );
1138 /* FIXME: should use Unicode buffer in TEB */
1139 if (!(status = RtlAnsiStringToUnicodeString( &nameW, &nameA, TRUE )))
1141 status = NtDeleteValueKey( hkey, &nameW );
1142 RtlFreeUnicodeString( &nameW );
1144 return RtlNtStatusToDosError( status );
1148 /******************************************************************************
1149 * RegLoadKeyW [ADVAPI32.185]
1152 * hkey [I] Handle of open key
1153 * subkey [I] Address of name of subkey
1154 * filename [I] Address of filename for registry information
1156 LONG WINAPI RegLoadKeyW( HKEY hkey, LPCWSTR subkey, LPCWSTR filename )
1159 DWORD ret, len, err = GetLastError();
1161 TRACE( "(%x,%s,%s)\n", hkey, debugstr_w(subkey), debugstr_w(filename) );
1163 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1164 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1166 len = strlenW( subkey ) * sizeof(WCHAR);
1167 if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
1169 if ((file = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1170 FILE_ATTRIBUTE_NORMAL, -1 )) == INVALID_HANDLE_VALUE)
1172 ret = GetLastError();
1178 struct load_registry_request *req = server_alloc_req( sizeof(*req), len );
1181 memcpy( server_data_ptr(req), subkey, len );
1182 ret = reg_server_call( REQ_LOAD_REGISTRY );
1185 CloseHandle( file );
1188 SetLastError( err ); /* restore the last error code */
1193 /******************************************************************************
1194 * RegLoadKeyA [ADVAPI32.184]
1196 LONG WINAPI RegLoadKeyA( HKEY hkey, LPCSTR subkey, LPCSTR filename )
1199 DWORD ret, len, err = GetLastError();
1201 TRACE( "(%x,%s,%s)\n", hkey, debugstr_a(subkey), debugstr_a(filename) );
1203 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1204 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1206 len = MultiByteToWideChar( CP_ACP, 0, subkey, strlen(subkey), NULL, 0 ) * sizeof(WCHAR);
1207 if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
1209 if ((file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1210 FILE_ATTRIBUTE_NORMAL, -1 )) == INVALID_HANDLE_VALUE)
1212 ret = GetLastError();
1218 struct load_registry_request *req = server_alloc_req( sizeof(*req), len );
1221 MultiByteToWideChar( CP_ACP, 0, subkey, strlen(subkey),
1222 server_data_ptr(req), len/sizeof(WCHAR) );
1223 ret = reg_server_call( REQ_LOAD_REGISTRY );
1226 CloseHandle( file );
1229 SetLastError( err ); /* restore the last error code */
1234 /******************************************************************************
1235 * RegSaveKeyA [ADVAPI32.165]
1238 * hkey [I] Handle of key where save begins
1239 * lpFile [I] Address of filename to save to
1240 * sa [I] Address of security structure
1242 LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa )
1250 TRACE( "(%x,%s,%p)\n", hkey, debugstr_a(file), sa );
1252 if (!file || !*file) return ERROR_INVALID_PARAMETER;
1254 err = GetLastError();
1255 GetFullPathNameA( file, sizeof(buffer), buffer, &name );
1258 sprintf( name, "reg%04x.tmp", count++ );
1259 handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL,
1260 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, -1 );
1261 if (handle != INVALID_HANDLE_VALUE) break;
1262 if ((ret = GetLastError()) != ERROR_ALREADY_EXISTS) goto done;
1264 /* Something gone haywire ? Please report if this happens abnormally */
1266 MESSAGE("Wow, we are already fiddling with a temp file %s with an ordinal as high as %d !\nYou might want to delete all corresponding temp files in that directory.\n", buffer, count);
1271 struct save_registry_request *req = server_alloc_req( sizeof(*req), 0 );
1274 ret = reg_server_call( REQ_SAVE_REGISTRY );
1278 CloseHandle( handle );
1281 if (!MoveFileExA( buffer, file, MOVEFILE_REPLACE_EXISTING ))
1283 ERR( "Failed to move %s to %s\n", buffer, file );
1284 ret = GetLastError();
1287 if (ret) DeleteFileA( buffer );
1290 SetLastError( err ); /* restore last error code */
1295 /******************************************************************************
1296 * RegSaveKeyW [ADVAPI32.166]
1298 LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
1300 LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file );
1301 DWORD ret = RegSaveKeyA( hkey, fileA, sa );
1302 if (fileA) HeapFree( GetProcessHeap(), 0, fileA );
1307 /******************************************************************************
1308 * RegRestoreKeyW [ADVAPI32.164]
1311 * hkey [I] Handle of key where restore begins
1312 * lpFile [I] Address of filename containing saved tree
1313 * dwFlags [I] Optional flags
1315 LONG WINAPI RegRestoreKeyW( HKEY hkey, LPCWSTR lpFile, DWORD dwFlags )
1317 TRACE("(%x,%s,%ld)\n",hkey,debugstr_w(lpFile),dwFlags);
1319 /* It seems to do this check before the hkey check */
1320 if (!lpFile || !*lpFile)
1321 return ERROR_INVALID_PARAMETER;
1323 FIXME("(%x,%s,%ld): stub\n",hkey,debugstr_w(lpFile),dwFlags);
1325 /* Check for file existence */
1327 return ERROR_SUCCESS;
1331 /******************************************************************************
1332 * RegRestoreKeyA [ADVAPI32.163]
1334 LONG WINAPI RegRestoreKeyA( HKEY hkey, LPCSTR lpFile, DWORD dwFlags )
1336 LPWSTR lpFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpFile );
1337 LONG ret = RegRestoreKeyW( hkey, lpFileW, dwFlags );
1338 HeapFree( GetProcessHeap(), 0, lpFileW );
1343 /******************************************************************************
1344 * RegUnLoadKeyW [ADVAPI32.173]
1347 * hkey [I] Handle of open key
1348 * lpSubKey [I] Address of name of subkey to unload
1350 LONG WINAPI RegUnLoadKeyW( HKEY hkey, LPCWSTR lpSubKey )
1352 FIXME("(%x,%s): stub\n",hkey, debugstr_w(lpSubKey));
1353 return ERROR_SUCCESS;
1357 /******************************************************************************
1358 * RegUnLoadKeyA [ADVAPI32.172]
1360 LONG WINAPI RegUnLoadKeyA( HKEY hkey, LPCSTR lpSubKey )
1362 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1363 LONG ret = RegUnLoadKeyW( hkey, lpSubKeyW );
1364 if(lpSubKeyW) HeapFree( GetProcessHeap(), 0, lpSubKeyW);
1369 /******************************************************************************
1370 * RegReplaceKeyW [ADVAPI32.162]
1373 * hkey [I] Handle of open key
1374 * lpSubKey [I] Address of name of subkey
1375 * lpNewFile [I] Address of filename for file with new data
1376 * lpOldFile [I] Address of filename for backup file
1378 LONG WINAPI RegReplaceKeyW( HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpNewFile,
1381 FIXME("(%x,%s,%s,%s): stub\n", hkey, debugstr_w(lpSubKey),
1382 debugstr_w(lpNewFile),debugstr_w(lpOldFile));
1383 return ERROR_SUCCESS;
1387 /******************************************************************************
1388 * RegReplaceKeyA [ADVAPI32.161]
1390 LONG WINAPI RegReplaceKeyA( HKEY hkey, LPCSTR lpSubKey, LPCSTR lpNewFile,
1393 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1394 LPWSTR lpNewFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpNewFile );
1395 LPWSTR lpOldFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpOldFile );
1396 LONG ret = RegReplaceKeyW( hkey, lpSubKeyW, lpNewFileW, lpOldFileW );
1397 HeapFree( GetProcessHeap(), 0, lpOldFileW );
1398 HeapFree( GetProcessHeap(), 0, lpNewFileW );
1399 HeapFree( GetProcessHeap(), 0, lpSubKeyW );
1404 /******************************************************************************
1405 * RegSetKeySecurity [ADVAPI32.167]
1408 * hkey [I] Open handle of key to set
1409 * SecurityInfo [I] Descriptor contents
1410 * pSecurityDesc [I] Address of descriptor for key
1412 LONG WINAPI RegSetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInfo,
1413 PSECURITY_DESCRIPTOR pSecurityDesc )
1415 TRACE("(%x,%ld,%p)\n",hkey,SecurityInfo,pSecurityDesc);
1417 /* It seems to perform this check before the hkey check */
1418 if ((SecurityInfo & OWNER_SECURITY_INFORMATION) ||
1419 (SecurityInfo & GROUP_SECURITY_INFORMATION) ||
1420 (SecurityInfo & DACL_SECURITY_INFORMATION) ||
1421 (SecurityInfo & SACL_SECURITY_INFORMATION)) {
1424 return ERROR_INVALID_PARAMETER;
1427 return ERROR_INVALID_PARAMETER;
1429 FIXME(":(%x,%ld,%p): stub\n",hkey,SecurityInfo,pSecurityDesc);
1431 return ERROR_SUCCESS;
1435 /******************************************************************************
1436 * RegGetKeySecurity [ADVAPI32.144]
1437 * Retrieves a copy of security descriptor protecting the registry key
1440 * hkey [I] Open handle of key to set
1441 * SecurityInformation [I] Descriptor contents
1442 * pSecurityDescriptor [O] Address of descriptor for key
1443 * lpcbSecurityDescriptor [I/O] Address of size of buffer and description
1446 * Success: ERROR_SUCCESS
1447 * Failure: Error code
1449 LONG WINAPI RegGetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInformation,
1450 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1451 LPDWORD lpcbSecurityDescriptor )
1453 TRACE("(%x,%ld,%p,%ld)\n",hkey,SecurityInformation,pSecurityDescriptor,
1454 lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1456 /* FIXME: Check for valid SecurityInformation values */
1458 if (*lpcbSecurityDescriptor < sizeof(SECURITY_DESCRIPTOR))
1459 return ERROR_INSUFFICIENT_BUFFER;
1461 FIXME("(%x,%ld,%p,%ld): stub\n",hkey,SecurityInformation,
1462 pSecurityDescriptor,lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1464 return ERROR_SUCCESS;
1468 /******************************************************************************
1469 * RegFlushKey [ADVAPI32.143]
1470 * Immediately writes key to registry.
1471 * Only returns after data has been written to disk.
1473 * FIXME: does it really wait until data is written ?
1476 * hkey [I] Handle of key to write
1479 * Success: ERROR_SUCCESS
1480 * Failure: Error code
1482 DWORD WINAPI RegFlushKey( HKEY hkey )
1484 FIXME( "(%x): stub\n", hkey );
1485 return ERROR_SUCCESS;
1489 /******************************************************************************
1490 * RegConnectRegistryW [ADVAPI32.128]
1493 * lpMachineName [I] Address of name of remote computer
1494 * hHey [I] Predefined registry handle
1495 * phkResult [I] Address of buffer for remote registry handle
1497 LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey,
1500 TRACE("(%s,%x,%p): stub\n",debugstr_w(lpMachineName),hKey,phkResult);
1502 if (!lpMachineName || !*lpMachineName) {
1503 /* Use the local machine name */
1504 return RegOpenKeyA( hKey, "", phkResult );
1507 FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName));
1508 return ERROR_BAD_NETPATH;
1512 /******************************************************************************
1513 * RegConnectRegistryA [ADVAPI32.127]
1515 LONG WINAPI RegConnectRegistryA( LPCSTR machine, HKEY hkey, LPHKEY reskey )
1517 LPWSTR machineW = HEAP_strdupAtoW( GetProcessHeap(), 0, machine );
1518 DWORD ret = RegConnectRegistryW( machineW, hkey, reskey );
1519 HeapFree( GetProcessHeap(), 0, machineW );
1524 /******************************************************************************
1525 * RegNotifyChangeKeyValue [ADVAPI32.???]
1528 * hkey [I] Handle of key to watch
1529 * fWatchSubTree [I] Flag for subkey notification
1530 * fdwNotifyFilter [I] Changes to be reported
1531 * hEvent [I] Handle of signaled event
1532 * fAsync [I] Flag for asynchronous reporting
1534 LONG WINAPI RegNotifyChangeKeyValue( HKEY hkey, BOOL fWatchSubTree,
1535 DWORD fdwNotifyFilter, HANDLE hEvent,
1538 FIXME("(%x,%i,%ld,%x,%i): stub\n",hkey,fWatchSubTree,fdwNotifyFilter,
1540 return ERROR_SUCCESS;