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
38 #include "wine/unicode.h"
39 #include "wine/server.h"
40 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(reg
);
45 /* allowed bits for access mask */
46 #define KEY_ACCESS_MASK (KEY_ALL_ACCESS | MAXIMUM_ALLOWED)
48 #define HKEY_SPECIAL_ROOT_FIRST HKEY_CLASSES_ROOT
49 #define HKEY_SPECIAL_ROOT_LAST HKEY_DYN_DATA
50 #define NB_SPECIAL_ROOT_KEYS ((UINT)HKEY_SPECIAL_ROOT_LAST - (UINT)HKEY_SPECIAL_ROOT_FIRST + 1)
52 static HKEY special_root_keys
[NB_SPECIAL_ROOT_KEYS
];
54 static const WCHAR name_CLASSES_ROOT
[] =
55 {'M','a','c','h','i','n','e','\\',
56 'S','o','f','t','w','a','r','e','\\',
57 'C','l','a','s','s','e','s',0};
58 static const WCHAR name_LOCAL_MACHINE
[] =
59 {'M','a','c','h','i','n','e',0};
60 static const WCHAR name_USERS
[] =
62 static const WCHAR name_PERFORMANCE_DATA
[] =
63 {'P','e','r','f','D','a','t','a',0};
64 static const WCHAR name_CURRENT_CONFIG
[] =
65 {'M','a','c','h','i','n','e','\\',
66 'S','y','s','t','e','m','\\',
67 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
68 'H','a','r','d','w','a','r','e',' ','P','r','o','f','i','l','e','s','\\',
69 'C','u','r','r','e','n','t',0};
70 static const WCHAR name_DYN_DATA
[] =
71 {'D','y','n','D','a','t','a',0};
73 #define DECL_STR(key) { sizeof(name_##key)-sizeof(WCHAR), sizeof(name_##key), (LPWSTR)name_##key }
74 static UNICODE_STRING root_key_names
[NB_SPECIAL_ROOT_KEYS
] =
76 DECL_STR(CLASSES_ROOT
),
77 { 0, 0, NULL
}, /* HKEY_CURRENT_USER is determined dynamically */
78 DECL_STR(LOCAL_MACHINE
),
80 DECL_STR(PERFORMANCE_DATA
),
81 DECL_STR(CURRENT_CONFIG
),
87 /* check if value type needs string conversion (Ansi<->Unicode) */
88 inline static int is_string( DWORD type
)
90 return (type
== REG_SZ
) || (type
== REG_EXPAND_SZ
) || (type
== REG_MULTI_SZ
);
93 /* check if current version is NT or Win95 */
94 inline static int is_version_nt(void)
96 return !(GetVersion() & 0x80000000);
99 /* create one of the HKEY_* special root keys */
100 static HKEY
create_special_root_hkey( HKEY hkey
, DWORD access
)
103 int idx
= (UINT
)hkey
- (UINT
)HKEY_SPECIAL_ROOT_FIRST
;
105 if (hkey
== HKEY_CURRENT_USER
)
107 if (RtlOpenCurrentUser( access
, &hkey
)) return 0;
108 TRACE( "HKEY_CURRENT_USER -> %p\n", hkey
);
112 OBJECT_ATTRIBUTES attr
;
114 attr
.Length
= sizeof(attr
);
115 attr
.RootDirectory
= 0;
116 attr
.ObjectName
= &root_key_names
[idx
];
118 attr
.SecurityDescriptor
= NULL
;
119 attr
.SecurityQualityOfService
= NULL
;
120 if (NtCreateKey( &hkey
, access
, &attr
, 0, NULL
, 0, NULL
)) return 0;
121 TRACE( "%s -> %p\n", debugstr_w(attr
.ObjectName
->Buffer
), hkey
);
124 if (!(ret
= InterlockedCompareExchangePointer( (void **)&special_root_keys
[idx
], hkey
, 0 )))
127 NtClose( hkey
); /* somebody beat us to it */
131 /* map the hkey from special root to normal key if necessary */
132 inline static HKEY
get_special_root_hkey( HKEY hkey
)
136 if ((hkey
>= HKEY_SPECIAL_ROOT_FIRST
) && (hkey
<= HKEY_SPECIAL_ROOT_LAST
))
138 if (!(ret
= special_root_keys
[(UINT
)hkey
- (UINT
)HKEY_SPECIAL_ROOT_FIRST
]))
139 ret
= create_special_root_hkey( hkey
, KEY_ALL_ACCESS
);
145 /******************************************************************************
146 * RegCreateKeyExW [ADVAPI32.@]
148 * See RegCreateKeyExA.
150 DWORD WINAPI
RegCreateKeyExW( HKEY hkey
, LPCWSTR name
, DWORD reserved
, LPCWSTR
class,
151 DWORD options
, REGSAM access
, SECURITY_ATTRIBUTES
*sa
,
152 PHKEY retkey
, LPDWORD dispos
)
154 OBJECT_ATTRIBUTES attr
;
155 UNICODE_STRING nameW
, classW
;
157 if (reserved
) return ERROR_INVALID_PARAMETER
;
158 if (!(access
& KEY_ACCESS_MASK
) || (access
& ~KEY_ACCESS_MASK
)) return ERROR_ACCESS_DENIED
;
159 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
161 attr
.Length
= sizeof(attr
);
162 attr
.RootDirectory
= hkey
;
163 attr
.ObjectName
= &nameW
;
165 attr
.SecurityDescriptor
= NULL
;
166 attr
.SecurityQualityOfService
= NULL
;
167 RtlInitUnicodeString( &nameW
, name
);
168 RtlInitUnicodeString( &classW
, class );
170 return RtlNtStatusToDosError( NtCreateKey( retkey
, access
, &attr
, 0,
171 &classW
, options
, dispos
) );
175 /******************************************************************************
176 * RegCreateKeyExA [ADVAPI32.@]
178 * Open a registry key, creating it if it doesn't exist.
181 * hkey [I] Handle of the parent registry key
182 * name [I] Name of the new key to open or create
183 * reserved [I] Reserved, pass 0
184 * class [I] The object type of the new key
185 * options [I] Flags controlling the key creation (REG_OPTION_* flags from "winnt.h")
186 * access [I] Access level desired
187 * sa [I] Security attributes for the key
188 * retkey [O] Destination for the resulting handle
189 * dispos [O] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
192 * Success: ERROR_SUCCESS.
193 * Failure: A standard Win32 error code. retkey remains untouched.
196 * MAXIMUM_ALLOWED in access mask not supported by server
198 DWORD WINAPI
RegCreateKeyExA( HKEY hkey
, LPCSTR name
, DWORD reserved
, LPCSTR
class,
199 DWORD options
, REGSAM access
, SECURITY_ATTRIBUTES
*sa
,
200 PHKEY retkey
, LPDWORD dispos
)
202 OBJECT_ATTRIBUTES attr
;
203 UNICODE_STRING classW
;
204 ANSI_STRING nameA
, classA
;
207 if (reserved
) return ERROR_INVALID_PARAMETER
;
208 if (!is_version_nt()) access
= KEY_ALL_ACCESS
; /* Win95 ignores the access mask */
209 else if (!(access
& KEY_ACCESS_MASK
) || (access
& ~KEY_ACCESS_MASK
)) return ERROR_ACCESS_DENIED
;
210 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
212 attr
.Length
= sizeof(attr
);
213 attr
.RootDirectory
= hkey
;
214 attr
.ObjectName
= &NtCurrentTeb()->StaticUnicodeString
;
216 attr
.SecurityDescriptor
= NULL
;
217 attr
.SecurityQualityOfService
= NULL
;
218 RtlInitAnsiString( &nameA
, name
);
219 RtlInitAnsiString( &classA
, class );
221 if (!(status
= RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString
,
224 if (!(status
= RtlAnsiStringToUnicodeString( &classW
, &classA
, TRUE
)))
226 status
= NtCreateKey( retkey
, access
, &attr
, 0, &classW
, options
, dispos
);
227 RtlFreeUnicodeString( &classW
);
230 return RtlNtStatusToDosError( status
);
234 /******************************************************************************
235 * RegCreateKeyW [ADVAPI32.@]
237 * Creates the specified reg key.
240 * hKey [I] Handle to an open key.
241 * lpSubKey [I] Name of a key that will be opened or created.
242 * phkResult [O] Receives a handle to the opened or created key.
245 * Success: ERROR_SUCCESS
246 * Failure: nonzero error code defined in Winerror.h
248 DWORD WINAPI
RegCreateKeyW( HKEY hkey
, LPCWSTR lpSubKey
, PHKEY phkResult
)
250 /* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
251 /* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
252 return RegCreateKeyExW( hkey
, lpSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
253 KEY_ALL_ACCESS
, NULL
, phkResult
, NULL
);
257 /******************************************************************************
258 * RegCreateKeyA [ADVAPI32.@]
262 DWORD WINAPI
RegCreateKeyA( HKEY hkey
, LPCSTR lpSubKey
, PHKEY phkResult
)
264 return RegCreateKeyExA( hkey
, lpSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
265 KEY_ALL_ACCESS
, NULL
, phkResult
, NULL
);
270 /******************************************************************************
271 * RegOpenKeyExW [ADVAPI32.@]
275 DWORD WINAPI
RegOpenKeyExW( HKEY hkey
, LPCWSTR name
, DWORD reserved
, REGSAM access
, PHKEY retkey
)
277 OBJECT_ATTRIBUTES attr
;
278 UNICODE_STRING nameW
;
280 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
282 attr
.Length
= sizeof(attr
);
283 attr
.RootDirectory
= hkey
;
284 attr
.ObjectName
= &nameW
;
286 attr
.SecurityDescriptor
= NULL
;
287 attr
.SecurityQualityOfService
= NULL
;
288 RtlInitUnicodeString( &nameW
, name
);
289 return RtlNtStatusToDosError( NtOpenKey( retkey
, access
, &attr
) );
293 /******************************************************************************
294 * RegOpenKeyExA [ADVAPI32.@]
296 * Open a registry key.
299 * hkey [I] Handle of open key
300 * name [I] Name of subkey to open
301 * reserved [I] Reserved - must be zero
302 * access [I] Security access mask
303 * retkey [O] Handle to open key
306 * Success: ERROR_SUCCESS
307 * Failure: A standard Win32 error code. retkey is set to 0.
310 * Unlike RegCreateKeyExA(), this function will not create the key if it
313 DWORD WINAPI
RegOpenKeyExA( HKEY hkey
, LPCSTR name
, DWORD reserved
, REGSAM access
, PHKEY retkey
)
315 OBJECT_ATTRIBUTES attr
;
319 if (!is_version_nt()) access
= KEY_ALL_ACCESS
; /* Win95 ignores the access mask */
321 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
323 attr
.Length
= sizeof(attr
);
324 attr
.RootDirectory
= hkey
;
325 attr
.ObjectName
= &NtCurrentTeb()->StaticUnicodeString
;
327 attr
.SecurityDescriptor
= NULL
;
328 attr
.SecurityQualityOfService
= NULL
;
330 RtlInitAnsiString( &nameA
, name
);
331 if (!(status
= RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString
,
334 status
= NtOpenKey( retkey
, access
, &attr
);
336 return RtlNtStatusToDosError( status
);
340 /******************************************************************************
341 * RegOpenKeyW [ADVAPI32.@]
345 DWORD WINAPI
RegOpenKeyW( HKEY hkey
, LPCWSTR name
, PHKEY retkey
)
350 return ERROR_SUCCESS
;
352 return RegOpenKeyExW( hkey
, name
, 0, KEY_ALL_ACCESS
, retkey
);
356 /******************************************************************************
357 * RegOpenKeyA [ADVAPI32.@]
359 * Open a registry key.
362 * hkey [I] Handle of parent key to open the new key under
363 * name [I] Name of the key under hkey to open
364 * retkey [O] Destination for the resulting Handle
367 * Success: ERROR_SUCCESS
368 * Failure: A standard Win32 error code. retkey is set to 0.
370 DWORD WINAPI
RegOpenKeyA( HKEY hkey
, LPCSTR name
, PHKEY retkey
)
375 return ERROR_SUCCESS
;
377 return RegOpenKeyExA( hkey
, name
, 0, KEY_ALL_ACCESS
, retkey
);
381 /******************************************************************************
382 * RegOpenCurrentUser [ADVAPI32.@]
384 * FIXME: This function is supposed to retrieve a handle to the
385 * HKEY_CURRENT_USER for the user the current thread is impersonating.
386 * Since Wine does not currently allow threads to impersonate other users,
387 * this stub should work fine.
389 DWORD WINAPI
RegOpenCurrentUser( REGSAM access
, PHKEY retkey
)
391 return RegOpenKeyExA( HKEY_CURRENT_USER
, "", 0, access
, retkey
);
396 /******************************************************************************
397 * RegEnumKeyExW [ADVAPI32.@]
400 * hkey [I] Handle to key to enumerate
401 * index [I] Index of subkey to enumerate
402 * name [O] Buffer for subkey name
403 * name_len [O] Size of subkey buffer
404 * reserved [I] Reserved
405 * class [O] Buffer for class string
406 * class_len [O] Size of class buffer
407 * ft [O] Time key last written to
410 * Success: ERROR_SUCCESS
411 * Failure: System error code. If there are no more subkeys available, the
412 * function returns ERROR_NO_MORE_ITEMS.
414 DWORD WINAPI
RegEnumKeyExW( HKEY hkey
, DWORD index
, LPWSTR name
, LPDWORD name_len
,
415 LPDWORD reserved
, LPWSTR
class, LPDWORD class_len
, FILETIME
*ft
)
418 char buffer
[256], *buf_ptr
= buffer
;
419 KEY_NODE_INFORMATION
*info
= (KEY_NODE_INFORMATION
*)buffer
;
422 TRACE( "(%p,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey
, index
, name
, name_len
,
423 name_len
? *name_len
: -1, reserved
, class, class_len
, ft
);
425 if (reserved
) return ERROR_INVALID_PARAMETER
;
426 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
428 status
= NtEnumerateKey( hkey
, index
, KeyNodeInformation
,
429 buffer
, sizeof(buffer
), &total_size
);
431 while (status
== STATUS_BUFFER_OVERFLOW
)
433 /* retry with a dynamically allocated buffer */
434 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
435 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
436 return ERROR_NOT_ENOUGH_MEMORY
;
437 info
= (KEY_NODE_INFORMATION
*)buf_ptr
;
438 status
= NtEnumerateKey( hkey
, index
, KeyNodeInformation
,
439 buf_ptr
, total_size
, &total_size
);
444 DWORD len
= info
->NameLength
/ sizeof(WCHAR
);
445 DWORD cls_len
= info
->ClassLength
/ sizeof(WCHAR
);
447 if (ft
) *ft
= *(FILETIME
*)&info
->LastWriteTime
;
449 if (len
>= *name_len
|| (class && class_len
&& (cls_len
>= *class_len
)))
450 status
= STATUS_BUFFER_OVERFLOW
;
454 memcpy( name
, info
->Name
, info
->NameLength
);
458 *class_len
= cls_len
;
461 memcpy( class, buf_ptr
+ info
->ClassOffset
, info
->ClassLength
);
468 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
469 return RtlNtStatusToDosError( status
);
473 /******************************************************************************
474 * RegEnumKeyExA [ADVAPI32.@]
478 DWORD WINAPI
RegEnumKeyExA( HKEY hkey
, DWORD index
, LPSTR name
, LPDWORD name_len
,
479 LPDWORD reserved
, LPSTR
class, LPDWORD class_len
, FILETIME
*ft
)
482 char buffer
[256], *buf_ptr
= buffer
;
483 KEY_NODE_INFORMATION
*info
= (KEY_NODE_INFORMATION
*)buffer
;
486 TRACE( "(%p,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey
, index
, name
, name_len
,
487 name_len
? *name_len
: -1, reserved
, class, class_len
, ft
);
489 if (reserved
) return ERROR_INVALID_PARAMETER
;
490 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
492 status
= NtEnumerateKey( hkey
, index
, KeyNodeInformation
,
493 buffer
, sizeof(buffer
), &total_size
);
495 while (status
== STATUS_BUFFER_OVERFLOW
)
497 /* retry with a dynamically allocated buffer */
498 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
499 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
500 return ERROR_NOT_ENOUGH_MEMORY
;
501 info
= (KEY_NODE_INFORMATION
*)buf_ptr
;
502 status
= NtEnumerateKey( hkey
, index
, KeyNodeInformation
,
503 buf_ptr
, total_size
, &total_size
);
510 RtlUnicodeToMultiByteSize( &len
, info
->Name
, info
->NameLength
);
511 RtlUnicodeToMultiByteSize( &cls_len
, (WCHAR
*)(buf_ptr
+ info
->ClassOffset
),
513 if (ft
) *ft
= *(FILETIME
*)&info
->LastWriteTime
;
515 if (len
>= *name_len
|| (class && class_len
&& (cls_len
>= *class_len
)))
516 status
= STATUS_BUFFER_OVERFLOW
;
520 RtlUnicodeToMultiByteN( name
, len
, NULL
, info
->Name
, info
->NameLength
);
524 *class_len
= cls_len
;
527 RtlUnicodeToMultiByteN( class, cls_len
, NULL
,
528 (WCHAR
*)(buf_ptr
+ info
->ClassOffset
),
536 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
537 return RtlNtStatusToDosError( status
);
541 /******************************************************************************
542 * RegEnumKeyW [ADVAPI32.@]
544 * Enumerates subkyes of the specified open reg key.
547 * hKey [I] Handle to an open key.
548 * dwIndex [I] Index of the subkey of hKey to retrieve.
549 * lpName [O] Name of the subkey.
550 * cchName [I] Size of lpName in TCHARS.
553 * Success: ERROR_SUCCESS
554 * Failure: system error code. If there are no more subkeys available, the
555 * function returns ERROR_NO_MORE_ITEMS.
557 DWORD WINAPI
RegEnumKeyW( HKEY hkey
, DWORD index
, LPWSTR name
, DWORD name_len
)
559 return RegEnumKeyExW( hkey
, index
, name
, &name_len
, NULL
, NULL
, NULL
, NULL
);
563 /******************************************************************************
564 * RegEnumKeyA [ADVAPI32.@]
568 DWORD WINAPI
RegEnumKeyA( HKEY hkey
, DWORD index
, LPSTR name
, DWORD name_len
)
570 return RegEnumKeyExA( hkey
, index
, name
, &name_len
, NULL
, NULL
, NULL
, NULL
);
574 /******************************************************************************
575 * RegQueryInfoKeyW [ADVAPI32.@]
578 * hkey [I] Handle to key to query
579 * class [O] Buffer for class string
580 * class_len [O] Size of class string buffer
581 * reserved [I] Reserved
582 * subkeys [O] Buffer for number of subkeys
583 * max_subkey [O] Buffer for longest subkey name length
584 * max_class [O] Buffer for longest class string length
585 * values [O] Buffer for number of value entries
586 * max_value [O] Buffer for longest value name length
587 * max_data [O] Buffer for longest value data length
588 * security [O] Buffer for security descriptor length
589 * modif [O] Modification time
591 * - win95 allows class to be valid and class_len to be NULL
592 * - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
593 * - both allow class to be NULL and class_len to be NULL
594 * (it's hard to test validity, so test !NULL instead)
596 DWORD WINAPI
RegQueryInfoKeyW( HKEY hkey
, LPWSTR
class, LPDWORD class_len
, LPDWORD reserved
,
597 LPDWORD subkeys
, LPDWORD max_subkey
, LPDWORD max_class
,
598 LPDWORD values
, LPDWORD max_value
, LPDWORD max_data
,
599 LPDWORD security
, FILETIME
*modif
)
602 char buffer
[256], *buf_ptr
= buffer
;
603 KEY_FULL_INFORMATION
*info
= (KEY_FULL_INFORMATION
*)buffer
;
606 TRACE( "(%p,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey
, class, class_len
? *class_len
: 0,
607 reserved
, subkeys
, max_subkey
, values
, max_value
, max_data
, security
, modif
);
609 if (class && !class_len
&& is_version_nt()) return ERROR_INVALID_PARAMETER
;
610 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
612 status
= NtQueryKey( hkey
, KeyFullInformation
, buffer
, sizeof(buffer
), &total_size
);
613 if (status
&& status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
617 /* retry with a dynamically allocated buffer */
618 while (status
== STATUS_BUFFER_OVERFLOW
)
620 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
621 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
622 return ERROR_NOT_ENOUGH_MEMORY
;
623 info
= (KEY_FULL_INFORMATION
*)buf_ptr
;
624 status
= NtQueryKey( hkey
, KeyFullInformation
, buf_ptr
, total_size
, &total_size
);
627 if (status
) goto done
;
629 if (class_len
&& (info
->ClassLength
/sizeof(WCHAR
) + 1 > *class_len
))
631 status
= STATUS_BUFFER_OVERFLOW
;
635 memcpy( class, buf_ptr
+ info
->ClassOffset
, info
->ClassLength
);
636 class[info
->ClassLength
/sizeof(WCHAR
)] = 0;
639 else status
= STATUS_SUCCESS
;
641 if (class_len
) *class_len
= info
->ClassLength
/ sizeof(WCHAR
);
642 if (subkeys
) *subkeys
= info
->SubKeys
;
643 if (max_subkey
) *max_subkey
= info
->MaxNameLen
;
644 if (max_class
) *max_class
= info
->MaxClassLen
;
645 if (values
) *values
= info
->Values
;
646 if (max_value
) *max_value
= info
->MaxValueNameLen
;
647 if (max_data
) *max_data
= info
->MaxValueDataLen
;
648 if (modif
) *modif
= *(FILETIME
*)&info
->LastWriteTime
;
651 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
652 return RtlNtStatusToDosError( status
);
656 /******************************************************************************
657 * RegQueryMultipleValuesA [ADVAPI32.@]
659 * Retrieves the type and data for a list of value names associated with a key.
662 * hKey [I] Handle to an open key.
663 * val_list [O] Array of VALENT structures that describes the entries.
664 * num_vals [I] Number of elements in val_list.
665 * lpValueBuf [O] Pointer to a buffer that receives the data for each value.
666 * ldwTotsize [I/O] Size of lpValueBuf.
669 * Success: ERROR_SUCCESS. ldwTotsize contains num bytes copied.
670 * Failure: nonzero error code from Winerror.h ldwTotsize contains num needed
673 DWORD WINAPI
RegQueryMultipleValuesA(HKEY hkey
, PVALENTA val_list
, DWORD num_vals
,
674 LPSTR lpValueBuf
, LPDWORD ldwTotsize
)
677 DWORD maxBytes
= *ldwTotsize
;
679 LPSTR bufptr
= lpValueBuf
;
682 TRACE("(%p,%p,%ld,%p,%p=%ld)\n", hkey
, val_list
, num_vals
, lpValueBuf
, ldwTotsize
, *ldwTotsize
);
684 for(i
=0; i
< num_vals
; ++i
)
687 val_list
[i
].ve_valuelen
=0;
688 status
= RegQueryValueExA(hkey
, val_list
[i
].ve_valuename
, NULL
, NULL
, NULL
, &val_list
[i
].ve_valuelen
);
689 if(status
!= ERROR_SUCCESS
)
694 if(lpValueBuf
!= NULL
&& *ldwTotsize
+ val_list
[i
].ve_valuelen
<= maxBytes
)
696 status
= RegQueryValueExA(hkey
, val_list
[i
].ve_valuename
, NULL
, &val_list
[i
].ve_type
,
697 bufptr
, &val_list
[i
].ve_valuelen
);
698 if(status
!= ERROR_SUCCESS
)
703 val_list
[i
].ve_valueptr
= (DWORD_PTR
)bufptr
;
705 bufptr
+= val_list
[i
].ve_valuelen
;
708 *ldwTotsize
+= val_list
[i
].ve_valuelen
;
710 return lpValueBuf
!= NULL
&& *ldwTotsize
<= maxBytes
? ERROR_SUCCESS
: ERROR_MORE_DATA
;
714 /******************************************************************************
715 * RegQueryMultipleValuesW [ADVAPI32.@]
717 * see RegQueryMultipleValuesA
719 DWORD WINAPI
RegQueryMultipleValuesW(HKEY hkey
, PVALENTW val_list
, DWORD num_vals
,
720 LPWSTR lpValueBuf
, LPDWORD ldwTotsize
)
723 DWORD maxBytes
= *ldwTotsize
;
725 LPSTR bufptr
= (LPSTR
)lpValueBuf
;
728 TRACE("(%p,%p,%ld,%p,%p=%ld)\n", hkey
, val_list
, num_vals
, lpValueBuf
, ldwTotsize
, *ldwTotsize
);
730 for(i
=0; i
< num_vals
; ++i
)
732 val_list
[i
].ve_valuelen
=0;
733 status
= RegQueryValueExW(hkey
, val_list
[i
].ve_valuename
, NULL
, NULL
, NULL
, &val_list
[i
].ve_valuelen
);
734 if(status
!= ERROR_SUCCESS
)
739 if(lpValueBuf
!= NULL
&& *ldwTotsize
+ val_list
[i
].ve_valuelen
<= maxBytes
)
741 status
= RegQueryValueExW(hkey
, val_list
[i
].ve_valuename
, NULL
, &val_list
[i
].ve_type
,
742 bufptr
, &val_list
[i
].ve_valuelen
);
743 if(status
!= ERROR_SUCCESS
)
748 val_list
[i
].ve_valueptr
= (DWORD_PTR
)bufptr
;
750 bufptr
+= val_list
[i
].ve_valuelen
;
753 *ldwTotsize
+= val_list
[i
].ve_valuelen
;
755 return lpValueBuf
!= NULL
&& *ldwTotsize
<= maxBytes
? ERROR_SUCCESS
: ERROR_MORE_DATA
;
758 /******************************************************************************
759 * RegQueryInfoKeyA [ADVAPI32.@]
761 * Retrieves information about a registry key.
764 * hKey [I] Handle to an open key.
765 * lpClass [O] Class string of the key.
766 * lpcClass [I/O] size of lpClass.
767 * lpReserved [I] Reserved; must be NULL.
768 * lpcSubKeys [O] Number of subkeys contained by the key.
769 * lpcMaxSubKeyLen [O] Size of the key's subkey with the longest name.
770 * lpcMaxClassLen [O] Size of the longest string specifying a subkey
772 * lpcValues [O] Number of values associated with the key.
773 * lpcMaxValueNameLen [O] Size of the key's longest value name in TCHARS.
774 * lpcMaxValueLen [O] Longest data component among the key's values
775 * lpcbSecurityDescriptor [O] Size of the key's security descriptor.
776 * lpftLastWriteTime [O] FILETIME strucutre that is the last write time.
779 * Success: ERROR_SUCCESS
780 * Failure: nonzero error code from Winerror.h
782 DWORD WINAPI
RegQueryInfoKeyA( HKEY hkey
, LPSTR
class, LPDWORD class_len
, LPDWORD reserved
,
783 LPDWORD subkeys
, LPDWORD max_subkey
, LPDWORD max_class
,
784 LPDWORD values
, LPDWORD max_value
, LPDWORD max_data
,
785 LPDWORD security
, FILETIME
*modif
)
788 char buffer
[256], *buf_ptr
= buffer
;
789 KEY_FULL_INFORMATION
*info
= (KEY_FULL_INFORMATION
*)buffer
;
790 DWORD total_size
, len
;
792 TRACE( "(%p,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey
, class, class_len
? *class_len
: 0,
793 reserved
, subkeys
, max_subkey
, values
, max_value
, max_data
, security
, modif
);
795 if (class && !class_len
&& is_version_nt()) return ERROR_INVALID_PARAMETER
;
796 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
798 status
= NtQueryKey( hkey
, KeyFullInformation
, buffer
, sizeof(buffer
), &total_size
);
799 if (status
&& status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
801 if (class || class_len
)
803 /* retry with a dynamically allocated buffer */
804 while (status
== STATUS_BUFFER_OVERFLOW
)
806 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
807 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
808 return ERROR_NOT_ENOUGH_MEMORY
;
809 info
= (KEY_FULL_INFORMATION
*)buf_ptr
;
810 status
= NtQueryKey( hkey
, KeyFullInformation
, buf_ptr
, total_size
, &total_size
);
813 if (status
) goto done
;
815 RtlUnicodeToMultiByteSize( &len
, (WCHAR
*)(buf_ptr
+ info
->ClassOffset
), info
->ClassLength
);
818 if (len
+ 1 > *class_len
) status
= STATUS_BUFFER_OVERFLOW
;
821 if (class && !status
)
823 RtlUnicodeToMultiByteN( class, len
, NULL
, (WCHAR
*)(buf_ptr
+ info
->ClassOffset
),
828 else status
= STATUS_SUCCESS
;
830 if (subkeys
) *subkeys
= info
->SubKeys
;
831 if (max_subkey
) *max_subkey
= info
->MaxNameLen
;
832 if (max_class
) *max_class
= info
->MaxClassLen
;
833 if (values
) *values
= info
->Values
;
834 if (max_value
) *max_value
= info
->MaxValueNameLen
;
835 if (max_data
) *max_data
= info
->MaxValueDataLen
;
836 if (modif
) *modif
= *(FILETIME
*)&info
->LastWriteTime
;
839 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
840 return RtlNtStatusToDosError( status
);
844 /******************************************************************************
845 * RegCloseKey [ADVAPI32.@]
847 * Close an open registry key.
850 * hkey [I] Handle of key to close
853 * Success: ERROR_SUCCESS
854 * Failure: Error code
856 DWORD WINAPI
RegCloseKey( HKEY hkey
)
858 if (!hkey
) return ERROR_INVALID_HANDLE
;
859 if (hkey
>= (HKEY
)0x80000000) return ERROR_SUCCESS
;
860 return RtlNtStatusToDosError( NtClose( hkey
) );
864 /******************************************************************************
865 * RegDeleteKeyW [ADVAPI32.@]
869 DWORD WINAPI
RegDeleteKeyW( HKEY hkey
, LPCWSTR name
)
874 if (!name
) return ERROR_INVALID_PARAMETER
;
876 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
880 ret
= RtlNtStatusToDosError( NtDeleteKey( hkey
) );
882 else if (!(ret
= RegOpenKeyExW( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
884 ret
= RtlNtStatusToDosError( NtDeleteKey( tmp
) );
887 TRACE("%s ret=%08lx\n", debugstr_w(name
), ret
);
892 /******************************************************************************
893 * RegDeleteKeyA [ADVAPI32.@]
895 * Delete a registry key.
898 * hkey [I] Handle to parent key containing the key to delete
899 * name [I] Name of the key user hkey to delete
902 * Success: ERROR_SUCCESS
903 * Failure: Error code
905 DWORD WINAPI
RegDeleteKeyA( HKEY hkey
, LPCSTR name
)
910 if (!name
) return ERROR_INVALID_PARAMETER
;
912 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
916 ret
= RtlNtStatusToDosError( NtDeleteKey( hkey
) );
918 else if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
920 if (!is_version_nt()) /* win95 does recursive key deletes */
924 while(!RegEnumKeyA(tmp
, 0, name
, sizeof(name
)))
926 if(RegDeleteKeyA(tmp
, name
)) /* recurse */
930 ret
= RtlNtStatusToDosError( NtDeleteKey( tmp
) );
933 TRACE("%s ret=%08lx\n", debugstr_a(name
), ret
);
939 /******************************************************************************
940 * RegSetValueExW [ADVAPI32.@]
942 * Set the data and contents of a registry value.
945 * hkey [I] Handle of key to set value for
946 * name [I] Name of value to set
947 * reserved [I] Reserved, must be zero
948 * type [I] Type of the value being set
949 * data [I] The new contents of the value to set
950 * count [I] Size of data
953 * Success: ERROR_SUCCESS
954 * Failure: Error code
956 DWORD WINAPI
RegSetValueExW( HKEY hkey
, LPCWSTR name
, DWORD reserved
,
957 DWORD type
, CONST BYTE
*data
, DWORD count
)
959 UNICODE_STRING nameW
;
961 /* no need for version check, not implemented on win9x anyway */
962 if (count
&& is_string(type
))
964 LPCWSTR str
= (LPCWSTR
)data
;
965 /* if user forgot to count terminating null, add it (yes NT does this) */
966 if (str
[count
/ sizeof(WCHAR
) - 1] && !str
[count
/ sizeof(WCHAR
)])
967 count
+= sizeof(WCHAR
);
969 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
971 RtlInitUnicodeString( &nameW
, name
);
972 return RtlNtStatusToDosError( NtSetValueKey( hkey
, &nameW
, 0, type
, data
, count
) );
976 /******************************************************************************
977 * RegSetValueExA [ADVAPI32.@]
982 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
983 * NT does definitely care (aj)
985 DWORD WINAPI
RegSetValueExA( HKEY hkey
, LPCSTR name
, DWORD reserved
, DWORD type
,
986 CONST BYTE
*data
, DWORD count
)
992 if (!is_version_nt()) /* win95 */
996 if (!data
) return ERROR_INVALID_PARAMETER
;
997 count
= strlen(data
) + 1;
1000 else if (count
&& is_string(type
))
1002 /* if user forgot to count terminating null, add it (yes NT does this) */
1003 if (data
[count
-1] && !data
[count
]) count
++;
1006 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1008 if (is_string( type
)) /* need to convert to Unicode */
1011 RtlMultiByteToUnicodeSize( &lenW
, data
, count
);
1012 if (!(dataW
= HeapAlloc( GetProcessHeap(), 0, lenW
))) return ERROR_OUTOFMEMORY
;
1013 RtlMultiByteToUnicodeN( dataW
, lenW
, NULL
, data
, count
);
1015 data
= (BYTE
*)dataW
;
1018 RtlInitAnsiString( &nameA
, name
);
1019 if (!(status
= RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString
,
1022 status
= NtSetValueKey( hkey
, &NtCurrentTeb()->StaticUnicodeString
, 0, type
, data
, count
);
1024 HeapFree( GetProcessHeap(), 0, dataW
);
1025 return RtlNtStatusToDosError( status
);
1029 /******************************************************************************
1030 * RegSetValueW [ADVAPI32.@]
1032 * Sets the data for the default or unnamed value of a reg key.
1035 * hKey [I] Handle to an open key.
1036 * lpSubKey [I] Name of a subkey of hKey.
1037 * dwType [I] Type of information to store.
1038 * lpData [I] String that contains the data to set for the default value.
1039 * cbData [I] Size of lpData.
1042 * Success: ERROR_SUCCESS
1043 * Failure: nonzero error code from Winerror.h
1045 DWORD WINAPI
RegSetValueW( HKEY hkey
, LPCWSTR name
, DWORD type
, LPCWSTR data
, DWORD count
)
1050 TRACE("(%p,%s,%ld,%s,%ld)\n", hkey
, debugstr_w(name
), type
, debugstr_w(data
), count
);
1052 if (type
!= REG_SZ
) return ERROR_INVALID_PARAMETER
;
1054 if (name
&& name
[0]) /* need to create the subkey */
1056 if ((ret
= RegCreateKeyW( hkey
, name
, &subkey
)) != ERROR_SUCCESS
) return ret
;
1059 ret
= RegSetValueExW( subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)data
,
1060 (strlenW( data
) + 1) * sizeof(WCHAR
) );
1061 if (subkey
!= hkey
) RegCloseKey( subkey
);
1066 /******************************************************************************
1067 * RegSetValueA [ADVAPI32.@]
1071 DWORD WINAPI
RegSetValueA( HKEY hkey
, LPCSTR name
, DWORD type
, LPCSTR data
, DWORD count
)
1076 TRACE("(%p,%s,%ld,%s,%ld)\n", hkey
, debugstr_a(name
), type
, debugstr_a(data
), count
);
1078 if (type
!= REG_SZ
) return ERROR_INVALID_PARAMETER
;
1080 if (name
&& name
[0]) /* need to create the subkey */
1082 if ((ret
= RegCreateKeyA( hkey
, name
, &subkey
)) != ERROR_SUCCESS
) return ret
;
1084 ret
= RegSetValueExA( subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)data
, strlen(data
)+1 );
1085 if (subkey
!= hkey
) RegCloseKey( subkey
);
1091 /******************************************************************************
1092 * RegQueryValueExW [ADVAPI32.@]
1094 * See RegQueryValueExA.
1096 DWORD WINAPI
RegQueryValueExW( HKEY hkey
, LPCWSTR name
, LPDWORD reserved
, LPDWORD type
,
1097 LPBYTE data
, LPDWORD count
)
1100 UNICODE_STRING name_str
;
1102 char buffer
[256], *buf_ptr
= buffer
;
1103 KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
1104 static const int info_size
= offsetof( KEY_VALUE_PARTIAL_INFORMATION
, Data
);
1106 TRACE("(%p,%s,%p,%p,%p,%p=%ld)\n",
1107 hkey
, debugstr_w(name
), reserved
, type
, data
, count
,
1108 (count
&& data
) ? *count
: 0 );
1110 if ((data
&& !count
) || reserved
) return ERROR_INVALID_PARAMETER
;
1111 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1113 RtlInitUnicodeString( &name_str
, name
);
1115 if (data
) total_size
= min( sizeof(buffer
), *count
+ info_size
);
1116 else total_size
= info_size
;
1118 status
= NtQueryValueKey( hkey
, &name_str
, KeyValuePartialInformation
,
1119 buffer
, total_size
, &total_size
);
1120 if (status
&& status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
1124 /* retry with a dynamically allocated buffer */
1125 while (status
== STATUS_BUFFER_OVERFLOW
&& total_size
- info_size
<= *count
)
1127 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1128 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
1129 return ERROR_NOT_ENOUGH_MEMORY
;
1130 info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buf_ptr
;
1131 status
= NtQueryValueKey( hkey
, &name_str
, KeyValuePartialInformation
,
1132 buf_ptr
, total_size
, &total_size
);
1137 memcpy( data
, buf_ptr
+ info_size
, total_size
- info_size
);
1138 /* if the type is REG_SZ and data is not 0-terminated
1139 * and there is enough space in the buffer NT appends a \0 */
1140 if (total_size
- info_size
<= *count
-sizeof(WCHAR
) && is_string(info
->Type
))
1142 WCHAR
*ptr
= (WCHAR
*)(data
+ total_size
- info_size
);
1143 if (ptr
> (WCHAR
*)data
&& ptr
[-1]) *ptr
= 0;
1146 else if (status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
1148 else status
= STATUS_SUCCESS
;
1150 if (type
) *type
= info
->Type
;
1151 if (count
) *count
= total_size
- info_size
;
1154 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1155 return RtlNtStatusToDosError(status
);
1159 /******************************************************************************
1160 * RegQueryValueExA [ADVAPI32.@]
1162 * Get the type and contents of a specified value under with a key.
1165 * hkey [I] Handle of the key to query
1166 * name [I] Name of value under hkey to query
1167 * reserved [I] Reserved - must be NULL
1168 * type [O] Destination for the value type, or NULL if not required
1169 * data [O] Destination for the values contents, or NULL if not required
1170 * count [I/O] Size of data, updated with the number of bytes returned
1173 * Success: ERROR_SUCCESS. *count is updated with the number of bytes copied to data.
1174 * Failure: ERROR_INVALID_HANDLE, if hkey is invalid.
1175 * ERROR_INVALID_PARAMETER, if any other parameter is invalid.
1176 * ERROR_MORE_DATA, if on input *count is too small to hold the contents.
1179 * MSDN states that if data is too small it is partially filled. In reality
1180 * it remains untouched.
1182 DWORD WINAPI
RegQueryValueExA( HKEY hkey
, LPCSTR name
, LPDWORD reserved
, LPDWORD type
,
1183 LPBYTE data
, LPDWORD count
)
1188 char buffer
[256], *buf_ptr
= buffer
;
1189 KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buffer
;
1190 static const int info_size
= offsetof( KEY_VALUE_PARTIAL_INFORMATION
, Data
);
1192 TRACE("(%p,%s,%p,%p,%p,%p=%ld)\n",
1193 hkey
, debugstr_a(name
), reserved
, type
, data
, count
, count
? *count
: 0 );
1195 if ((data
&& !count
) || reserved
) return ERROR_INVALID_PARAMETER
;
1196 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1198 RtlInitAnsiString( &nameA
, name
);
1199 if ((status
= RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString
,
1201 return RtlNtStatusToDosError(status
);
1203 status
= NtQueryValueKey( hkey
, &NtCurrentTeb()->StaticUnicodeString
,
1204 KeyValuePartialInformation
, buffer
, sizeof(buffer
), &total_size
);
1205 if (status
&& status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
1207 /* we need to fetch the contents for a string type even if not requested,
1208 * because we need to compute the length of the ASCII string. */
1209 if (data
|| is_string(info
->Type
))
1211 /* retry with a dynamically allocated buffer */
1212 while (status
== STATUS_BUFFER_OVERFLOW
)
1214 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1215 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
1217 status
= STATUS_NO_MEMORY
;
1220 info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buf_ptr
;
1221 status
= NtQueryValueKey( hkey
, &NtCurrentTeb()->StaticUnicodeString
,
1222 KeyValuePartialInformation
, buf_ptr
, total_size
, &total_size
);
1225 if (status
) goto done
;
1227 if (is_string(info
->Type
))
1231 RtlUnicodeToMultiByteSize( &len
, (WCHAR
*)(buf_ptr
+ info_size
),
1232 total_size
- info_size
);
1235 if (len
> *count
) status
= STATUS_BUFFER_OVERFLOW
;
1238 RtlUnicodeToMultiByteN( data
, len
, NULL
, (WCHAR
*)(buf_ptr
+ info_size
),
1239 total_size
- info_size
);
1240 /* if the type is REG_SZ and data is not 0-terminated
1241 * and there is enough space in the buffer NT appends a \0 */
1242 if (len
< *count
&& data
[len
-1]) data
[len
] = 0;
1245 total_size
= len
+ info_size
;
1249 if (total_size
- info_size
> *count
) status
= STATUS_BUFFER_OVERFLOW
;
1250 else memcpy( data
, buf_ptr
+ info_size
, total_size
- info_size
);
1253 else status
= STATUS_SUCCESS
;
1255 if (type
) *type
= info
->Type
;
1256 if (count
) *count
= total_size
- info_size
;
1259 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1260 return RtlNtStatusToDosError(status
);
1264 /******************************************************************************
1265 * RegQueryValueW [ADVAPI32.@]
1267 * Retrieves the data associated with the default or unnamed value of a key.
1270 * hkey [I] Handle to an open key.
1271 * name [I] Name of the subkey of hKey.
1272 * data [O] Receives the string associated with the default value
1274 * count [I/O] Size of lpValue in bytes.
1277 * Success: ERROR_SUCCESS
1278 * Failure: nonzero error code from Winerror.h
1280 DWORD WINAPI
RegQueryValueW( HKEY hkey
, LPCWSTR name
, LPWSTR data
, LPLONG count
)
1285 TRACE("(%p,%s,%p,%ld)\n", hkey
, debugstr_w(name
), data
, count
? *count
: 0 );
1287 if (name
&& name
[0])
1289 if ((ret
= RegOpenKeyW( hkey
, name
, &subkey
)) != ERROR_SUCCESS
) return ret
;
1291 ret
= RegQueryValueExW( subkey
, NULL
, NULL
, NULL
, (LPBYTE
)data
, count
);
1292 if (subkey
!= hkey
) RegCloseKey( subkey
);
1293 if (ret
== ERROR_FILE_NOT_FOUND
)
1295 /* return empty string if default value not found */
1296 if (data
) *data
= 0;
1297 if (count
) *count
= sizeof(WCHAR
);
1298 ret
= ERROR_SUCCESS
;
1304 /******************************************************************************
1305 * RegQueryValueA [ADVAPI32.@]
1307 * see RegQueryValueW
1309 DWORD WINAPI
RegQueryValueA( HKEY hkey
, LPCSTR name
, LPSTR data
, LPLONG count
)
1314 TRACE("(%p,%s,%p,%ld)\n", hkey
, debugstr_a(name
), data
, count
? *count
: 0 );
1316 if (name
&& name
[0])
1318 if ((ret
= RegOpenKeyA( hkey
, name
, &subkey
)) != ERROR_SUCCESS
) return ret
;
1320 ret
= RegQueryValueExA( subkey
, NULL
, NULL
, NULL
, (LPBYTE
)data
, count
);
1321 if (subkey
!= hkey
) RegCloseKey( subkey
);
1322 if (ret
== ERROR_FILE_NOT_FOUND
)
1324 /* return empty string if default value not found */
1325 if (data
) *data
= 0;
1326 if (count
) *count
= 1;
1327 ret
= ERROR_SUCCESS
;
1333 /******************************************************************************
1334 * RegEnumValueW [ADVAPI32.@]
1337 * hkey [I] Handle to key to query
1338 * index [I] Index of value to query
1339 * value [O] Value string
1340 * val_count [I/O] Size of value buffer (in wchars)
1341 * reserved [I] Reserved
1342 * type [O] Type code
1343 * data [O] Value data
1344 * count [I/O] Size of data buffer (in bytes)
1347 * Success: ERROR_SUCCESS
1348 * Failure: nonzero error code from Winerror.h
1351 DWORD WINAPI
RegEnumValueW( HKEY hkey
, DWORD index
, LPWSTR value
, LPDWORD val_count
,
1352 LPDWORD reserved
, LPDWORD type
, LPBYTE data
, LPDWORD count
)
1356 char buffer
[256], *buf_ptr
= buffer
;
1357 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
1358 static const int info_size
= offsetof( KEY_VALUE_FULL_INFORMATION
, Name
);
1360 TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
1361 hkey
, index
, value
, val_count
, reserved
, type
, data
, count
);
1363 /* NT only checks count, not val_count */
1364 if ((data
&& !count
) || reserved
) return ERROR_INVALID_PARAMETER
;
1365 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1367 total_size
= info_size
+ (MAX_PATH
+ 1) * sizeof(WCHAR
);
1368 if (data
) total_size
+= *count
;
1369 total_size
= min( sizeof(buffer
), total_size
);
1371 status
= NtEnumerateValueKey( hkey
, index
, KeyValueFullInformation
,
1372 buffer
, total_size
, &total_size
);
1373 if (status
&& status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
1377 /* retry with a dynamically allocated buffer */
1378 while (status
== STATUS_BUFFER_OVERFLOW
)
1380 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1381 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
1382 return ERROR_NOT_ENOUGH_MEMORY
;
1383 info
= (KEY_VALUE_FULL_INFORMATION
*)buf_ptr
;
1384 status
= NtEnumerateValueKey( hkey
, index
, KeyValueFullInformation
,
1385 buf_ptr
, total_size
, &total_size
);
1388 if (status
) goto done
;
1392 if (info
->NameLength
/sizeof(WCHAR
) >= *val_count
)
1394 status
= STATUS_BUFFER_OVERFLOW
;
1397 memcpy( value
, info
->Name
, info
->NameLength
);
1398 *val_count
= info
->NameLength
/ sizeof(WCHAR
);
1399 value
[*val_count
] = 0;
1404 if (total_size
- info
->DataOffset
> *count
)
1406 status
= STATUS_BUFFER_OVERFLOW
;
1409 memcpy( data
, buf_ptr
+ info
->DataOffset
, total_size
- info
->DataOffset
);
1410 if (total_size
- info
->DataOffset
<= *count
-sizeof(WCHAR
) && is_string(info
->Type
))
1412 /* if the type is REG_SZ and data is not 0-terminated
1413 * and there is enough space in the buffer NT appends a \0 */
1414 WCHAR
*ptr
= (WCHAR
*)(data
+ total_size
- info
->DataOffset
);
1415 if (ptr
> (WCHAR
*)data
&& ptr
[-1]) *ptr
= 0;
1419 else status
= STATUS_SUCCESS
;
1422 if (type
) *type
= info
->Type
;
1423 if (count
) *count
= info
->DataLength
;
1426 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1427 return RtlNtStatusToDosError(status
);
1431 /******************************************************************************
1432 * RegEnumValueA [ADVAPI32.@]
1436 DWORD WINAPI
RegEnumValueA( HKEY hkey
, DWORD index
, LPSTR value
, LPDWORD val_count
,
1437 LPDWORD reserved
, LPDWORD type
, LPBYTE data
, LPDWORD count
)
1441 char buffer
[256], *buf_ptr
= buffer
;
1442 KEY_VALUE_FULL_INFORMATION
*info
= (KEY_VALUE_FULL_INFORMATION
*)buffer
;
1443 static const int info_size
= offsetof( KEY_VALUE_FULL_INFORMATION
, Name
);
1445 TRACE("(%p,%ld,%p,%p,%p,%p,%p,%p)\n",
1446 hkey
, index
, value
, val_count
, reserved
, type
, data
, count
);
1448 /* NT only checks count, not val_count */
1449 if ((data
&& !count
) || reserved
) return ERROR_INVALID_PARAMETER
;
1450 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1452 total_size
= info_size
+ (MAX_PATH
+ 1) * sizeof(WCHAR
);
1453 if (data
) total_size
+= *count
;
1454 total_size
= min( sizeof(buffer
), total_size
);
1456 status
= NtEnumerateValueKey( hkey
, index
, KeyValueFullInformation
,
1457 buffer
, total_size
, &total_size
);
1458 if (status
&& status
!= STATUS_BUFFER_OVERFLOW
) goto done
;
1460 /* we need to fetch the contents for a string type even if not requested,
1461 * because we need to compute the length of the ASCII string. */
1462 if (value
|| data
|| is_string(info
->Type
))
1464 /* retry with a dynamically allocated buffer */
1465 while (status
== STATUS_BUFFER_OVERFLOW
)
1467 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1468 if (!(buf_ptr
= HeapAlloc( GetProcessHeap(), 0, total_size
)))
1469 return ERROR_NOT_ENOUGH_MEMORY
;
1470 info
= (KEY_VALUE_FULL_INFORMATION
*)buf_ptr
;
1471 status
= NtEnumerateValueKey( hkey
, index
, KeyValueFullInformation
,
1472 buf_ptr
, total_size
, &total_size
);
1475 if (status
) goto done
;
1477 if (is_string(info
->Type
))
1480 RtlUnicodeToMultiByteSize( &len
, (WCHAR
*)(buf_ptr
+ info
->DataOffset
),
1481 total_size
- info
->DataOffset
);
1484 if (len
> *count
) status
= STATUS_BUFFER_OVERFLOW
;
1487 RtlUnicodeToMultiByteN( data
, len
, NULL
, (WCHAR
*)(buf_ptr
+ info
->DataOffset
),
1488 total_size
- info
->DataOffset
);
1489 /* if the type is REG_SZ and data is not 0-terminated
1490 * and there is enough space in the buffer NT appends a \0 */
1491 if (len
< *count
&& data
[len
-1]) data
[len
] = 0;
1494 info
->DataLength
= len
;
1498 if (total_size
- info
->DataOffset
> *count
) status
= STATUS_BUFFER_OVERFLOW
;
1499 else memcpy( data
, buf_ptr
+ info
->DataOffset
, total_size
- info
->DataOffset
);
1502 if (value
&& !status
)
1506 RtlUnicodeToMultiByteSize( &len
, info
->Name
, info
->NameLength
);
1507 if (len
>= *val_count
)
1509 status
= STATUS_BUFFER_OVERFLOW
;
1512 len
= *val_count
- 1;
1513 RtlUnicodeToMultiByteN( value
, len
, NULL
, info
->Name
, info
->NameLength
);
1519 RtlUnicodeToMultiByteN( value
, len
, NULL
, info
->Name
, info
->NameLength
);
1525 else status
= STATUS_SUCCESS
;
1527 if (type
) *type
= info
->Type
;
1528 if (count
) *count
= info
->DataLength
;
1531 if (buf_ptr
!= buffer
) HeapFree( GetProcessHeap(), 0, buf_ptr
);
1532 return RtlNtStatusToDosError(status
);
1537 /******************************************************************************
1538 * RegDeleteValueW [ADVAPI32.@]
1540 * See RegDeleteValueA.
1542 DWORD WINAPI
RegDeleteValueW( HKEY hkey
, LPCWSTR name
)
1544 UNICODE_STRING nameW
;
1546 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1548 RtlInitUnicodeString( &nameW
, name
);
1549 return RtlNtStatusToDosError( NtDeleteValueKey( hkey
, &nameW
) );
1553 /******************************************************************************
1554 * RegDeleteValueA [ADVAPI32.@]
1556 * Delete a value from the registry.
1559 * hkey [I] Registry handle of the key holding the value
1560 * name [I] Name of the value under hkey to delete
1563 * Success: ERROR_SUCCESS
1564 * Failure: nonzero error code from Winerror.h
1566 DWORD WINAPI
RegDeleteValueA( HKEY hkey
, LPCSTR name
)
1571 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1573 RtlInitAnsiString( &nameA
, name
);
1574 if (!(status
= RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString
,
1576 status
= NtDeleteValueKey( hkey
, &NtCurrentTeb()->StaticUnicodeString
);
1577 return RtlNtStatusToDosError( status
);
1581 /******************************************************************************
1582 * RegLoadKeyW [ADVAPI32.@]
1585 * hkey [I] Handle of open key
1586 * subkey [I] Address of name of subkey
1587 * filename [I] Address of filename for registry information
1590 * Success: ERROR_SUCCES
1591 * Failure: nonzero error code from Winerror.h
1593 LONG WINAPI
RegLoadKeyW( HKEY hkey
, LPCWSTR subkey
, LPCWSTR filename
)
1595 OBJECT_ATTRIBUTES destkey
, file
;
1596 UNICODE_STRING subkeyW
, filenameW
;
1598 if (!(hkey
= get_special_root_hkey(hkey
))) return ERROR_INVALID_HANDLE
;
1600 destkey
.Length
= sizeof(destkey
);
1601 destkey
.RootDirectory
= hkey
; /* root key: HKLM or HKU */
1602 destkey
.ObjectName
= &subkeyW
; /* name of the key */
1603 destkey
.Attributes
= 0;
1604 destkey
.SecurityDescriptor
= NULL
;
1605 destkey
.SecurityQualityOfService
= NULL
;
1606 RtlInitUnicodeString(&subkeyW
, subkey
);
1608 file
.Length
= sizeof(file
);
1609 file
.RootDirectory
= NULL
;
1610 file
.ObjectName
= &filenameW
; /* file containing the hive */
1611 file
.Attributes
= OBJ_CASE_INSENSITIVE
;
1612 file
.SecurityDescriptor
= NULL
;
1613 file
.SecurityQualityOfService
= NULL
;
1614 RtlDosPathNameToNtPathName_U(filename
, &filenameW
, NULL
, NULL
);
1616 return RtlNtStatusToDosError( NtLoadKey(&destkey
, &file
) );
1620 /******************************************************************************
1621 * RegLoadKeyA [ADVAPI32.@]
1625 LONG WINAPI
RegLoadKeyA( HKEY hkey
, LPCSTR subkey
, LPCSTR filename
)
1627 UNICODE_STRING subkeyW
, filenameW
;
1628 STRING subkeyA
, filenameA
;
1631 RtlInitAnsiString(&subkeyA
, subkey
);
1632 RtlInitAnsiString(&filenameA
, filename
);
1634 if ((status
= RtlAnsiStringToUnicodeString(&subkeyW
, &subkeyA
, TRUE
)))
1635 return RtlNtStatusToDosError(status
);
1637 if ((status
= RtlAnsiStringToUnicodeString(&filenameW
, &filenameA
, TRUE
)))
1638 return RtlNtStatusToDosError(status
);
1640 return RegLoadKeyW(hkey
, subkeyW
.Buffer
, filenameW
.Buffer
);
1644 /******************************************************************************
1645 * RegSaveKeyW [ADVAPI32.@]
1648 * hkey [I] Handle of key where save begins
1649 * lpFile [I] Address of filename to save to
1650 * sa [I] Address of security structure
1653 * Success: ERROR_SUCCESS
1654 * Failure: nonzero error code from Winerror.h
1656 LONG WINAPI
RegSaveKeyW( HKEY hkey
, LPCWSTR file
, LPSECURITY_ATTRIBUTES sa
)
1658 static const WCHAR format
[] =
1659 {'r','e','g','%','0','4','x','.','t','m','p',0};
1660 WCHAR buffer
[MAX_PATH
];
1666 TRACE( "(%p,%s,%p)\n", hkey
, debugstr_w(file
), sa
);
1668 if (!file
|| !*file
) return ERROR_INVALID_PARAMETER
;
1669 if (!(hkey
= get_special_root_hkey( hkey
))) return ERROR_INVALID_HANDLE
;
1671 err
= GetLastError();
1672 GetFullPathNameW( file
, sizeof(buffer
)/sizeof(WCHAR
), buffer
, &nameW
);
1676 snprintfW( nameW
, 16, format
, count
++ );
1677 handle
= CreateFileW( buffer
, GENERIC_WRITE
, 0, NULL
,
1678 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1679 if (handle
!= INVALID_HANDLE_VALUE
) break;
1680 if ((ret
= GetLastError()) != ERROR_ALREADY_EXISTS
) goto done
;
1682 /* Something gone haywire ? Please report if this happens abnormally */
1684 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", debugstr_w(buffer
), count
);
1687 ret
= RtlNtStatusToDosError(NtSaveKey(hkey
, handle
));
1689 CloseHandle( handle
);
1692 if (!MoveFileExW( buffer
, file
, MOVEFILE_REPLACE_EXISTING
))
1694 ERR( "Failed to move %s to %s\n", debugstr_w(buffer
),
1696 ret
= GetLastError();
1699 if (ret
) DeleteFileW( buffer
);
1702 SetLastError( err
); /* restore last error code */
1707 /******************************************************************************
1708 * RegSaveKeyA [ADVAPI32.@]
1712 LONG WINAPI
RegSaveKeyA( HKEY hkey
, LPCSTR file
, LPSECURITY_ATTRIBUTES sa
)
1714 UNICODE_STRING
*fileW
= &NtCurrentTeb()->StaticUnicodeString
;
1718 RtlInitAnsiString(&fileA
, file
);
1719 if ((status
= RtlAnsiStringToUnicodeString(fileW
, &fileA
, FALSE
)))
1720 return RtlNtStatusToDosError( status
);
1721 return RegSaveKeyW(hkey
, fileW
->Buffer
, sa
);
1725 /******************************************************************************
1726 * RegRestoreKeyW [ADVAPI32.@]
1729 * hkey [I] Handle of key where restore begins
1730 * lpFile [I] Address of filename containing saved tree
1731 * dwFlags [I] Optional flags
1734 * Success: ERROR_SUCCESS
1735 * Failure: nonzero error code from Winerror.h
1737 LONG WINAPI
RegRestoreKeyW( HKEY hkey
, LPCWSTR lpFile
, DWORD dwFlags
)
1739 TRACE("(%p,%s,%ld)\n",hkey
,debugstr_w(lpFile
),dwFlags
);
1741 /* It seems to do this check before the hkey check */
1742 if (!lpFile
|| !*lpFile
)
1743 return ERROR_INVALID_PARAMETER
;
1745 FIXME("(%p,%s,%ld): stub\n",hkey
,debugstr_w(lpFile
),dwFlags
);
1747 /* Check for file existence */
1749 return ERROR_SUCCESS
;
1753 /******************************************************************************
1754 * RegRestoreKeyA [ADVAPI32.@]
1756 * see RegRestoreKeyW
1758 LONG WINAPI
RegRestoreKeyA( HKEY hkey
, LPCSTR lpFile
, DWORD dwFlags
)
1760 UNICODE_STRING lpFileW
;
1763 RtlCreateUnicodeStringFromAsciiz( &lpFileW
, lpFile
);
1764 ret
= RegRestoreKeyW( hkey
, lpFileW
.Buffer
, dwFlags
);
1765 RtlFreeUnicodeString( &lpFileW
);
1770 /******************************************************************************
1771 * RegUnLoadKeyW [ADVAPI32.@]
1774 * hkey [I] Handle of open key
1775 * lpSubKey [I] Address of name of subkey to unload
1778 * Success: ERROR_SUCCESS
1779 * Failure: nonzero error code from Winerror.h
1781 LONG WINAPI
RegUnLoadKeyW( HKEY hkey
, LPCWSTR lpSubKey
)
1786 TRACE("(%p,%s)\n",hkey
, debugstr_w(lpSubKey
));
1788 ret
= RegOpenKeyW(hkey
,lpSubKey
,&shkey
);
1790 return ERROR_INVALID_PARAMETER
;
1792 ret
= RtlNtStatusToDosError(NtUnloadKey(shkey
));
1800 /******************************************************************************
1801 * RegUnLoadKeyA [ADVAPI32.@]
1805 LONG WINAPI
RegUnLoadKeyA( HKEY hkey
, LPCSTR lpSubKey
)
1807 UNICODE_STRING lpSubKeyW
;
1810 RtlCreateUnicodeStringFromAsciiz( &lpSubKeyW
, lpSubKey
);
1811 ret
= RegUnLoadKeyW( hkey
, lpSubKeyW
.Buffer
);
1812 RtlFreeUnicodeString( &lpSubKeyW
);
1817 /******************************************************************************
1818 * RegReplaceKeyW [ADVAPI32.@]
1821 * hkey [I] Handle of open key
1822 * lpSubKey [I] Address of name of subkey
1823 * lpNewFile [I] Address of filename for file with new data
1824 * lpOldFile [I] Address of filename for backup file
1827 * Success: ERROR_SUCCESS
1828 * Failure: nonzero error code from Winerror.h
1830 LONG WINAPI
RegReplaceKeyW( HKEY hkey
, LPCWSTR lpSubKey
, LPCWSTR lpNewFile
,
1833 FIXME("(%p,%s,%s,%s): stub\n", hkey
, debugstr_w(lpSubKey
),
1834 debugstr_w(lpNewFile
),debugstr_w(lpOldFile
));
1835 return ERROR_SUCCESS
;
1839 /******************************************************************************
1840 * RegReplaceKeyA [ADVAPI32.@]
1842 * see RegReplaceKeyW
1844 LONG WINAPI
RegReplaceKeyA( HKEY hkey
, LPCSTR lpSubKey
, LPCSTR lpNewFile
,
1847 UNICODE_STRING lpSubKeyW
;
1848 UNICODE_STRING lpNewFileW
;
1849 UNICODE_STRING lpOldFileW
;
1852 RtlCreateUnicodeStringFromAsciiz( &lpSubKeyW
, lpSubKey
);
1853 RtlCreateUnicodeStringFromAsciiz( &lpOldFileW
, lpOldFile
);
1854 RtlCreateUnicodeStringFromAsciiz( &lpNewFileW
, lpNewFile
);
1855 ret
= RegReplaceKeyW( hkey
, lpSubKeyW
.Buffer
, lpNewFileW
.Buffer
, lpOldFileW
.Buffer
);
1856 RtlFreeUnicodeString( &lpOldFileW
);
1857 RtlFreeUnicodeString( &lpNewFileW
);
1858 RtlFreeUnicodeString( &lpSubKeyW
);
1863 /******************************************************************************
1864 * RegSetKeySecurity [ADVAPI32.@]
1867 * hkey [I] Open handle of key to set
1868 * SecurityInfo [I] Descriptor contents
1869 * pSecurityDesc [I] Address of descriptor for key
1872 * Success: ERROR_SUCCESS
1873 * Failure: nonzero error code from Winerror.h
1875 LONG WINAPI
RegSetKeySecurity( HKEY hkey
, SECURITY_INFORMATION SecurityInfo
,
1876 PSECURITY_DESCRIPTOR pSecurityDesc
)
1878 TRACE("(%p,%ld,%p)\n",hkey
,SecurityInfo
,pSecurityDesc
);
1880 /* It seems to perform this check before the hkey check */
1881 if ((SecurityInfo
& OWNER_SECURITY_INFORMATION
) ||
1882 (SecurityInfo
& GROUP_SECURITY_INFORMATION
) ||
1883 (SecurityInfo
& DACL_SECURITY_INFORMATION
) ||
1884 (SecurityInfo
& SACL_SECURITY_INFORMATION
)) {
1887 return ERROR_INVALID_PARAMETER
;
1890 return ERROR_INVALID_PARAMETER
;
1892 FIXME(":(%p,%ld,%p): stub\n",hkey
,SecurityInfo
,pSecurityDesc
);
1894 return ERROR_SUCCESS
;
1898 /******************************************************************************
1899 * RegGetKeySecurity [ADVAPI32.@]
1901 * Get a copy of the security descriptor for a given registry key.
1904 * hkey [I] Open handle of key to set
1905 * SecurityInformation [I] Descriptor contents
1906 * pSecurityDescriptor [O] Address of descriptor for key
1907 * lpcbSecurityDescriptor [I/O] Address of size of buffer and description
1910 * Success: ERROR_SUCCESS
1911 * Failure: Error code
1913 LONG WINAPI
RegGetKeySecurity( HKEY hkey
, SECURITY_INFORMATION SecurityInformation
,
1914 PSECURITY_DESCRIPTOR pSecurityDescriptor
,
1915 LPDWORD lpcbSecurityDescriptor
)
1917 TRACE("(%p,%ld,%p,%ld)\n",hkey
,SecurityInformation
,pSecurityDescriptor
,
1918 lpcbSecurityDescriptor
?*lpcbSecurityDescriptor
:0);
1920 /* FIXME: Check for valid SecurityInformation values */
1922 if (*lpcbSecurityDescriptor
< sizeof(SECURITY_DESCRIPTOR
))
1923 return ERROR_INSUFFICIENT_BUFFER
;
1925 FIXME("(%p,%ld,%p,%ld): stub\n",hkey
,SecurityInformation
,
1926 pSecurityDescriptor
,lpcbSecurityDescriptor
?*lpcbSecurityDescriptor
:0);
1928 /* Do not leave security descriptor filled with garbage */
1929 RtlCreateSecurityDescriptor(pSecurityDescriptor
, SECURITY_DESCRIPTOR_REVISION
);
1931 return ERROR_SUCCESS
;
1935 /******************************************************************************
1936 * RegFlushKey [ADVAPI32.@]
1938 * Immediately write a registry key to registry.
1941 * hkey [I] Handle of key to write
1944 * Success: ERROR_SUCCESS
1945 * Failure: Error code
1947 DWORD WINAPI
RegFlushKey( HKEY hkey
)
1949 hkey
= get_special_root_hkey( hkey
);
1950 if (!hkey
) return ERROR_INVALID_HANDLE
;
1952 return RtlNtStatusToDosError( NtFlushKey( hkey
) );
1956 /******************************************************************************
1957 * RegConnectRegistryW [ADVAPI32.@]
1960 * lpMachineName [I] Address of name of remote computer
1961 * hHey [I] Predefined registry handle
1962 * phkResult [I] Address of buffer for remote registry handle
1965 * Success: ERROR_SUCCESS
1966 * Failure: nonzero error code from Winerror.h
1968 LONG WINAPI
RegConnectRegistryW( LPCWSTR lpMachineName
, HKEY hKey
,
1973 TRACE("(%s,%p,%p): stub\n",debugstr_w(lpMachineName
),hKey
,phkResult
);
1975 if (!lpMachineName
|| !*lpMachineName
) {
1976 /* Use the local machine name */
1977 ret
= RegOpenKeyW( hKey
, NULL
, phkResult
);
1979 else if (lpMachineName
[0] != '\\' || lpMachineName
[1] != '\\')
1980 ret
= ERROR_BAD_NETPATH
;
1983 WCHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1984 DWORD len
= sizeof(compName
) / sizeof(WCHAR
);
1986 if (GetComputerNameW(compName
, &len
))
1988 if (!strcmpiW(lpMachineName
+ 2, compName
))
1989 ret
= RegOpenKeyW(hKey
, NULL
, phkResult
);
1992 FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName
));
1993 ret
= ERROR_BAD_NETPATH
;
1997 ret
= GetLastError();
2003 /******************************************************************************
2004 * RegConnectRegistryA [ADVAPI32.@]
2006 * see RegConnectRegistryW
2008 LONG WINAPI
RegConnectRegistryA( LPCSTR machine
, HKEY hkey
, PHKEY reskey
)
2010 UNICODE_STRING machineW
;
2013 RtlCreateUnicodeStringFromAsciiz( &machineW
, machine
);
2014 ret
= RegConnectRegistryW( machineW
.Buffer
, hkey
, reskey
);
2015 RtlFreeUnicodeString( &machineW
);
2020 /******************************************************************************
2021 * RegNotifyChangeKeyValue [ADVAPI32.@]
2024 * hkey [I] Handle of key to watch
2025 * fWatchSubTree [I] Flag for subkey notification
2026 * fdwNotifyFilter [I] Changes to be reported
2027 * hEvent [I] Handle of signaled event
2028 * fAsync [I] Flag for asynchronous reporting
2031 * Success: ERROR_SUCCESS
2032 * Failure: nonzero error code from Winerror.h
2034 LONG WINAPI
RegNotifyChangeKeyValue( HKEY hkey
, BOOL fWatchSubTree
,
2035 DWORD fdwNotifyFilter
, HANDLE hEvent
,
2040 TRACE("(%p,%i,%ld,%p,%i)\n",hkey
,fWatchSubTree
,fdwNotifyFilter
,
2044 hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
2046 SERVER_START_REQ( set_registry_notification
)
2049 req
->event
= hEvent
;
2050 req
->subtree
= fWatchSubTree
;
2051 req
->filter
= fdwNotifyFilter
;
2052 ret
= RtlNtStatusToDosError( wine_server_call(req
) );
2058 if( ret
== ERROR_SUCCESS
)
2059 WaitForSingleObject( hEvent
, INFINITE
);
2060 CloseHandle( hEvent
);
2066 /******************************************************************************
2067 * RegOpenUserClassesRoot [ADVAPI32.@]
2069 * Open the HKEY_CLASSES_ROOT key for a user.
2072 * hToken [I] Handle of token representing the user
2073 * dwOptions [I] Reserved, nust be 0
2074 * samDesired [I] Desired access rights
2075 * phkResult [O] Destination for the resulting key handle
2078 * Success: ERROR_SUCCESS
2079 * Failure: nonzero error code from Winerror.h
2082 * On Windows 2000 and upwards the HKEY_CLASSES_ROOT key is a view of the
2083 * "HKEY_LOCAL_MACHINE\Software\Classes" and the
2084 * "HKEY_CURRENT_USER\Software\Classes" keys merged together.
2086 LONG WINAPI
RegOpenUserClassesRoot(
2093 FIXME("(%p, 0x%lx, 0x%lx, %p) semi-stub\n", hToken
, dwOptions
, samDesired
, phkResult
);
2095 *phkResult
= HKEY_CLASSES_ROOT
;
2096 return ERROR_SUCCESS
;