msi: Increase verbosity in some failing tests.
[wine/multimedia.git] / dlls / ntdll / reg.c
blobd0c5e62e61790a3ab258b2d44ea3d77f73bad92a
1 /*
2 * Registry functions
4 * Copyright (C) 1999 Juergen Schmied
5 * Copyright (C) 2000 Alexandre Julliard
6 * Copyright 2005 Ivan Leo Puoti, Laurent Pinchart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES:
23 * HKEY_LOCAL_MACHINE \\REGISTRY\\MACHINE
24 * HKEY_USERS \\REGISTRY\\USER
25 * HKEY_CURRENT_CONFIG \\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\HARDWARE PROFILES\\CURRENT
26 * HKEY_CLASSES \\REGISTRY\\MACHINE\\SOFTWARE\\CLASSES
29 #include "config.h"
30 #include "wine/port.h"
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <string.h>
36 #include "ntstatus.h"
37 #define WIN32_NO_STATUS
38 #include "wine/library.h"
39 #include "ntdll_misc.h"
40 #include "wine/debug.h"
41 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(reg);
45 /* maximum length of a key/value name in bytes (without terminating null) */
46 #define MAX_NAME_LENGTH ((MAX_PATH-1) * sizeof(WCHAR))
48 /******************************************************************************
49 * NtCreateKey [NTDLL.@]
50 * ZwCreateKey [NTDLL.@]
52 NTSTATUS WINAPI NtCreateKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
53 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
54 PULONG dispos )
56 NTSTATUS ret;
58 TRACE( "(%p,%s,%s,%lx,%lx,%p)\n", attr->RootDirectory, debugstr_us(attr->ObjectName),
59 debugstr_us(class), options, access, retkey );
61 if (attr->ObjectName->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
62 if (!retkey) return STATUS_INVALID_PARAMETER;
64 SERVER_START_REQ( create_key )
66 req->parent = attr->RootDirectory;
67 req->access = access;
68 req->attributes = attr->Attributes;
69 req->options = options;
70 req->modif = 0;
71 req->namelen = attr->ObjectName->Length;
72 wine_server_add_data( req, attr->ObjectName->Buffer, attr->ObjectName->Length );
73 if (class) wine_server_add_data( req, class->Buffer, class->Length );
74 if (!(ret = wine_server_call( req )))
76 *retkey = reply->hkey;
77 if (dispos) *dispos = reply->created ? REG_CREATED_NEW_KEY : REG_OPENED_EXISTING_KEY;
80 SERVER_END_REQ;
81 TRACE("<- %p\n", *retkey);
82 return ret;
85 /******************************************************************************
86 * RtlpNtCreateKey [NTDLL.@]
88 * See NtCreateKey.
90 NTSTATUS WINAPI RtlpNtCreateKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr,
91 ULONG TitleIndex, const UNICODE_STRING *class, ULONG options,
92 PULONG dispos )
94 OBJECT_ATTRIBUTES oa;
96 if (attr)
98 memcpy( &oa, attr, sizeof oa );
99 oa.Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
100 attr = &oa;
103 return NtCreateKey(retkey, access, attr, 0, NULL, 0, dispos);
106 /******************************************************************************
107 * NtOpenKey [NTDLL.@]
108 * ZwOpenKey [NTDLL.@]
110 * OUT HANDLE retkey (returns 0 when failure)
111 * IN ACCESS_MASK access
112 * IN POBJECT_ATTRIBUTES attr
114 NTSTATUS WINAPI NtOpenKey( PHANDLE retkey, ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr )
116 NTSTATUS ret;
117 DWORD len = attr->ObjectName->Length;
119 TRACE( "(%p,%s,%lx,%p)\n", attr->RootDirectory,
120 debugstr_us(attr->ObjectName), access, retkey );
122 if (len > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
123 if (!retkey) return STATUS_INVALID_PARAMETER;
125 SERVER_START_REQ( open_key )
127 req->parent = attr->RootDirectory;
128 req->access = access;
129 req->attributes = attr->Attributes;
130 wine_server_add_data( req, attr->ObjectName->Buffer, len );
131 ret = wine_server_call( req );
132 *retkey = reply->hkey;
134 SERVER_END_REQ;
135 TRACE("<- %p\n", *retkey);
136 return ret;
139 /******************************************************************************
140 * RtlpNtOpenKey [NTDLL.@]
142 * See NtOpenKey.
144 NTSTATUS WINAPI RtlpNtOpenKey( PHANDLE retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
146 if (attr)
147 attr->Attributes &= ~(OBJ_PERMANENT|OBJ_EXCLUSIVE);
148 return NtOpenKey(retkey, access, attr);
151 /******************************************************************************
152 * NtDeleteKey [NTDLL.@]
153 * ZwDeleteKey [NTDLL.@]
155 NTSTATUS WINAPI NtDeleteKey( HANDLE hkey )
157 NTSTATUS ret;
159 TRACE( "(%p)\n", hkey );
161 SERVER_START_REQ( delete_key )
163 req->hkey = hkey;
164 ret = wine_server_call( req );
166 SERVER_END_REQ;
167 return ret;
170 /******************************************************************************
171 * RtlpNtMakeTemporaryKey [NTDLL.@]
173 * See NtDeleteKey.
175 NTSTATUS WINAPI RtlpNtMakeTemporaryKey( HANDLE hkey )
177 return NtDeleteKey(hkey);
180 /******************************************************************************
181 * NtDeleteValueKey [NTDLL.@]
182 * ZwDeleteValueKey [NTDLL.@]
184 NTSTATUS WINAPI NtDeleteValueKey( HANDLE hkey, const UNICODE_STRING *name )
186 NTSTATUS ret;
188 TRACE( "(%p,%s)\n", hkey, debugstr_us(name) );
189 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
191 SERVER_START_REQ( delete_key_value )
193 req->hkey = hkey;
194 wine_server_add_data( req, name->Buffer, name->Length );
195 ret = wine_server_call( req );
197 SERVER_END_REQ;
198 return ret;
202 /******************************************************************************
203 * enumerate_key
205 * Implementation of NtQueryKey and NtEnumerateKey
207 static NTSTATUS enumerate_key( HANDLE handle, int index, KEY_INFORMATION_CLASS info_class,
208 void *info, DWORD length, DWORD *result_len )
211 NTSTATUS ret;
212 void *data_ptr;
213 size_t fixed_size;
215 switch(info_class)
217 case KeyBasicInformation: data_ptr = ((KEY_BASIC_INFORMATION *)info)->Name; break;
218 case KeyFullInformation: data_ptr = ((KEY_FULL_INFORMATION *)info)->Class; break;
219 case KeyNodeInformation: data_ptr = ((KEY_NODE_INFORMATION *)info)->Name; break;
220 default:
221 FIXME( "Information class %d not implemented\n", info_class );
222 return STATUS_INVALID_PARAMETER;
224 fixed_size = (char *)data_ptr - (char *)info;
226 SERVER_START_REQ( enum_key )
228 req->hkey = handle;
229 req->index = index;
230 req->info_class = info_class;
231 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
232 if (!(ret = wine_server_call( req )))
234 LARGE_INTEGER modif;
236 RtlSecondsSince1970ToTime( reply->modif, &modif );
238 switch(info_class)
240 case KeyBasicInformation:
242 KEY_BASIC_INFORMATION keyinfo;
243 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
244 keyinfo.LastWriteTime = modif;
245 keyinfo.TitleIndex = 0;
246 keyinfo.NameLength = reply->namelen;
247 memcpy( info, &keyinfo, min( length, fixed_size ) );
249 break;
250 case KeyFullInformation:
252 KEY_FULL_INFORMATION keyinfo;
253 fixed_size = (char *)keyinfo.Class - (char *)&keyinfo;
254 keyinfo.LastWriteTime = modif;
255 keyinfo.TitleIndex = 0;
256 keyinfo.ClassLength = wine_server_reply_size(reply);
257 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size : -1;
258 keyinfo.SubKeys = reply->subkeys;
259 keyinfo.MaxNameLen = reply->max_subkey;
260 keyinfo.MaxClassLen = reply->max_class;
261 keyinfo.Values = reply->values;
262 keyinfo.MaxValueNameLen = reply->max_value;
263 keyinfo.MaxValueDataLen = reply->max_data;
264 memcpy( info, &keyinfo, min( length, fixed_size ) );
266 break;
267 case KeyNodeInformation:
269 KEY_NODE_INFORMATION keyinfo;
270 fixed_size = (char *)keyinfo.Name - (char *)&keyinfo;
271 keyinfo.LastWriteTime = modif;
272 keyinfo.TitleIndex = 0;
273 keyinfo.ClassLength = max( 0, wine_server_reply_size(reply) - reply->namelen );
274 keyinfo.ClassOffset = keyinfo.ClassLength ? fixed_size + reply->namelen : -1;
275 keyinfo.NameLength = reply->namelen;
276 memcpy( info, &keyinfo, min( length, fixed_size ) );
278 break;
280 *result_len = fixed_size + reply->total;
281 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
284 SERVER_END_REQ;
285 return ret;
290 /******************************************************************************
291 * NtEnumerateKey [NTDLL.@]
292 * ZwEnumerateKey [NTDLL.@]
294 * NOTES
295 * the name copied into the buffer is NOT 0-terminated
297 NTSTATUS WINAPI NtEnumerateKey( HANDLE handle, ULONG index, KEY_INFORMATION_CLASS info_class,
298 void *info, DWORD length, DWORD *result_len )
300 /* -1 means query key, so avoid it here */
301 if (index == (ULONG)-1) return STATUS_NO_MORE_ENTRIES;
302 return enumerate_key( handle, index, info_class, info, length, result_len );
306 /******************************************************************************
307 * RtlpNtEnumerateSubKey [NTDLL.@]
310 NTSTATUS WINAPI RtlpNtEnumerateSubKey( HANDLE handle, UNICODE_STRING *out, ULONG index )
312 KEY_BASIC_INFORMATION *info;
313 DWORD dwLen, dwResultLen;
314 NTSTATUS ret;
316 if (out->Length)
318 dwLen = out->Length + sizeof(KEY_BASIC_INFORMATION);
319 info = (KEY_BASIC_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
320 if (!info)
321 return STATUS_NO_MEMORY;
323 else
325 dwLen = 0;
326 info = NULL;
329 ret = NtEnumerateKey( handle, index, KeyBasicInformation, info, dwLen, &dwResultLen );
330 dwResultLen -= sizeof(KEY_BASIC_INFORMATION);
332 if (ret == STATUS_BUFFER_OVERFLOW)
333 out->Length = dwResultLen;
334 else if (!ret)
336 if (out->Length < info->NameLength)
338 out->Length = dwResultLen;
339 ret = STATUS_BUFFER_OVERFLOW;
341 else
343 out->Length = info->NameLength;
344 memcpy(out->Buffer, info->Name, info->NameLength);
348 RtlFreeHeap( GetProcessHeap(), 0, info );
349 return ret;
352 /******************************************************************************
353 * NtQueryKey [NTDLL.@]
354 * ZwQueryKey [NTDLL.@]
356 NTSTATUS WINAPI NtQueryKey( HANDLE handle, KEY_INFORMATION_CLASS info_class,
357 void *info, DWORD length, DWORD *result_len )
359 return enumerate_key( handle, -1, info_class, info, length, result_len );
363 /* fill the key value info structure for a specific info class */
364 static void copy_key_value_info( KEY_VALUE_INFORMATION_CLASS info_class, void *info,
365 DWORD length, int type, int name_len, int data_len )
367 switch(info_class)
369 case KeyValueBasicInformation:
371 KEY_VALUE_BASIC_INFORMATION keyinfo;
372 keyinfo.TitleIndex = 0;
373 keyinfo.Type = type;
374 keyinfo.NameLength = name_len;
375 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
376 memcpy( info, &keyinfo, length );
377 break;
379 case KeyValueFullInformation:
381 KEY_VALUE_FULL_INFORMATION keyinfo;
382 keyinfo.TitleIndex = 0;
383 keyinfo.Type = type;
384 keyinfo.DataOffset = (char *)keyinfo.Name - (char *)&keyinfo + name_len;
385 keyinfo.DataLength = data_len;
386 keyinfo.NameLength = name_len;
387 length = min( length, (char *)keyinfo.Name - (char *)&keyinfo );
388 memcpy( info, &keyinfo, length );
389 break;
391 case KeyValuePartialInformation:
393 KEY_VALUE_PARTIAL_INFORMATION keyinfo;
394 keyinfo.TitleIndex = 0;
395 keyinfo.Type = type;
396 keyinfo.DataLength = data_len;
397 length = min( length, (char *)keyinfo.Data - (char *)&keyinfo );
398 memcpy( info, &keyinfo, length );
399 break;
401 default:
402 break;
407 /******************************************************************************
408 * NtEnumerateValueKey [NTDLL.@]
409 * ZwEnumerateValueKey [NTDLL.@]
411 NTSTATUS WINAPI NtEnumerateValueKey( HANDLE handle, ULONG index,
412 KEY_VALUE_INFORMATION_CLASS info_class,
413 void *info, DWORD length, DWORD *result_len )
415 NTSTATUS ret;
416 void *ptr;
417 size_t fixed_size;
419 TRACE( "(%p,%lu,%d,%p,%ld)\n", handle, index, info_class, info, length );
421 /* compute the length we want to retrieve */
422 switch(info_class)
424 case KeyValueBasicInformation: ptr = ((KEY_VALUE_BASIC_INFORMATION *)info)->Name; break;
425 case KeyValueFullInformation: ptr = ((KEY_VALUE_FULL_INFORMATION *)info)->Name; break;
426 case KeyValuePartialInformation: ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data; break;
427 default:
428 FIXME( "Information class %d not implemented\n", info_class );
429 return STATUS_INVALID_PARAMETER;
431 fixed_size = (char *)ptr - (char *)info;
433 SERVER_START_REQ( enum_key_value )
435 req->hkey = handle;
436 req->index = index;
437 req->info_class = info_class;
438 if (length > fixed_size) wine_server_set_reply( req, ptr, length - fixed_size );
439 if (!(ret = wine_server_call( req )))
441 copy_key_value_info( info_class, info, length, reply->type, reply->namelen,
442 wine_server_reply_size(reply) - reply->namelen );
443 *result_len = fixed_size + reply->total;
444 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
447 SERVER_END_REQ;
448 return ret;
452 /******************************************************************************
453 * NtQueryValueKey [NTDLL.@]
454 * ZwQueryValueKey [NTDLL.@]
456 * NOTES
457 * the name in the KeyValueInformation is never set
459 NTSTATUS WINAPI NtQueryValueKey( HANDLE handle, const UNICODE_STRING *name,
460 KEY_VALUE_INFORMATION_CLASS info_class,
461 void *info, DWORD length, DWORD *result_len )
463 NTSTATUS ret;
464 UCHAR *data_ptr;
465 unsigned int fixed_size = 0;
467 TRACE( "(%p,%s,%d,%p,%ld)\n", handle, debugstr_us(name), info_class, info, length );
469 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
471 /* compute the length we want to retrieve */
472 switch(info_class)
474 case KeyValueBasicInformation:
475 fixed_size = (char *)((KEY_VALUE_BASIC_INFORMATION *)info)->Name - (char *)info;
476 data_ptr = NULL;
477 break;
478 case KeyValueFullInformation:
479 data_ptr = (UCHAR *)((KEY_VALUE_FULL_INFORMATION *)info)->Name;
480 fixed_size = (char *)data_ptr - (char *)info;
481 break;
482 case KeyValuePartialInformation:
483 data_ptr = ((KEY_VALUE_PARTIAL_INFORMATION *)info)->Data;
484 fixed_size = (char *)data_ptr - (char *)info;
485 break;
486 default:
487 FIXME( "Information class %d not implemented\n", info_class );
488 return STATUS_INVALID_PARAMETER;
491 SERVER_START_REQ( get_key_value )
493 req->hkey = handle;
494 wine_server_add_data( req, name->Buffer, name->Length );
495 if (length > fixed_size) wine_server_set_reply( req, data_ptr, length - fixed_size );
496 if (!(ret = wine_server_call( req )))
498 copy_key_value_info( info_class, info, length, reply->type,
499 0, wine_server_reply_size(reply) );
500 *result_len = fixed_size + reply->total;
501 if (length < *result_len) ret = STATUS_BUFFER_OVERFLOW;
504 SERVER_END_REQ;
505 return ret;
508 /******************************************************************************
509 * RtlpNtQueryValueKey [NTDLL.@]
512 NTSTATUS WINAPI RtlpNtQueryValueKey( HANDLE handle, ULONG *result_type, PBYTE dest,
513 DWORD *result_len )
515 KEY_VALUE_PARTIAL_INFORMATION *info;
516 UNICODE_STRING name;
517 NTSTATUS ret;
518 DWORD dwResultLen;
519 DWORD dwLen = sizeof (KEY_VALUE_PARTIAL_INFORMATION) + result_len ? *result_len : 0;
521 info = (KEY_VALUE_PARTIAL_INFORMATION*)RtlAllocateHeap( GetProcessHeap(), 0, dwLen );
522 if (!info)
523 return STATUS_NO_MEMORY;
525 name.Length = 0;
526 ret = NtQueryValueKey( handle, &name, KeyValuePartialInformation, info, dwLen, &dwResultLen );
528 if (!ret || ret == STATUS_BUFFER_OVERFLOW)
530 if (result_len)
531 *result_len = info->DataLength;
533 if (result_type)
534 *result_type = info->Type;
536 if (ret != STATUS_BUFFER_OVERFLOW)
537 memcpy( dest, info->Data, info->DataLength );
540 RtlFreeHeap( GetProcessHeap(), 0, info );
541 return ret;
544 /******************************************************************************
545 * NtFlushKey [NTDLL.@]
546 * ZwFlushKey [NTDLL.@]
548 NTSTATUS WINAPI NtFlushKey(HANDLE key)
550 NTSTATUS ret;
552 TRACE("key=%p\n", key);
554 SERVER_START_REQ( flush_key )
556 req->hkey = key;
557 ret = wine_server_call( req );
559 SERVER_END_REQ;
561 return ret;
564 /******************************************************************************
565 * NtLoadKey [NTDLL.@]
566 * ZwLoadKey [NTDLL.@]
568 NTSTATUS WINAPI NtLoadKey( const OBJECT_ATTRIBUTES *attr, OBJECT_ATTRIBUTES *file )
570 NTSTATUS ret;
571 HANDLE hive;
572 IO_STATUS_BLOCK io;
574 TRACE("(%p,%p)\n", attr, file);
576 ret = NtCreateFile(&hive, GENERIC_READ, file, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
577 FILE_OPEN, 0, NULL, 0);
578 if (ret) return ret;
580 SERVER_START_REQ( load_registry )
582 req->hkey = attr->RootDirectory;
583 req->file = hive;
584 wine_server_add_data(req, attr->ObjectName->Buffer, attr->ObjectName->Length);
585 ret = wine_server_call( req );
587 SERVER_END_REQ;
589 NtClose(hive);
591 return ret;
594 /******************************************************************************
595 * NtNotifyChangeKey [NTDLL.@]
596 * ZwNotifyChangeKey [NTDLL.@]
598 NTSTATUS WINAPI NtNotifyChangeKey(
599 IN HANDLE KeyHandle,
600 IN HANDLE Event,
601 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
602 IN PVOID ApcContext OPTIONAL,
603 OUT PIO_STATUS_BLOCK IoStatusBlock,
604 IN ULONG CompletionFilter,
605 IN BOOLEAN Asynchronous,
606 OUT PVOID ChangeBuffer,
607 IN ULONG Length,
608 IN BOOLEAN WatchSubtree)
610 NTSTATUS ret;
612 TRACE("(%p,%p,%p,%p,%p,0x%08lx, 0x%08x,%p,0x%08lx,0x%08x)\n",
613 KeyHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, CompletionFilter,
614 Asynchronous, ChangeBuffer, Length, WatchSubtree);
616 if (ApcRoutine || ApcContext || ChangeBuffer || Length)
617 FIXME("Unimplemented optional parameter\n");
619 if (!Asynchronous)
621 OBJECT_ATTRIBUTES attr;
622 InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
623 ret = NtCreateEvent( &Event, EVENT_ALL_ACCESS, &attr, FALSE, FALSE );
624 if (ret != STATUS_SUCCESS)
625 return ret;
628 SERVER_START_REQ( set_registry_notification )
630 req->hkey = KeyHandle;
631 req->event = Event;
632 req->subtree = WatchSubtree;
633 req->filter = CompletionFilter;
634 ret = wine_server_call( req );
636 SERVER_END_REQ;
638 if (!Asynchronous)
640 if (ret == STATUS_SUCCESS)
641 NtWaitForSingleObject( Event, FALSE, NULL );
642 NtClose( Event );
645 return STATUS_SUCCESS;
648 /******************************************************************************
649 * NtQueryMultipleValueKey [NTDLL]
650 * ZwQueryMultipleValueKey
653 NTSTATUS WINAPI NtQueryMultipleValueKey(
654 HANDLE KeyHandle,
655 PKEY_MULTIPLE_VALUE_INFORMATION ListOfValuesToQuery,
656 ULONG NumberOfItems,
657 PVOID MultipleValueInformation,
658 ULONG Length,
659 PULONG ReturnLength)
661 FIXME("(%p,%p,0x%08lx,%p,0x%08lx,%p) stub!\n",
662 KeyHandle, ListOfValuesToQuery, NumberOfItems, MultipleValueInformation,
663 Length,ReturnLength);
664 return STATUS_SUCCESS;
667 /******************************************************************************
668 * NtReplaceKey [NTDLL.@]
669 * ZwReplaceKey [NTDLL.@]
671 NTSTATUS WINAPI NtReplaceKey(
672 IN POBJECT_ATTRIBUTES ObjectAttributes,
673 IN HANDLE Key,
674 IN POBJECT_ATTRIBUTES ReplacedObjectAttributes)
676 FIXME("(%p),stub!\n", Key);
677 dump_ObjectAttributes(ObjectAttributes);
678 dump_ObjectAttributes(ReplacedObjectAttributes);
679 return STATUS_SUCCESS;
681 /******************************************************************************
682 * NtRestoreKey [NTDLL.@]
683 * ZwRestoreKey [NTDLL.@]
685 NTSTATUS WINAPI NtRestoreKey(
686 HANDLE KeyHandle,
687 HANDLE FileHandle,
688 ULONG RestoreFlags)
690 FIXME("(%p,%p,0x%08lx) stub\n",
691 KeyHandle, FileHandle, RestoreFlags);
692 return STATUS_SUCCESS;
694 /******************************************************************************
695 * NtSaveKey [NTDLL.@]
696 * ZwSaveKey [NTDLL.@]
698 NTSTATUS WINAPI NtSaveKey(IN HANDLE KeyHandle, IN HANDLE FileHandle)
700 NTSTATUS ret;
702 TRACE("(%p,%p)\n", KeyHandle, FileHandle);
704 SERVER_START_REQ( save_registry )
706 req->hkey = KeyHandle;
707 req->file = FileHandle;
708 ret = wine_server_call( req );
710 SERVER_END_REQ;
712 return ret;
714 /******************************************************************************
715 * NtSetInformationKey [NTDLL.@]
716 * ZwSetInformationKey [NTDLL.@]
718 NTSTATUS WINAPI NtSetInformationKey(
719 IN HANDLE KeyHandle,
720 IN const int KeyInformationClass,
721 IN PVOID KeyInformation,
722 IN ULONG KeyInformationLength)
724 FIXME("(%p,0x%08x,%p,0x%08lx) stub\n",
725 KeyHandle, KeyInformationClass, KeyInformation, KeyInformationLength);
726 return STATUS_SUCCESS;
730 /******************************************************************************
731 * NtSetValueKey [NTDLL.@]
732 * ZwSetValueKey [NTDLL.@]
734 * NOTES
735 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
736 * NT does definitely care (aj)
738 NTSTATUS WINAPI NtSetValueKey( HANDLE hkey, const UNICODE_STRING *name, ULONG TitleIndex,
739 ULONG type, const void *data, ULONG count )
741 NTSTATUS ret;
743 TRACE( "(%p,%s,%ld,%p,%ld)\n", hkey, debugstr_us(name), type, data, count );
745 if (name->Length > MAX_NAME_LENGTH) return STATUS_BUFFER_OVERFLOW;
747 SERVER_START_REQ( set_key_value )
749 req->hkey = hkey;
750 req->type = type;
751 req->namelen = name->Length;
752 wine_server_add_data( req, name->Buffer, name->Length );
753 wine_server_add_data( req, data, count );
754 ret = wine_server_call( req );
756 SERVER_END_REQ;
757 return ret;
760 /******************************************************************************
761 * RtlpNtSetValueKey [NTDLL.@]
764 NTSTATUS WINAPI RtlpNtSetValueKey( HANDLE hkey, ULONG type, const void *data,
765 ULONG count )
767 UNICODE_STRING name;
769 name.Length = 0;
770 return NtSetValueKey( hkey, &name, 0, type, data, count );
773 /******************************************************************************
774 * NtUnloadKey [NTDLL.@]
775 * ZwUnloadKey [NTDLL.@]
777 NTSTATUS WINAPI NtUnloadKey(IN HANDLE KeyHandle)
779 NTSTATUS ret;
781 TRACE("(%p)\n", KeyHandle);
783 SERVER_START_REQ( unload_registry )
785 req->hkey = KeyHandle;
786 ret = wine_server_call(req);
788 SERVER_END_REQ;
790 return ret;
793 /******************************************************************************
794 * RtlFormatCurrentUserKeyPath [NTDLL.@]
797 NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
799 static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
800 HANDLE token;
801 NTSTATUS status;
803 status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
804 if (status == STATUS_NO_TOKEN)
805 status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
806 if (status == STATUS_SUCCESS)
808 char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
809 DWORD len = sizeof(buffer);
811 status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
812 if (status == STATUS_SUCCESS)
814 KeyPath->MaximumLength = 0;
815 status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
816 if (status == STATUS_BUFFER_OVERFLOW)
818 PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
819 sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
820 if (buf)
822 memcpy(buf, pathW, sizeof(pathW));
823 KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
824 KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
825 status = RtlConvertSidToUnicodeString(KeyPath,
826 ((TOKEN_USER *)buffer)->User.Sid, FALSE);
827 KeyPath->Buffer = (PWCHAR)buf;
828 KeyPath->Length += sizeof(pathW);
829 KeyPath->MaximumLength += sizeof(pathW);
831 else
832 status = STATUS_NO_MEMORY;
835 NtClose(token);
837 return status;
840 /******************************************************************************
841 * RtlOpenCurrentUser [NTDLL.@]
843 * NOTES
844 * If we return just HKEY_CURRENT_USER the advapi tries to find a remote
845 * registry (odd handle) and fails.
847 NTSTATUS WINAPI RtlOpenCurrentUser(
848 IN ACCESS_MASK DesiredAccess, /* [in] */
849 OUT PHANDLE KeyHandle) /* [out] handle of HKEY_CURRENT_USER */
851 OBJECT_ATTRIBUTES ObjectAttributes;
852 UNICODE_STRING ObjectName;
853 NTSTATUS ret;
855 TRACE("(0x%08lx, %p)\n",DesiredAccess, KeyHandle);
857 if ((ret = RtlFormatCurrentUserKeyPath(&ObjectName))) return ret;
858 InitializeObjectAttributes(&ObjectAttributes,&ObjectName,OBJ_CASE_INSENSITIVE,0, NULL);
859 ret = NtCreateKey(KeyHandle, DesiredAccess, &ObjectAttributes, 0, NULL, 0, NULL);
860 RtlFreeUnicodeString(&ObjectName);
861 return ret;
865 static NTSTATUS RTL_ReportRegistryValue(PKEY_VALUE_FULL_INFORMATION pInfo,
866 PRTL_QUERY_REGISTRY_TABLE pQuery, PVOID pContext, PVOID pEnvironment)
868 PUNICODE_STRING str;
869 UNICODE_STRING src, dst;
870 LONG *bin;
871 ULONG offset;
872 PWSTR wstr;
873 DWORD res;
874 NTSTATUS status = STATUS_SUCCESS;
875 ULONG len;
876 LPWSTR String;
877 INT count = 0;
879 if (pInfo == NULL)
881 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
882 return STATUS_INVALID_PARAMETER;
883 else
885 status = pQuery->QueryRoutine(pQuery->Name, pQuery->DefaultType, pQuery->DefaultData,
886 pQuery->DefaultLength, pContext, pQuery->EntryContext);
888 return status;
890 len = pInfo->DataLength;
892 if (pQuery->Flags & RTL_QUERY_REGISTRY_DIRECT)
894 str = (PUNICODE_STRING)pQuery->EntryContext;
896 switch(pInfo->Type)
898 case REG_EXPAND_SZ:
899 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
901 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
902 res = 0;
903 dst.MaximumLength = 0;
904 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
905 dst.Length = 0;
906 dst.MaximumLength = res;
907 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
908 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
909 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
910 dst.Length, pContext, pQuery->EntryContext);
911 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
914 case REG_SZ:
915 case REG_LINK:
916 if (str->Buffer == NULL)
917 RtlCreateUnicodeString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
918 else
919 RtlAppendUnicodeToString(str, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
920 break;
922 case REG_MULTI_SZ:
923 if (!(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND))
924 return STATUS_INVALID_PARAMETER;
926 if (str->Buffer == NULL)
928 str->Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
929 str->MaximumLength = len;
931 len = min(len, str->MaximumLength);
932 memcpy(str->Buffer, ((CHAR*)pInfo) + pInfo->DataOffset, len);
933 str->Length = len;
934 break;
936 default:
937 bin = (LONG*)pQuery->EntryContext;
938 if (pInfo->DataLength <= sizeof(ULONG))
939 memcpy(bin, ((CHAR*)pInfo) + pInfo->DataOffset,
940 pInfo->DataLength);
941 else
943 if (bin[0] <= sizeof(ULONG))
945 memcpy(&bin[1], ((CHAR*)pInfo) + pInfo->DataOffset,
946 min(-bin[0], pInfo->DataLength));
948 else
950 len = min(bin[0], pInfo->DataLength);
951 bin[1] = len;
952 bin[2] = pInfo->Type;
953 memcpy(&bin[3], ((CHAR*)pInfo) + pInfo->DataOffset, len);
956 break;
959 else
961 if((pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND) ||
962 (pInfo->Type != REG_EXPAND_SZ && pInfo->Type != REG_MULTI_SZ))
964 status = pQuery->QueryRoutine(pInfo->Name, pInfo->Type,
965 ((CHAR*)pInfo) + pInfo->DataOffset, pInfo->DataLength,
966 pContext, pQuery->EntryContext);
968 else if (pInfo->Type == REG_EXPAND_SZ)
970 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
971 res = 0;
972 dst.MaximumLength = 0;
973 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
974 dst.Length = 0;
975 dst.MaximumLength = res;
976 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
977 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
978 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
979 dst.Length, pContext, pQuery->EntryContext);
980 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
982 else /* REG_MULTI_SZ */
984 if(pQuery->Flags & RTL_QUERY_REGISTRY_NOEXPAND)
986 for (offset = 0; offset <= pInfo->DataLength; offset += len + sizeof(WCHAR))
988 wstr = (WCHAR*)(((CHAR*)pInfo) + offset);
989 len = strlenW(wstr) * sizeof(WCHAR);
990 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, wstr, len,
991 pContext, pQuery->EntryContext);
992 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
993 return status;
996 else
998 while(count<=pInfo->DataLength)
1000 String = (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset)+count;
1001 count+=strlenW(String)+1;
1002 RtlInitUnicodeString(&src, (WCHAR*)(((CHAR*)pInfo) + pInfo->DataOffset));
1003 res = 0;
1004 dst.MaximumLength = 0;
1005 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1006 dst.Length = 0;
1007 dst.MaximumLength = res;
1008 dst.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, res * sizeof(WCHAR));
1009 RtlExpandEnvironmentStrings_U(pEnvironment, &src, &dst, &res);
1010 status = pQuery->QueryRoutine(pQuery->Name, pInfo->Type, dst.Buffer,
1011 dst.Length, pContext, pQuery->EntryContext);
1012 RtlFreeHeap(GetProcessHeap(), 0, dst.Buffer);
1013 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1014 return status;
1019 return status;
1023 static NTSTATUS RTL_GetKeyHandle(ULONG RelativeTo, PCWSTR Path, PHANDLE handle)
1025 UNICODE_STRING KeyString;
1026 OBJECT_ATTRIBUTES regkey;
1027 PCWSTR base;
1028 INT len;
1029 NTSTATUS status;
1031 static const WCHAR empty[] = {0};
1032 static const WCHAR control[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e',
1033 '\\','S','y','s','t','e','m','\\','C','u','r','r','e','n','t',' ','C','o','n','t','r','o','l','S','e','t','\\',
1034 'C','o','n','t','r','o','l','\\',0};
1036 static const WCHAR devicemap[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1037 'H','a','r','d','w','a','r','e','\\','D','e','v','i','c','e','M','a','p','\\',0};
1039 static const WCHAR services[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1040 'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
1041 'S','e','r','v','i','c','e','s','\\',0};
1043 static const WCHAR user[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',
1044 'C','u','r','r','e','n','t','U','s','e','r','\\',0};
1046 static const WCHAR windows_nt[] = {'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',
1047 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1048 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',0};
1050 switch (RelativeTo & 0xff)
1052 case RTL_REGISTRY_ABSOLUTE:
1053 base = empty;
1054 break;
1056 case RTL_REGISTRY_CONTROL:
1057 base = control;
1058 break;
1060 case RTL_REGISTRY_DEVICEMAP:
1061 base = devicemap;
1062 break;
1064 case RTL_REGISTRY_SERVICES:
1065 base = services;
1066 break;
1068 case RTL_REGISTRY_USER:
1069 base = user;
1070 break;
1072 case RTL_REGISTRY_WINDOWS_NT:
1073 base = windows_nt;
1074 break;
1076 default:
1077 return STATUS_INVALID_PARAMETER;
1080 len = (strlenW(base) + strlenW(Path) + 1) * sizeof(WCHAR);
1081 KeyString.Buffer = RtlAllocateHeap(GetProcessHeap(), 0, len);
1082 if (KeyString.Buffer == NULL)
1083 return STATUS_NO_MEMORY;
1085 strcpyW(KeyString.Buffer, base);
1086 strcatW(KeyString.Buffer, Path);
1087 KeyString.Length = len - sizeof(WCHAR);
1088 KeyString.MaximumLength = len;
1089 InitializeObjectAttributes(&regkey, &KeyString, OBJ_CASE_INSENSITIVE, NULL, NULL);
1090 status = NtOpenKey(handle, KEY_ALL_ACCESS, &regkey);
1091 RtlFreeHeap(GetProcessHeap(), 0, KeyString.Buffer);
1092 return status;
1095 /*************************************************************************
1096 * RtlQueryRegistryValues [NTDLL.@]
1098 * Query multiple registry values with a signle call.
1100 * PARAMS
1101 * RelativeTo [I] Registry path that Path refers to
1102 * Path [I] Path to key
1103 * QueryTable [I] Table of key values to query
1104 * Context [I] Paremeter to pass to the application defined QueryRoutine function
1105 * Environment [I] Optional parameter to use when performing expantion
1107 * RETURNS
1108 * STATUS_SUCCESS or an appropriate NTSTATUS error code.
1110 NTSTATUS WINAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path,
1111 IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context,
1112 IN PVOID Environment OPTIONAL)
1114 UNICODE_STRING Value;
1115 HANDLE handle, topkey;
1116 PKEY_VALUE_FULL_INFORMATION pInfo = NULL;
1117 ULONG len, buflen = 0;
1118 NTSTATUS status=STATUS_SUCCESS, ret = STATUS_SUCCESS;
1119 INT i;
1121 TRACE("(%ld, %s, %p, %p, %p)\n", RelativeTo, debugstr_w(Path), QueryTable, Context, Environment);
1123 if(Path == NULL)
1124 return STATUS_INVALID_PARAMETER;
1126 /* get a valid handle */
1127 if (RelativeTo & RTL_REGISTRY_HANDLE)
1128 topkey = handle = (HANDLE)Path;
1129 else
1131 status = RTL_GetKeyHandle(RelativeTo, Path, &topkey);
1132 handle = topkey;
1134 if(status != STATUS_SUCCESS)
1135 return status;
1137 /* Process query table entries */
1138 for (; QueryTable->QueryRoutine != NULL || QueryTable->Name != NULL; ++QueryTable)
1140 if (QueryTable->Flags &
1141 (RTL_QUERY_REGISTRY_SUBKEY | RTL_QUERY_REGISTRY_TOPKEY))
1143 /* topkey must be kept open just in case we will reuse it later */
1144 if (handle != topkey)
1145 NtClose(handle);
1147 if (QueryTable->Flags & RTL_QUERY_REGISTRY_SUBKEY)
1149 handle = 0;
1150 status = RTL_GetKeyHandle((ULONG)QueryTable->Name, Path, &handle);
1151 if(status != STATUS_SUCCESS)
1153 ret = status;
1154 goto out;
1157 else
1158 handle = topkey;
1161 if (QueryTable->Flags & RTL_QUERY_REGISTRY_NOVALUE)
1163 QueryTable->QueryRoutine(QueryTable->Name, REG_NONE, NULL, 0,
1164 Context, QueryTable->EntryContext);
1165 continue;
1168 if (!handle)
1170 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1172 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1173 goto out;
1175 continue;
1178 if (QueryTable->Name == NULL)
1180 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT)
1182 ret = STATUS_INVALID_PARAMETER;
1183 goto out;
1186 /* Report all subkeys */
1187 for (i = 0;; ++i)
1189 status = NtEnumerateValueKey(handle, i,
1190 KeyValueFullInformation, pInfo, buflen, &len);
1191 if (status == STATUS_NO_MORE_ENTRIES)
1192 break;
1193 if (status == STATUS_BUFFER_OVERFLOW ||
1194 status == STATUS_BUFFER_TOO_SMALL)
1196 buflen = len;
1197 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1198 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1199 GetProcessHeap(), 0, buflen);
1200 NtEnumerateValueKey(handle, i, KeyValueFullInformation,
1201 pInfo, buflen, &len);
1204 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1205 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1207 ret = status;
1208 goto out;
1210 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1212 RtlInitUnicodeString(&Value, pInfo->Name);
1213 NtDeleteValueKey(handle, &Value);
1217 if (i == 0 && (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED))
1219 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1220 goto out;
1223 else
1225 RtlInitUnicodeString(&Value, QueryTable->Name);
1226 status = NtQueryValueKey(handle, &Value, KeyValueFullInformation,
1227 pInfo, buflen, &len);
1228 if (status == STATUS_BUFFER_OVERFLOW ||
1229 status == STATUS_BUFFER_TOO_SMALL)
1231 buflen = len;
1232 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1233 pInfo = (KEY_VALUE_FULL_INFORMATION*)RtlAllocateHeap(
1234 GetProcessHeap(), 0, buflen);
1235 status = NtQueryValueKey(handle, &Value,
1236 KeyValueFullInformation, pInfo, buflen, &len);
1238 if (status != STATUS_SUCCESS)
1240 if (QueryTable->Flags & RTL_QUERY_REGISTRY_REQUIRED)
1242 ret = STATUS_OBJECT_NAME_NOT_FOUND;
1243 goto out;
1245 status = RTL_ReportRegistryValue(NULL, QueryTable, Context, Environment);
1246 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1248 ret = status;
1249 goto out;
1252 else
1254 status = RTL_ReportRegistryValue(pInfo, QueryTable, Context, Environment);
1255 if(status != STATUS_SUCCESS && status != STATUS_BUFFER_TOO_SMALL)
1257 ret = status;
1258 goto out;
1260 if (QueryTable->Flags & RTL_QUERY_REGISTRY_DELETE)
1261 NtDeleteValueKey(handle, &Value);
1266 out:
1267 RtlFreeHeap(GetProcessHeap(), 0, pInfo);
1268 if (handle != topkey)
1269 NtClose(handle);
1270 NtClose(topkey);
1271 return ret;
1274 /*************************************************************************
1275 * RtlCheckRegistryKey [NTDLL.@]
1277 * Query multiple registry values with a signle call.
1279 * PARAMS
1280 * RelativeTo [I] Registry path that Path refers to
1281 * Path [I] Path to key
1283 * RETURNS
1284 * STATUS_SUCCESS if the specified key exists, or an NTSTATUS error code.
1286 NTSTATUS WINAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
1288 HANDLE handle;
1289 NTSTATUS status;
1291 TRACE("(%ld, %s)\n", RelativeTo, debugstr_w(Path));
1293 if((!RelativeTo) && Path == NULL)
1294 return STATUS_OBJECT_PATH_SYNTAX_BAD;
1295 if(RelativeTo & RTL_REGISTRY_HANDLE)
1296 return STATUS_SUCCESS;
1298 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1299 if (handle) NtClose(handle);
1300 if (status == STATUS_INVALID_HANDLE) status = STATUS_OBJECT_NAME_NOT_FOUND;
1301 return status;
1304 /*************************************************************************
1305 * RtlDeleteRegistryValue [NTDLL.@]
1307 * Query multiple registry values with a signle call.
1309 * PARAMS
1310 * RelativeTo [I] Registry path that Path refers to
1311 * Path [I] Path to key
1312 * ValueName [I] Name of the value to delete
1314 * RETURNS
1315 * STATUS_SUCCESS if the specified key is successfully deleted, or an NTSTATUS error code.
1317 NTSTATUS WINAPI RtlDeleteRegistryValue(IN ULONG RelativeTo, IN PCWSTR Path, IN PCWSTR ValueName)
1319 NTSTATUS status;
1320 HANDLE handle;
1321 UNICODE_STRING Value;
1323 TRACE("(%ld, %s, %s)\n", RelativeTo, debugstr_w(Path), debugstr_w(ValueName));
1325 RtlInitUnicodeString(&Value, ValueName);
1326 if(RelativeTo == RTL_REGISTRY_HANDLE)
1328 return NtDeleteValueKey((HANDLE)Path, &Value);
1330 status = RTL_GetKeyHandle(RelativeTo, Path, &handle);
1331 if (status) return status;
1332 status = NtDeleteValueKey(handle, &Value);
1333 NtClose(handle);
1334 return status;