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.
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(reg);
44 /* check if value type needs string conversion (Ansi<->Unicode) */
45 inline static int is_string( DWORD type )
47 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
50 /* check if current version is NT or Win95 */
51 inline static int is_version_nt(void)
53 return !(GetVersion() & 0x80000000);
56 /* allowed bits for access mask */
57 #define KEY_ACCESS_MASK (KEY_ALL_ACCESS | MAXIMUM_ALLOWED)
59 /******************************************************************************
60 * RegCreateKeyExW [ADVAPI32.@]
63 * hkey [I] Handle of an open key
64 * name [I] Address of subkey name
65 * reserved [I] Reserved - must be 0
66 * class [I] Address of class string
67 * options [I] Special options flag
68 * access [I] Desired security access
69 * sa [I] Address of key security structure
70 * retkey [O] Address of buffer for opened handle
71 * dispos [O] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
74 * in case of failing retkey remains untouched
76 * FIXME MAXIMUM_ALLOWED in access mask not supported by server
78 DWORD WINAPI RegCreateKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR class,
79 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
80 LPHKEY retkey, LPDWORD dispos )
82 OBJECT_ATTRIBUTES attr;
83 UNICODE_STRING nameW, classW;
85 if (reserved) return ERROR_INVALID_PARAMETER;
86 if (!(access & KEY_ACCESS_MASK) || (access & ~KEY_ACCESS_MASK)) return ERROR_ACCESS_DENIED;
88 attr.Length = sizeof(attr);
89 attr.RootDirectory = hkey;
90 attr.ObjectName = &nameW;
92 attr.SecurityDescriptor = NULL;
93 attr.SecurityQualityOfService = NULL;
94 RtlInitUnicodeString( &nameW, name );
95 RtlInitUnicodeString( &classW, class );
97 return RtlNtStatusToDosError( NtCreateKey( retkey, access, &attr, 0,
98 &classW, options, dispos ) );
102 /******************************************************************************
103 * RegCreateKeyExA [ADVAPI32.@]
105 * FIXME MAXIMUM_ALLOWED in access mask not supported by server
107 DWORD WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR class,
108 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
109 LPHKEY retkey, LPDWORD dispos )
111 OBJECT_ATTRIBUTES attr;
112 UNICODE_STRING classW;
113 ANSI_STRING nameA, classA;
116 if (reserved) return ERROR_INVALID_PARAMETER;
117 if (!is_version_nt()) access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */
118 else if (!(access & KEY_ACCESS_MASK) || (access & ~KEY_ACCESS_MASK)) return ERROR_ACCESS_DENIED;
120 attr.Length = sizeof(attr);
121 attr.RootDirectory = hkey;
122 attr.ObjectName = &NtCurrentTeb()->StaticUnicodeString;
124 attr.SecurityDescriptor = NULL;
125 attr.SecurityQualityOfService = NULL;
126 RtlInitAnsiString( &nameA, name );
127 RtlInitAnsiString( &classA, class );
129 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
132 if (!(status = RtlAnsiStringToUnicodeString( &classW, &classA, TRUE )))
134 status = NtCreateKey( retkey, access, &attr, 0, &classW, options, dispos );
135 RtlFreeUnicodeString( &classW );
138 return RtlNtStatusToDosError( status );
142 /******************************************************************************
143 * RegCreateKeyW [ADVAPI32.@]
145 DWORD WINAPI RegCreateKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
147 /* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
148 /* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
149 return RegCreateKeyExW( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
150 KEY_ALL_ACCESS, NULL, retkey, NULL );
154 /******************************************************************************
155 * RegCreateKeyA [ADVAPI32.@]
157 DWORD WINAPI RegCreateKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
159 return RegCreateKeyExA( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
160 KEY_ALL_ACCESS, NULL, retkey, NULL );
165 /******************************************************************************
166 * RegOpenKeyExW [ADVAPI32.@]
168 * Opens the specified key
170 * Unlike RegCreateKeyEx, this does not create the key if it does not exist.
173 * hkey [I] Handle of open key
174 * name [I] Name of subkey to open
175 * reserved [I] Reserved - must be zero
176 * access [I] Security access mask
177 * retkey [O] Handle to open key
180 * Success: ERROR_SUCCESS
181 * Failure: Error code
184 * in case of failing is retkey = 0
186 DWORD WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
188 OBJECT_ATTRIBUTES attr;
189 UNICODE_STRING nameW;
191 attr.Length = sizeof(attr);
192 attr.RootDirectory = hkey;
193 attr.ObjectName = &nameW;
195 attr.SecurityDescriptor = NULL;
196 attr.SecurityQualityOfService = NULL;
197 RtlInitUnicodeString( &nameW, name );
198 return RtlNtStatusToDosError( NtOpenKey( retkey, access, &attr ) );
202 /******************************************************************************
203 * RegOpenKeyExA [ADVAPI32.@]
205 DWORD WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
207 OBJECT_ATTRIBUTES attr;
211 if (!is_version_nt()) access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */
213 attr.Length = sizeof(attr);
214 attr.RootDirectory = hkey;
215 attr.ObjectName = &NtCurrentTeb()->StaticUnicodeString;
217 attr.SecurityDescriptor = NULL;
218 attr.SecurityQualityOfService = NULL;
220 RtlInitAnsiString( &nameA, name );
221 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
224 status = NtOpenKey( retkey, access, &attr );
226 return RtlNtStatusToDosError( status );
230 /******************************************************************************
231 * RegOpenKeyW [ADVAPI32.@]
234 * hkey [I] Handle of open key
235 * name [I] Address of name of subkey to open
236 * retkey [O] Handle to open key
239 * Success: ERROR_SUCCESS
240 * Failure: Error code
243 * in case of failing is retkey = 0
245 DWORD WINAPI RegOpenKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
247 return RegOpenKeyExW( hkey, name, 0, KEY_ALL_ACCESS, retkey );
251 /******************************************************************************
252 * RegOpenKeyA [ADVAPI32.@]
254 DWORD WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
256 return RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, retkey );
260 /******************************************************************************
261 * RegOpenCurrentUser [ADVAPI32.@]
262 * FIXME: This function is supposed to retrieve a handle to the
263 * HKEY_CURRENT_USER for the user the current thread is impersonating.
264 * Since Wine does not currently allow threads to impersonate other users,
265 * this stub should work fine.
267 DWORD WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey )
269 return RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey );
274 /******************************************************************************
275 * RegEnumKeyExW [ADVAPI32.@]
278 * hkey [I] Handle to key to enumerate
279 * index [I] Index of subkey to enumerate
280 * name [O] Buffer for subkey name
281 * name_len [O] Size of subkey buffer
282 * reserved [I] Reserved
283 * class [O] Buffer for class string
284 * class_len [O] Size of class buffer
285 * ft [O] Time key last written to
287 DWORD WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_len,
288 LPDWORD reserved, LPWSTR class, LPDWORD class_len, FILETIME *ft )
291 char buffer[256], *buf_ptr = buffer;
292 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
295 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
296 name_len ? *name_len : -1, reserved, class, class_len, ft );
298 if (reserved) return ERROR_INVALID_PARAMETER;
300 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
301 buffer, sizeof(buffer), &total_size );
303 while (status == STATUS_BUFFER_OVERFLOW)
305 /* retry with a dynamically allocated buffer */
306 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
307 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
308 return ERROR_NOT_ENOUGH_MEMORY;
309 info = (KEY_NODE_INFORMATION *)buf_ptr;
310 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
311 buf_ptr, total_size, &total_size );
316 DWORD len = info->NameLength / sizeof(WCHAR);
317 DWORD cls_len = info->ClassLength / sizeof(WCHAR);
319 if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
321 if (len >= *name_len || (class && class_len && (cls_len >= *class_len)))
322 status = STATUS_BUFFER_OVERFLOW;
326 memcpy( name, info->Name, info->NameLength );
330 *class_len = cls_len;
333 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
340 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
341 return RtlNtStatusToDosError( status );
345 /******************************************************************************
346 * RegEnumKeyExA [ADVAPI32.@]
348 DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len,
349 LPDWORD reserved, LPSTR class, LPDWORD class_len, FILETIME *ft )
352 char buffer[256], *buf_ptr = buffer;
353 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
356 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
357 name_len ? *name_len : -1, reserved, class, class_len, ft );
359 if (reserved) return ERROR_INVALID_PARAMETER;
361 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
362 buffer, sizeof(buffer), &total_size );
364 while (status == STATUS_BUFFER_OVERFLOW)
366 /* retry with a dynamically allocated buffer */
367 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
368 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
369 return ERROR_NOT_ENOUGH_MEMORY;
370 info = (KEY_NODE_INFORMATION *)buf_ptr;
371 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
372 buf_ptr, total_size, &total_size );
379 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
380 RtlUnicodeToMultiByteSize( &cls_len, (WCHAR *)(buf_ptr + info->ClassOffset),
382 if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
384 if (len >= *name_len || (class && class_len && (cls_len >= *class_len)))
385 status = STATUS_BUFFER_OVERFLOW;
389 RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
393 *class_len = cls_len;
396 RtlUnicodeToMultiByteN( class, cls_len, NULL,
397 (WCHAR *)(buf_ptr + info->ClassOffset),
405 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
406 return RtlNtStatusToDosError( status );
410 /******************************************************************************
411 * RegEnumKeyW [ADVAPI32.@]
413 DWORD WINAPI RegEnumKeyW( HKEY hkey, DWORD index, LPWSTR name, DWORD name_len )
415 return RegEnumKeyExW( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
419 /******************************************************************************
420 * RegEnumKeyA [ADVAPI32.@]
422 DWORD WINAPI RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
424 return RegEnumKeyExA( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
428 /******************************************************************************
429 * RegQueryInfoKeyW [ADVAPI32.@]
432 * hkey [I] Handle to key to query
433 * class [O] Buffer for class string
434 * class_len [O] Size of class string buffer
435 * reserved [I] Reserved
436 * subkeys [O] Buffer for number of subkeys
437 * max_subkey [O] Buffer for longest subkey name length
438 * max_class [O] Buffer for longest class string length
439 * values [O] Buffer for number of value entries
440 * max_value [O] Buffer for longest value name length
441 * max_data [O] Buffer for longest value data length
442 * security [O] Buffer for security descriptor length
443 * modif [O] Modification time
445 * - win95 allows class to be valid and class_len to be NULL
446 * - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
447 * - both allow class to be NULL and class_len to be NULL
448 * (it's hard to test validity, so test !NULL instead)
450 DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWORD reserved,
451 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
452 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
453 LPDWORD security, FILETIME *modif )
456 char buffer[256], *buf_ptr = buffer;
457 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
460 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
461 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
463 if (class && !class_len && is_version_nt()) return ERROR_INVALID_PARAMETER;
465 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
466 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
470 /* retry with a dynamically allocated buffer */
471 while (status == STATUS_BUFFER_OVERFLOW)
473 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
474 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
475 return ERROR_NOT_ENOUGH_MEMORY;
476 info = (KEY_FULL_INFORMATION *)buf_ptr;
477 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
480 if (status) goto done;
482 if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len))
484 status = STATUS_BUFFER_OVERFLOW;
488 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
489 class[info->ClassLength/sizeof(WCHAR)] = 0;
492 else status = STATUS_SUCCESS;
494 if (class_len) *class_len = info->ClassLength / sizeof(WCHAR);
495 if (subkeys) *subkeys = info->SubKeys;
496 if (max_subkey) *max_subkey = info->MaxNameLen;
497 if (max_class) *max_class = info->MaxClassLen;
498 if (values) *values = info->Values;
499 if (max_value) *max_value = info->MaxValueNameLen;
500 if (max_data) *max_data = info->MaxValueDataLen;
501 if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
504 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
505 return RtlNtStatusToDosError( status );
509 /******************************************************************************
510 * RegQueryInfoKeyA [ADVAPI32.@]
512 DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWORD reserved,
513 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
514 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
515 LPDWORD security, FILETIME *modif )
518 char buffer[256], *buf_ptr = buffer;
519 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
520 DWORD total_size, len;
522 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
523 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
525 if (class && !class_len && is_version_nt()) return ERROR_INVALID_PARAMETER;
527 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
528 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
530 if (class || class_len)
532 /* retry with a dynamically allocated buffer */
533 while (status == STATUS_BUFFER_OVERFLOW)
535 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
536 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
537 return ERROR_NOT_ENOUGH_MEMORY;
538 info = (KEY_FULL_INFORMATION *)buf_ptr;
539 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
542 if (status) goto done;
544 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->ClassOffset), info->ClassLength);
547 if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
550 if (class && !status)
552 RtlUnicodeToMultiByteN( class, len, NULL, (WCHAR *)(buf_ptr + info->ClassOffset),
557 else status = STATUS_SUCCESS;
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 = *(FILETIME *)&info->LastWriteTime;
568 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
569 return RtlNtStatusToDosError( status );
573 /******************************************************************************
574 * RegCloseKey [ADVAPI32.@]
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.@]
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.@]
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.@]
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 (!is_version_nt()) /* win95 */
665 if (type == REG_SZ) count = (strlenW( (WCHAR *)data ) + 1) * sizeof(WCHAR);
667 else if (count && is_string(type))
669 LPCWSTR str = (LPCWSTR)data;
670 /* if user forgot to count terminating null, add it (yes NT does this) */
671 if (str[count / sizeof(WCHAR) - 1] && !str[count / sizeof(WCHAR)])
672 count += sizeof(WCHAR);
675 RtlInitUnicodeString( &nameW, name );
676 return RtlNtStatusToDosError( NtSetValueKey( hkey, &nameW, 0, type, data, count ) );
680 /******************************************************************************
681 * RegSetValueExA [ADVAPI32.@]
683 DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
684 CONST BYTE *data, DWORD count )
690 if (!is_version_nt()) /* win95 */
692 if (type == REG_SZ) count = strlen(data) + 1;
694 else if (count && is_string(type))
696 /* if user forgot to count terminating null, add it (yes NT does this) */
697 if (data[count-1] && !data[count]) count++;
700 if (is_string( type )) /* need to convert to Unicode */
703 RtlMultiByteToUnicodeSize( &lenW, data, count );
704 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
705 RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
707 data = (BYTE *)dataW;
710 RtlInitAnsiString( &nameA, name );
711 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
714 status = NtSetValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString, 0, type, data, count );
716 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
717 return RtlNtStatusToDosError( status );
721 /******************************************************************************
722 * RegSetValueW [ADVAPI32.@]
724 DWORD WINAPI RegSetValueW( HKEY hkey, LPCWSTR name, DWORD type, LPCWSTR data, DWORD count )
729 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
731 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
733 if (name && name[0]) /* need to create the subkey */
735 if ((ret = RegCreateKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
738 ret = RegSetValueExW( subkey, NULL, 0, REG_SZ, (LPBYTE)data,
739 (strlenW( data ) + 1) * sizeof(WCHAR) );
740 if (subkey != hkey) RegCloseKey( subkey );
745 /******************************************************************************
746 * RegSetValueA [ADVAPI32.@]
748 DWORD WINAPI RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
753 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_a(name), type, debugstr_a(data), count );
755 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
757 if (name && name[0]) /* need to create the subkey */
759 if ((ret = RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
761 ret = RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
762 if (subkey != hkey) RegCloseKey( subkey );
768 /******************************************************************************
769 * RegQueryValueExW [ADVAPI32.@]
771 * Retrieves type and data for a specified name associated with an open key
774 * hkey [I] Handle of key to query
775 * name [I] Name of value to query
776 * reserved [I] Reserved - must be NULL
777 * type [O] Address of buffer for value type. If NULL, the type
779 * data [O] Address of data buffer. If NULL, the actual data is
781 * count [I/O] Address of data buffer size
784 * ERROR_SUCCESS: Success
785 * ERROR_MORE_DATA: !!! if the specified buffer is not big enough to hold the data
786 * buffer is left untouched. The MS-documentation is wrong (js) !!!
788 DWORD WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDWORD type,
789 LPBYTE data, LPDWORD count )
792 UNICODE_STRING name_str;
794 char buffer[256], *buf_ptr = buffer;
795 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
796 static const int info_size = info->Data - (UCHAR *)info;
798 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
799 hkey, debugstr_w(name), reserved, type, data, count, count ? *count : 0 );
801 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
803 RtlInitUnicodeString( &name_str, name );
805 if (data) total_size = min( sizeof(buffer), *count + info_size );
806 else total_size = info_size;
808 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
809 buffer, total_size, &total_size );
810 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
814 /* retry with a dynamically allocated buffer */
815 while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
817 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
818 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
819 return ERROR_NOT_ENOUGH_MEMORY;
820 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
821 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
822 buf_ptr, total_size, &total_size );
827 memcpy( data, buf_ptr + info_size, total_size - info_size );
828 /* if the type is REG_SZ and data is not 0-terminated
829 * and there is enough space in the buffer NT appends a \0 */
830 if (total_size - info_size <= *count-sizeof(WCHAR) && is_string(info->Type))
832 WCHAR *ptr = (WCHAR *)(data + total_size - info_size);
833 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
836 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
838 else status = STATUS_SUCCESS;
840 if (type) *type = info->Type;
841 if (count) *count = total_size - info_size;
844 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
845 return RtlNtStatusToDosError(status);
849 /******************************************************************************
850 * RegQueryValueExA [ADVAPI32.@]
853 * the documentation is wrong: if the buffer is too small it remains untouched
855 DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
856 LPBYTE data, LPDWORD count )
861 char buffer[256], *buf_ptr = buffer;
862 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
863 static const int info_size = info->Data - (UCHAR *)info;
865 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
866 hkey, debugstr_a(name), reserved, type, data, count, count ? *count : 0 );
868 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
870 RtlInitAnsiString( &nameA, name );
871 if ((status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
873 return RtlNtStatusToDosError(status);
875 status = NtQueryValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString,
876 KeyValuePartialInformation, buffer, sizeof(buffer), &total_size );
877 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
879 /* we need to fetch the contents for a string type even if not requested,
880 * because we need to compute the length of the ASCII string. */
881 if (data || is_string(info->Type))
883 /* retry with a dynamically allocated buffer */
884 while (status == STATUS_BUFFER_OVERFLOW)
886 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
887 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
889 status = STATUS_NO_MEMORY;
892 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
893 status = NtQueryValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString,
894 KeyValuePartialInformation, buf_ptr, total_size, &total_size );
897 if (status) goto done;
899 if (is_string(info->Type))
903 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info_size),
904 total_size - info_size );
907 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
910 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info_size),
911 total_size - info_size );
912 /* if the type is REG_SZ and data is not 0-terminated
913 * and there is enough space in the buffer NT appends a \0 */
914 if (len < *count && data[len-1]) data[len] = 0;
917 total_size = len + info_size;
921 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
922 else memcpy( data, buf_ptr + info_size, total_size - info_size );
925 else status = STATUS_SUCCESS;
927 if (type) *type = info->Type;
928 if (count) *count = total_size - info_size;
931 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
932 return RtlNtStatusToDosError(status);
936 /******************************************************************************
937 * RegQueryValueW [ADVAPI32.@]
939 DWORD WINAPI RegQueryValueW( HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count )
944 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_w(name), data, count ? *count : 0 );
948 if ((ret = RegOpenKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
950 ret = RegQueryValueExW( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
951 if (subkey != hkey) RegCloseKey( subkey );
952 if (ret == ERROR_FILE_NOT_FOUND)
954 /* return empty string if default value not found */
956 if (count) *count = 1;
963 /******************************************************************************
964 * RegQueryValueA [ADVAPI32.@]
966 DWORD WINAPI RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
971 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_a(name), data, count ? *count : 0 );
975 if ((ret = RegOpenKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
977 ret = RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
978 if (subkey != hkey) RegCloseKey( subkey );
979 if (ret == ERROR_FILE_NOT_FOUND)
981 /* return empty string if default value not found */
983 if (count) *count = 1;
990 /******************************************************************************
991 * RegEnumValueW [ADVAPI32.@]
994 * hkey [I] Handle to key to query
995 * index [I] Index of value to query
996 * value [O] Value string
997 * val_count [I/O] Size of value buffer (in wchars)
998 * reserved [I] Reserved
1000 * data [O] Value data
1001 * count [I/O] Size of data buffer (in bytes)
1004 DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_count,
1005 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1009 char buffer[256], *buf_ptr = buffer;
1010 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1011 static const int info_size = (char *)info->Name - (char *)info;
1013 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1014 hkey, index, value, val_count, reserved, type, data, count );
1016 /* NT only checks count, not val_count */
1017 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1019 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
1020 if (data) total_size += *count;
1021 total_size = min( sizeof(buffer), total_size );
1023 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1024 buffer, total_size, &total_size );
1025 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
1029 /* retry with a dynamically allocated buffer */
1030 while (status == STATUS_BUFFER_OVERFLOW)
1032 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1033 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1034 return ERROR_NOT_ENOUGH_MEMORY;
1035 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
1036 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1037 buf_ptr, total_size, &total_size );
1040 if (status) goto done;
1044 if (info->NameLength/sizeof(WCHAR) >= *val_count)
1046 status = STATUS_BUFFER_OVERFLOW;
1049 memcpy( value, info->Name, info->NameLength );
1050 *val_count = info->NameLength / sizeof(WCHAR);
1051 value[*val_count] = 0;
1056 if (total_size - info->DataOffset > *count)
1058 status = STATUS_BUFFER_OVERFLOW;
1061 memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1062 if (total_size - info->DataOffset <= *count-sizeof(WCHAR) && is_string(info->Type))
1064 /* if the type is REG_SZ and data is not 0-terminated
1065 * and there is enough space in the buffer NT appends a \0 */
1066 WCHAR *ptr = (WCHAR *)(data + total_size - info->DataOffset);
1067 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
1071 else status = STATUS_SUCCESS;
1073 if (type) *type = info->Type;
1074 if (count) *count = info->DataLength;
1077 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1078 return RtlNtStatusToDosError(status);
1082 /******************************************************************************
1083 * RegEnumValueA [ADVAPI32.@]
1085 DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
1086 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1090 char buffer[256], *buf_ptr = buffer;
1091 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1092 static const int info_size = (char *)info->Name - (char *)info;
1094 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1095 hkey, index, value, val_count, reserved, type, data, count );
1097 /* NT only checks count, not val_count */
1098 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1100 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
1101 if (data) total_size += *count;
1102 total_size = min( sizeof(buffer), total_size );
1104 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1105 buffer, total_size, &total_size );
1106 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
1108 /* we need to fetch the contents for a string type even if not requested,
1109 * because we need to compute the length of the ASCII string. */
1110 if (value || data || is_string(info->Type))
1112 /* retry with a dynamically allocated buffer */
1113 while (status == STATUS_BUFFER_OVERFLOW)
1115 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1116 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1117 return ERROR_NOT_ENOUGH_MEMORY;
1118 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
1119 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1120 buf_ptr, total_size, &total_size );
1123 if (status) goto done;
1129 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1130 if (len >= *val_count)
1132 status = STATUS_BUFFER_OVERFLOW;
1135 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
1140 if (is_string(info->Type))
1143 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
1144 total_size - info->DataOffset );
1149 status = STATUS_BUFFER_OVERFLOW;
1152 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
1153 total_size - info->DataOffset );
1154 /* if the type is REG_SZ and data is not 0-terminated
1155 * and there is enough space in the buffer NT appends a \0 */
1156 if (len < *count && data[len-1]) data[len] = 0;
1158 info->DataLength = len;
1162 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
1163 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1166 else status = STATUS_SUCCESS;
1168 if (type) *type = info->Type;
1169 if (count) *count = info->DataLength;
1172 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1173 return RtlNtStatusToDosError(status);
1178 /******************************************************************************
1179 * RegDeleteValueW [ADVAPI32.@]
1182 * hkey [I] handle to key
1183 * name [I] name of value to delete
1188 DWORD WINAPI RegDeleteValueW( HKEY hkey, LPCWSTR name )
1190 UNICODE_STRING nameW;
1191 RtlInitUnicodeString( &nameW, name );
1192 return RtlNtStatusToDosError( NtDeleteValueKey( hkey, &nameW ) );
1196 /******************************************************************************
1197 * RegDeleteValueA [ADVAPI32.@]
1199 DWORD WINAPI RegDeleteValueA( HKEY hkey, LPCSTR name )
1204 RtlInitAnsiString( &nameA, name );
1205 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
1208 status = NtDeleteValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString );
1210 return RtlNtStatusToDosError( status );
1214 /******************************************************************************
1215 * RegLoadKeyW [ADVAPI32.@]
1218 * hkey [I] Handle of open key
1219 * subkey [I] Address of name of subkey
1220 * filename [I] Address of filename for registry information
1222 LONG WINAPI RegLoadKeyW( HKEY hkey, LPCWSTR subkey, LPCWSTR filename )
1225 DWORD ret, len, err = GetLastError();
1227 TRACE( "(%x,%s,%s)\n", hkey, debugstr_w(subkey), debugstr_w(filename) );
1229 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1230 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1232 len = strlenW( subkey ) * sizeof(WCHAR);
1233 if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
1235 if ((file = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1236 FILE_ATTRIBUTE_NORMAL, 0 )) == INVALID_HANDLE_VALUE)
1238 ret = GetLastError();
1242 SERVER_START_REQ( load_registry )
1246 wine_server_add_data( req, subkey, len );
1247 ret = RtlNtStatusToDosError( wine_server_call(req) );
1250 CloseHandle( file );
1253 SetLastError( err ); /* restore the last error code */
1258 /******************************************************************************
1259 * RegLoadKeyA [ADVAPI32.@]
1261 LONG WINAPI RegLoadKeyA( HKEY hkey, LPCSTR subkey, LPCSTR filename )
1263 WCHAR buffer[MAX_PATH];
1265 DWORD ret, len, err = GetLastError();
1267 TRACE( "(%x,%s,%s)\n", hkey, debugstr_a(subkey), debugstr_a(filename) );
1269 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1270 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1272 if (!(len = MultiByteToWideChar( CP_ACP, 0, subkey, strlen(subkey), buffer, MAX_PATH )))
1273 return ERROR_INVALID_PARAMETER;
1275 if ((file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1276 FILE_ATTRIBUTE_NORMAL, 0 )) == INVALID_HANDLE_VALUE)
1278 ret = GetLastError();
1282 SERVER_START_REQ( load_registry )
1286 wine_server_add_data( req, buffer, len * sizeof(WCHAR) );
1287 ret = RtlNtStatusToDosError( wine_server_call(req) );
1290 CloseHandle( file );
1293 SetLastError( err ); /* restore the last error code */
1298 /******************************************************************************
1299 * RegSaveKeyA [ADVAPI32.@]
1302 * hkey [I] Handle of key where save begins
1303 * lpFile [I] Address of filename to save to
1304 * sa [I] Address of security structure
1306 LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa )
1314 TRACE( "(%x,%s,%p)\n", hkey, debugstr_a(file), sa );
1316 if (!file || !*file) return ERROR_INVALID_PARAMETER;
1318 err = GetLastError();
1319 GetFullPathNameA( file, sizeof(buffer), buffer, &name );
1322 sprintf( name, "reg%04x.tmp", count++ );
1323 handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL,
1324 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1325 if (handle != INVALID_HANDLE_VALUE) break;
1326 if ((ret = GetLastError()) != ERROR_ALREADY_EXISTS) goto done;
1328 /* Something gone haywire ? Please report if this happens abnormally */
1330 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);
1333 SERVER_START_REQ( save_registry )
1337 ret = RtlNtStatusToDosError( wine_server_call( req ) );
1341 CloseHandle( handle );
1344 if (!MoveFileExA( buffer, file, MOVEFILE_REPLACE_EXISTING ))
1346 ERR( "Failed to move %s to %s\n", buffer, file );
1347 ret = GetLastError();
1350 if (ret) DeleteFileA( buffer );
1353 SetLastError( err ); /* restore last error code */
1358 /******************************************************************************
1359 * RegSaveKeyW [ADVAPI32.@]
1361 LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
1363 LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file );
1364 DWORD ret = RegSaveKeyA( hkey, fileA, sa );
1365 if (fileA) HeapFree( GetProcessHeap(), 0, fileA );
1370 /******************************************************************************
1371 * RegRestoreKeyW [ADVAPI32.@]
1374 * hkey [I] Handle of key where restore begins
1375 * lpFile [I] Address of filename containing saved tree
1376 * dwFlags [I] Optional flags
1378 LONG WINAPI RegRestoreKeyW( HKEY hkey, LPCWSTR lpFile, DWORD dwFlags )
1380 TRACE("(%x,%s,%ld)\n",hkey,debugstr_w(lpFile),dwFlags);
1382 /* It seems to do this check before the hkey check */
1383 if (!lpFile || !*lpFile)
1384 return ERROR_INVALID_PARAMETER;
1386 FIXME("(%x,%s,%ld): stub\n",hkey,debugstr_w(lpFile),dwFlags);
1388 /* Check for file existence */
1390 return ERROR_SUCCESS;
1394 /******************************************************************************
1395 * RegRestoreKeyA [ADVAPI32.@]
1397 LONG WINAPI RegRestoreKeyA( HKEY hkey, LPCSTR lpFile, DWORD dwFlags )
1399 LPWSTR lpFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpFile );
1400 LONG ret = RegRestoreKeyW( hkey, lpFileW, dwFlags );
1401 HeapFree( GetProcessHeap(), 0, lpFileW );
1406 /******************************************************************************
1407 * RegUnLoadKeyW [ADVAPI32.@]
1410 * hkey [I] Handle of open key
1411 * lpSubKey [I] Address of name of subkey to unload
1413 LONG WINAPI RegUnLoadKeyW( HKEY hkey, LPCWSTR lpSubKey )
1415 FIXME("(%x,%s): stub\n",hkey, debugstr_w(lpSubKey));
1416 return ERROR_SUCCESS;
1420 /******************************************************************************
1421 * RegUnLoadKeyA [ADVAPI32.@]
1423 LONG WINAPI RegUnLoadKeyA( HKEY hkey, LPCSTR lpSubKey )
1425 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1426 LONG ret = RegUnLoadKeyW( hkey, lpSubKeyW );
1427 if(lpSubKeyW) HeapFree( GetProcessHeap(), 0, lpSubKeyW);
1432 /******************************************************************************
1433 * RegReplaceKeyW [ADVAPI32.@]
1436 * hkey [I] Handle of open key
1437 * lpSubKey [I] Address of name of subkey
1438 * lpNewFile [I] Address of filename for file with new data
1439 * lpOldFile [I] Address of filename for backup file
1441 LONG WINAPI RegReplaceKeyW( HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpNewFile,
1444 FIXME("(%x,%s,%s,%s): stub\n", hkey, debugstr_w(lpSubKey),
1445 debugstr_w(lpNewFile),debugstr_w(lpOldFile));
1446 return ERROR_SUCCESS;
1450 /******************************************************************************
1451 * RegReplaceKeyA [ADVAPI32.@]
1453 LONG WINAPI RegReplaceKeyA( HKEY hkey, LPCSTR lpSubKey, LPCSTR lpNewFile,
1456 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1457 LPWSTR lpNewFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpNewFile );
1458 LPWSTR lpOldFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpOldFile );
1459 LONG ret = RegReplaceKeyW( hkey, lpSubKeyW, lpNewFileW, lpOldFileW );
1460 HeapFree( GetProcessHeap(), 0, lpOldFileW );
1461 HeapFree( GetProcessHeap(), 0, lpNewFileW );
1462 HeapFree( GetProcessHeap(), 0, lpSubKeyW );
1467 /******************************************************************************
1468 * RegSetKeySecurity [ADVAPI32.@]
1471 * hkey [I] Open handle of key to set
1472 * SecurityInfo [I] Descriptor contents
1473 * pSecurityDesc [I] Address of descriptor for key
1475 LONG WINAPI RegSetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInfo,
1476 PSECURITY_DESCRIPTOR pSecurityDesc )
1478 TRACE("(%x,%ld,%p)\n",hkey,SecurityInfo,pSecurityDesc);
1480 /* It seems to perform this check before the hkey check */
1481 if ((SecurityInfo & OWNER_SECURITY_INFORMATION) ||
1482 (SecurityInfo & GROUP_SECURITY_INFORMATION) ||
1483 (SecurityInfo & DACL_SECURITY_INFORMATION) ||
1484 (SecurityInfo & SACL_SECURITY_INFORMATION)) {
1487 return ERROR_INVALID_PARAMETER;
1490 return ERROR_INVALID_PARAMETER;
1492 FIXME(":(%x,%ld,%p): stub\n",hkey,SecurityInfo,pSecurityDesc);
1494 return ERROR_SUCCESS;
1498 /******************************************************************************
1499 * RegGetKeySecurity [ADVAPI32.@]
1500 * Retrieves a copy of security descriptor protecting the registry key
1503 * hkey [I] Open handle of key to set
1504 * SecurityInformation [I] Descriptor contents
1505 * pSecurityDescriptor [O] Address of descriptor for key
1506 * lpcbSecurityDescriptor [I/O] Address of size of buffer and description
1509 * Success: ERROR_SUCCESS
1510 * Failure: Error code
1512 LONG WINAPI RegGetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInformation,
1513 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1514 LPDWORD lpcbSecurityDescriptor )
1516 TRACE("(%x,%ld,%p,%ld)\n",hkey,SecurityInformation,pSecurityDescriptor,
1517 lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1519 /* FIXME: Check for valid SecurityInformation values */
1521 if (*lpcbSecurityDescriptor < sizeof(SECURITY_DESCRIPTOR))
1522 return ERROR_INSUFFICIENT_BUFFER;
1524 FIXME("(%x,%ld,%p,%ld): stub\n",hkey,SecurityInformation,
1525 pSecurityDescriptor,lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1527 /* Do not leave security descriptor filled with garbage */
1528 RtlCreateSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
1530 return ERROR_SUCCESS;
1534 /******************************************************************************
1535 * RegFlushKey [ADVAPI32.@]
1536 * Immediately writes key to registry.
1537 * Only returns after data has been written to disk.
1539 * FIXME: does it really wait until data is written ?
1542 * hkey [I] Handle of key to write
1545 * Success: ERROR_SUCCESS
1546 * Failure: Error code
1548 DWORD WINAPI RegFlushKey( HKEY hkey )
1550 FIXME( "(%x): stub\n", hkey );
1551 return ERROR_SUCCESS;
1555 /******************************************************************************
1556 * RegConnectRegistryW [ADVAPI32.@]
1559 * lpMachineName [I] Address of name of remote computer
1560 * hHey [I] Predefined registry handle
1561 * phkResult [I] Address of buffer for remote registry handle
1563 LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey,
1566 TRACE("(%s,%x,%p): stub\n",debugstr_w(lpMachineName),hKey,phkResult);
1568 if (!lpMachineName || !*lpMachineName) {
1569 /* Use the local machine name */
1570 return RegOpenKeyA( hKey, "", phkResult );
1573 FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName));
1574 return ERROR_BAD_NETPATH;
1578 /******************************************************************************
1579 * RegConnectRegistryA [ADVAPI32.@]
1581 LONG WINAPI RegConnectRegistryA( LPCSTR machine, HKEY hkey, LPHKEY reskey )
1583 LPWSTR machineW = HEAP_strdupAtoW( GetProcessHeap(), 0, machine );
1584 DWORD ret = RegConnectRegistryW( machineW, hkey, reskey );
1585 HeapFree( GetProcessHeap(), 0, machineW );
1590 /******************************************************************************
1591 * RegNotifyChangeKeyValue [ADVAPI32.@]
1594 * hkey [I] Handle of key to watch
1595 * fWatchSubTree [I] Flag for subkey notification
1596 * fdwNotifyFilter [I] Changes to be reported
1597 * hEvent [I] Handle of signaled event
1598 * fAsync [I] Flag for asynchronous reporting
1600 LONG WINAPI RegNotifyChangeKeyValue( HKEY hkey, BOOL fWatchSubTree,
1601 DWORD fdwNotifyFilter, HANDLE hEvent,
1604 FIXME("(%x,%i,%ld,%x,%i): stub\n",hkey,fWatchSubTree,fdwNotifyFilter,
1606 return ERROR_SUCCESS;