2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
34 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
36 static HKEY hkey_main
;
39 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
40 static const char * sTestpath2
= "%FOO%\\subdir1";
41 static const DWORD ptr_size
= 8 * sizeof(void*);
43 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
44 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
45 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
46 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
47 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
48 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
49 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
50 static LONG (WINAPI
*pRegDeleteKeyValueA
)(HKEY
,LPCSTR
,LPCSTR
);
51 static LONG (WINAPI
*pRegSetKeyValueW
)(HKEY
,LPCWSTR
,LPCWSTR
,DWORD
,const void*,DWORD
);
53 static BOOL limited_user
;
56 /* Debugging functions from wine/libs/wine/debug.c */
58 /* allocate some tmp string space */
59 /* FIXME: this is not 100% thread-safe */
60 static char *get_temp_buffer( int size
)
62 static char *list
[32];
67 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
69 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
71 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
72 if (ret
) list
[idx
] = ret
;
76 static const char *wine_debugstr_an( const char *str
, int n
)
78 static const char hex
[16] = "0123456789abcdef";
82 if (!((ULONG_PTR
)str
>> 16))
84 if (!str
) return "(null)";
85 res
= get_temp_buffer( 6 );
86 sprintf( res
, "#%04x", LOWORD(str
) );
89 if (n
== -1) n
= strlen(str
);
91 size
= 10 + min( 300, n
* 4 );
92 dst
= res
= get_temp_buffer( size
);
94 while (n
-- > 0 && dst
<= res
+ size
- 9)
96 unsigned char c
= *str
++;
99 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
100 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
101 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
102 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
103 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
105 if (c
>= ' ' && c
<= 126)
111 *dst
++ = hex
[(c
>> 4) & 0x0f];
112 *dst
++ = hex
[c
& 0x0f];
127 #define ADVAPI32_GET_PROC(func) \
128 p ## func = (void*)GetProcAddress(hadvapi32, #func)
130 static void InitFunctionPtrs(void)
132 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
133 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
134 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
136 /* This function was introduced with Windows 2003 SP1 */
137 ADVAPI32_GET_PROC(RegGetValueA
);
138 ADVAPI32_GET_PROC(RegDeleteTreeA
);
139 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
140 ADVAPI32_GET_PROC(RegDeleteKeyValueA
);
141 ADVAPI32_GET_PROC(RegSetKeyValueW
);
143 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
144 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
145 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
146 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
149 /* delete key and all its subkeys */
150 static DWORD
delete_key( HKEY hkey
)
155 if ((ret
= RegOpenKeyExA( hkey
, "", 0, KEY_ENUMERATE_SUB_KEYS
, &hkey
))) return ret
;
156 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
159 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
161 ret
= delete_key( tmp
);
166 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
167 RegDeleteKeyA( hkey
, "" );
172 static void setup_main_key(void)
174 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
176 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
179 static void check_user_privs(void)
182 HKEY hkey
= (HKEY
)0xdeadbeef;
184 ret
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WRITE
, &hkey
);
185 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_ACCESS_DENIED
, "expected success or access denied, got %i\n", ret
);
186 if (ret
== ERROR_SUCCESS
)
188 ok(hkey
!= NULL
, "RegOpenKeyExA succeeded but returned NULL hkey\n");
193 ok(hkey
== NULL
, "RegOpenKeyExA failed but returned hkey %p\n", hkey
);
195 trace("running as limited user\n");
199 #define lok ok_(__FILE__, line)
200 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
201 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
204 DWORD ret
, type
, cbData
;
210 /* When successful RegQueryValueExA() leaves GLE as is,
211 * so we must reset it to detect unimplemented functions.
213 SetLastError(0xdeadbeef);
214 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
215 GLE
= GetLastError();
216 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
217 /* It is wrong for the Ansi version to not be implemented */
218 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
219 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
221 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
222 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
223 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
225 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
226 memset(value
, 0xbd, cbData
+1);
228 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
229 GLE
= GetLastError();
230 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
233 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
234 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
238 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
239 wine_debugstr_an((char*)value
, cbData
), cbData
,
240 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
241 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
243 HeapFree(GetProcessHeap(), 0, value
);
246 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
247 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
250 DWORD ret
, type
, cbData
;
255 /* When successful RegQueryValueExW() leaves GLE as is,
256 * so we must reset it to detect unimplemented functions.
258 SetLastError(0xdeadbeef);
259 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
260 GLE
= GetLastError();
261 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
262 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
264 win_skip("RegQueryValueExW() is not implemented\n");
268 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
269 lok(cbData
== full_byte_len
,
270 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
272 /* Give enough space to overflow by one WCHAR */
273 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
274 memset(value
, 0xbd, cbData
+2);
276 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
277 GLE
= GetLastError();
278 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
281 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
282 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
283 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
285 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
286 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
287 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
288 HeapFree(GetProcessHeap(), 0, value
);
291 static void test_set_value(void)
295 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
296 static const WCHAR name2W
[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
297 static const WCHAR emptyW
[] = {0};
298 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
299 static const WCHAR string2W
[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
300 static const WCHAR substring2W
[] = {'T','h','i','s',0};
302 static const char name1A
[] = "CleanSingleString";
303 static const char name2A
[] = "SomeIntraZeroedString";
304 static const char emptyA
[] = "";
305 static const char string1A
[] = "ThisNeverBreaks";
306 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
307 static const char substring2A
[] = "This";
311 /* Crashes on NT4, Windows 2000 and XP SP1 */
312 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
313 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
316 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
317 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
318 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
319 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
321 /* RegSetValueA ignores the size passed in */
322 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
323 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
324 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
325 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
327 /* stops at first null */
328 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
329 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
330 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
331 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
333 /* only REG_SZ is supported on NT*/
334 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
335 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
337 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
338 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
340 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
341 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
343 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
344 * Surprisingly enough we're supposed to get zero bytes out of it.
346 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
347 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
348 test_hkey_main_Value_A(name1A
, NULL
, 0);
349 test_hkey_main_Value_W(name1W
, NULL
, 0);
351 /* test RegSetValueExA with an empty string */
352 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
353 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
354 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
355 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
357 /* test RegSetValueExA with off-by-one size */
358 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
359 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
360 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
361 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
363 /* test RegSetValueExA with normal string */
364 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
365 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
366 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
367 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
369 /* test RegSetValueExA with intrazeroed string */
370 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
371 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
372 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
373 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
377 /* Crashes on NT4, Windows 2000 and XP SP1 */
378 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
379 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
381 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
382 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
385 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
386 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
387 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
388 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
390 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
391 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
392 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
393 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
395 /* RegSetValueW ignores the size passed in */
396 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
397 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
398 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
399 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
401 /* stops at first null */
402 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
403 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
404 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
405 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
407 /* only REG_SZ is supported */
408 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
409 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
410 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
411 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
412 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
413 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
415 /* test RegSetValueExW with off-by-one size */
416 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
417 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
418 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
419 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
421 /* test RegSetValueExW with normal string */
422 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
423 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
424 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
425 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
427 /* test RegSetValueExW with intrazeroed string */
428 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
429 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
430 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
431 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
433 /* test RegSetValueExW with data = 1 */
434 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
435 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
436 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
437 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
440 if (!pRegSetKeyValueW
)
441 win_skip("RegSetKeyValue() is not supported.\n");
444 static const WCHAR subkeyW
[] = {'s','u','b','k','e','y',0};
448 ret
= pRegSetKeyValueW(hkey_main
, NULL
, name1W
, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
449 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
450 test_hkey_main_Value_A(name1A
, string2A
, sizeof(string2A
));
451 test_hkey_main_Value_W(name1W
, string2W
, sizeof(string2W
));
453 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
454 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
456 ret
= RegOpenKeyExW(hkey_main
, subkeyW
, 0, KEY_QUERY_VALUE
, &subkey
);
457 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
459 ret
= RegQueryValueExW(subkey
, name1W
, 0, &type
, NULL
, &len
);
460 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
461 ok(len
== sizeof(string1W
), "got %d\n", len
);
462 ok(type
== REG_SZ
, "got type %d\n", type
);
464 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 0);
465 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
471 static void create_test_entries(void)
473 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
475 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
476 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
478 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
479 "RegSetValueExA failed\n");
480 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
481 "RegSetValueExA failed\n");
482 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
483 "RegSetValueExA failed\n");
484 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
485 "RegSetValueExA failed\n");
486 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
487 "RegSetValueExA failed\n");
488 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
489 "RegSetValueExA failed\n");
490 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
491 "RegSetValueExA failed\n");
494 static void test_enum_value(void)
498 char value
[20], data
[20];
499 WCHAR valueW
[20], dataW
[20];
500 DWORD val_count
, data_count
, type
;
501 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
502 static const WCHAR testW
[] = {'T','e','s','t',0};
503 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
505 /* create the working key for new 'Test' value */
506 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
507 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
509 /* check NULL data with zero length */
510 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
511 if (GetVersion() & 0x80000000)
512 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
514 ok( !res
, "RegSetValueExA returned %d\n", res
);
515 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
516 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
517 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
518 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
520 /* test reading the value and data without setting them */
524 strcpy( value
, "xxxxxxxxxx" );
525 strcpy( data
, "xxxxxxxxxx" );
526 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
527 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
528 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
529 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
530 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
531 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
532 ok( !strcmp( data
, "xxxxxxxxxx" ), "data is '%s' instead of xxxxxxxxxx\n", data
);
537 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
538 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
539 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
540 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
541 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
542 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
543 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
544 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
545 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data is not 'xxxxxxxxxx'\n" );
547 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
548 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
550 /* overflow both name and data */
554 strcpy( value
, "xxxxxxxxxx" );
555 strcpy( data
, "xxxxxxxxxx" );
556 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
557 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
558 ok( val_count
== 2, "val_count set to %d\n", val_count
);
559 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
560 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
561 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
562 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
568 strcpy( value
, "xxxxxxxxxx" );
569 strcpy( data
, "xxxxxxxxxx" );
570 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
571 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
572 ok( val_count
== 3, "val_count set to %d\n", val_count
);
573 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
574 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
575 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
576 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
577 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
578 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
579 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
581 /* overflow empty name */
585 strcpy( value
, "xxxxxxxxxx" );
586 strcpy( data
, "xxxxxxxxxx" );
587 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
588 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
589 ok( val_count
== 0, "val_count set to %d\n", val_count
);
590 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
591 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
592 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
593 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
594 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
595 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
601 strcpy( value
, "xxxxxxxxxx" );
602 strcpy( data
, "xxxxxxxxxx" );
603 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
604 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
605 ok( val_count
== 20, "val_count set to %d\n", val_count
);
606 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
607 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
608 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
609 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
615 strcpy( value
, "xxxxxxxxxx" );
616 strcpy( data
, "xxxxxxxxxx" );
617 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
618 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
619 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
620 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
621 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
622 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
623 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
627 SetLastError(0xdeadbeef);
628 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
629 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
631 win_skip("RegSetValueExW is not implemented\n");
634 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
636 /* overflow both name and data */
640 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
641 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
642 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
643 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
644 ok( val_count
== 2, "val_count set to %d\n", val_count
);
645 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
646 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
647 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
648 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
654 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
655 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
656 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
657 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
658 ok( val_count
== 3, "val_count set to %d\n", val_count
);
659 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
660 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
661 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
662 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
668 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
669 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
670 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
671 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
672 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
673 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
674 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
675 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
676 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
682 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
683 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
684 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
685 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
686 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
687 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
688 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
689 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
690 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
693 RegDeleteKeyA(test_key
, "");
694 RegCloseKey(test_key
);
697 static void test_query_value_ex(void)
704 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
705 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
706 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
707 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
711 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
712 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
713 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
715 size
= sizeof(buffer
);
716 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
717 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
718 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
721 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
722 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
725 static void test_get_value(void)
732 CHAR expanded
[] = "bar\\subdir1";
733 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
737 win_skip("RegGetValue not available on this platform\n");
741 /* Invalid parameter */
742 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
743 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
745 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
746 size
= type
= dw
= 0xdeadbeef;
747 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
748 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
749 ok(size
== 4, "size=%d\n", size
);
750 ok(type
== REG_DWORD
, "type=%d\n", type
);
751 ok(dw
== 0x12345678, "dw=%d\n", dw
);
753 /* Query by subkey-name */
754 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
755 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
757 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
758 size
= type
= dw
= 0xdeadbeef;
759 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
760 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
761 /* Although the function failed all values are retrieved */
762 ok(size
== 4, "size=%d\n", size
);
763 ok(type
== REG_DWORD
, "type=%d\n", type
);
764 ok(dw
== 0x12345678, "dw=%d\n", dw
);
766 /* Test RRF_ZEROONFAILURE */
767 type
= dw
= 0xdeadbeef; size
= 4;
768 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
769 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
770 /* Again all values are retrieved ... */
771 ok(size
== 4, "size=%d\n", size
);
772 ok(type
== REG_DWORD
, "type=%d\n", type
);
773 /* ... except the buffer, which is zeroed out */
774 ok(dw
== 0, "dw=%d\n", dw
);
776 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
777 type
= size
= 0xbadbeef;
778 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
779 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
780 ok(size
== 4, "size=%d\n", size
);
781 ok(type
== REG_DWORD
, "type=%d\n", type
);
783 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
784 size
= type
= dw
= 0xdeadbeef;
785 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
786 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
787 ok(size
== 4, "size=%d\n", size
);
788 ok(type
== REG_DWORD
, "type=%d\n", type
);
789 ok(dw
== 0x12345678, "dw=%d\n", dw
);
791 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
792 size
= type
= dw
= 0xdeadbeef;
793 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
794 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
795 ok(size
== 4, "size=%d\n", size
);
796 ok(type
== REG_BINARY
, "type=%d\n", type
);
797 ok(dw
== 0x12345678, "dw=%d\n", dw
);
799 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
800 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
801 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
802 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
803 ok(size
== 8, "size=%d\n", size
);
804 ok(type
== REG_BINARY
, "type=%d\n", type
);
805 ok(qw
[0] == 0x12345678 &&
806 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
808 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
809 type
= dw
= 0xdeadbeef; size
= 4;
810 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
811 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
812 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
813 ok(size
== 8, "size=%d\n", size
);
815 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
816 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
817 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
818 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
819 ok(size
== 8, "size=%d\n", size
);
820 ok(type
== REG_BINARY
, "type=%d\n", type
);
821 ok(qw
[0] == 0x12345678 &&
822 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
824 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
825 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
826 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
827 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
828 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
829 ok(type
== REG_SZ
, "type=%d\n", type
);
830 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
832 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
833 type
= 0xdeadbeef; size
= 0;
834 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
835 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
836 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
837 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
838 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
839 ok(type
== REG_SZ
, "type=%d\n", type
);
841 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
842 strcpy(buf
, sTestpath1
);
845 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
846 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
847 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
849 size
== 1, /* win2k3 */
851 ok(type
== REG_SZ
, "type=%d\n", type
);
852 ok(!strcmp(sTestpath1
, buf
) ||
854 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
856 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
857 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
858 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
859 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
860 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
861 ok(type
== REG_SZ
, "type=%d\n", type
);
862 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
864 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
866 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
867 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
868 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
869 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
870 (size
== strlen(sTestpath2
)+1),
871 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
873 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
874 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
875 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
876 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
877 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
878 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
879 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
880 ok(type
== REG_SZ
, "type=%d\n", type
);
881 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
883 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
884 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
885 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
886 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
887 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
888 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
889 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
890 ok(type
== REG_SZ
, "type=%d\n", type
);
891 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
893 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
894 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
895 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
896 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
897 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
898 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
899 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
901 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
903 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
904 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
905 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
906 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
907 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
909 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
910 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
911 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
913 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
914 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
915 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
916 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
918 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
919 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
920 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
921 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
922 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
923 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
924 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
925 ok(type
== REG_SZ
, "type=%d\n", type
);
926 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
929 static void test_reg_open_key(void)
932 HKEY hkResult
= NULL
;
933 HKEY hkPreserve
= NULL
;
934 HKEY hkRoot64
= NULL
;
935 HKEY hkRoot32
= NULL
;
937 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
939 EXPLICIT_ACCESSA access
;
941 SECURITY_DESCRIPTOR
*sd
;
943 /* successful open */
944 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
945 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
946 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
947 hkPreserve
= hkResult
;
949 /* open same key twice */
950 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
951 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
952 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
953 ok(hkResult
!= NULL
, "hkResult != NULL\n");
954 RegCloseKey(hkResult
);
956 /* trailing slashes */
957 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test\\\\", &hkResult
);
958 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
959 RegCloseKey(hkResult
);
961 /* open nonexistent key
962 * check that hkResult is set to NULL
964 hkResult
= hkPreserve
;
965 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
966 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
967 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
969 /* open the same nonexistent key again to make sure the key wasn't created */
970 hkResult
= hkPreserve
;
971 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
972 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
973 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
975 /* send in NULL lpSubKey
976 * check that hkResult receives the value of hKey
978 hkResult
= hkPreserve
;
979 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
980 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
981 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
983 /* send empty-string in lpSubKey */
984 hkResult
= hkPreserve
;
985 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
986 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
987 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
989 /* send in NULL lpSubKey and NULL hKey
990 * hkResult is set to NULL
992 hkResult
= hkPreserve
;
993 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
994 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
995 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
997 /* only send NULL hKey
998 * the value of hkResult remains unchanged
1000 hkResult
= hkPreserve
;
1001 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
1002 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1003 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1004 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
1005 RegCloseKey(hkResult
);
1007 /* send in NULL hkResult */
1008 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
1009 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1011 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
1012 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1014 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
1015 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1017 /* beginning backslash character */
1018 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
1019 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
1020 broken(ret
== ERROR_SUCCESS
), /* wow64 */
1021 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1022 if (!ret
) RegCloseKey(hkResult
);
1025 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
1026 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
1027 ret
== ERROR_BAD_PATHNAME
, /* NT */
1028 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1029 RegCloseKey(hkResult
);
1033 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
1034 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1035 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1036 RegCloseKey(hkResult
);
1039 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
1040 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1041 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1042 RegCloseKey(hkResult
);
1044 /* check special HKEYs on 64bit
1045 * only the lower 4 bytes of the supplied key are used
1049 /* HKEY_CURRENT_USER */
1050 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
1051 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1052 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1053 RegCloseKey(hkResult
);
1055 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
1056 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1057 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1058 RegCloseKey(hkResult
);
1060 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1061 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1062 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1063 RegCloseKey(hkResult
);
1065 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
1066 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1067 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1068 RegCloseKey(hkResult
);
1070 /* HKEY_LOCAL_MACHINE */
1071 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1072 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1073 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1074 RegCloseKey(hkResult
);
1077 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1078 * the registry access check is performed correctly. Redirection isn't
1079 * being tested, so the tests don't care about whether the process is
1080 * running under WOW64. */
1081 if (!pIsWow64Process
)
1083 win_skip("WOW64 flags are not recognized\n");
1087 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1088 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1090 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1091 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1093 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1094 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1096 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1097 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1099 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1100 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1102 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1103 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1105 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1106 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1108 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1110 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1111 access
.grfAccessMode
= SET_ACCESS
;
1112 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1113 access
.Trustee
.pMultipleTrustee
= NULL
;
1114 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1115 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1116 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1117 access
.Trustee
.ptstrName
= (char *)world_sid
;
1119 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1120 ok(ret
== ERROR_SUCCESS
,
1121 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1123 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1124 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1126 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1128 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1130 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1134 skip("not enough privileges to modify HKLM\n");
1140 error
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1141 ok(error
== ERROR_SUCCESS
,
1142 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1144 error
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1145 ok(error
== ERROR_SUCCESS
,
1146 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1149 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1150 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1151 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1152 RegCloseKey(hkResult
);
1155 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1156 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1157 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1158 RegCloseKey(hkResult
);
1161 HeapFree(GetProcessHeap(), 0, sd
);
1164 RegDeleteKeyA(hkRoot64
, "");
1165 RegCloseKey(hkRoot64
);
1166 RegDeleteKeyA(hkRoot32
, "");
1167 RegCloseKey(hkRoot32
);
1170 static void test_reg_create_key(void)
1174 HKEY hkRoot64
= NULL
;
1175 HKEY hkRoot32
= NULL
;
1178 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1180 EXPLICIT_ACCESSA access
;
1182 SECURITY_DESCRIPTOR
*sd
;
1184 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1185 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1186 /* should succeed: all versions of Windows ignore the access rights
1187 * to the parent handle */
1188 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1189 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1192 RegDeleteKeyA(hkey2
, "");
1193 RegDeleteKeyA(hkey1
, "");
1197 /* test creation of volatile keys */
1198 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1199 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1200 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1201 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1202 if (!ret
) RegCloseKey( hkey2
);
1203 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1204 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1206 /* should succeed if the key already exists */
1207 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1208 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1211 RegDeleteKeyA(hkey2
, "");
1212 RegDeleteKeyA(hkey1
, "");
1216 /* beginning backslash character */
1217 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1218 if (!(GetVersion() & 0x80000000))
1219 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1221 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1222 RegDeleteKeyA(hkey1
, "");
1226 /* trailing backslash characters */
1227 ret
= RegCreateKeyExA(hkey_main
, "Subkey4\\\\", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1228 ok(ret
== ERROR_SUCCESS
, "RegCreateKeyExA failed with error %d\n", ret
);
1229 RegDeleteKeyA(hkey1
, "");
1232 /* WOW64 flags - open an existing key */
1234 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1235 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1236 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1240 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1241 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1242 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1245 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1246 * the registry access check is performed correctly. Redirection isn't
1247 * being tested, so the tests don't care about whether the process is
1248 * running under WOW64. */
1249 if (!pIsWow64Process
)
1251 win_skip("WOW64 flags are not recognized\n");
1255 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1256 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1258 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1259 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1261 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1262 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1264 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1265 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1267 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1268 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1270 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1271 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1273 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1274 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1276 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1278 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1279 access
.grfAccessMode
= SET_ACCESS
;
1280 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1281 access
.Trustee
.pMultipleTrustee
= NULL
;
1282 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1283 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1284 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1285 access
.Trustee
.ptstrName
= (char *)world_sid
;
1287 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1288 ok(dwRet
== ERROR_SUCCESS
,
1289 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1291 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1292 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1294 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1296 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1298 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1302 skip("not enough privileges to modify HKLM\n");
1306 ret
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1307 ok(ret
== ERROR_SUCCESS
,
1308 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1310 ret
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1311 ok(ret
== ERROR_SUCCESS
,
1312 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1315 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1316 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1317 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1318 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1322 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1323 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1324 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1325 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1329 HeapFree(GetProcessHeap(), 0, sd
);
1332 RegDeleteKeyA(hkRoot64
, "");
1333 RegCloseKey(hkRoot64
);
1334 RegDeleteKeyA(hkRoot32
, "");
1335 RegCloseKey(hkRoot32
);
1338 static void test_reg_close_key(void)
1343 /* successfully close key
1344 * hkHandle remains changed after call to RegCloseKey
1346 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1347 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1348 ret
= RegCloseKey(hkHandle
);
1349 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1351 /* try to close the key twice */
1352 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1353 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1354 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1356 /* try to close a NULL handle */
1357 ret
= RegCloseKey(NULL
);
1358 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1359 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1361 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1362 * win98 doesn't give a new handle when the same key is opened.
1363 * Not re-opening will make some next tests fail.
1365 if (hkey_main
== hkHandle
)
1367 trace("The main handle is most likely closed, so re-opening\n");
1368 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1372 static void test_reg_delete_key(void)
1377 ret
= RegDeleteKeyA(hkey_main
, NULL
);
1379 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1380 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1381 * Not re-creating will make some next tests fail.
1383 if (ret
== ERROR_SUCCESS
)
1385 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1386 " re-creating the main key\n");
1390 ok(ret
== ERROR_INVALID_PARAMETER
||
1391 ret
== ERROR_ACCESS_DENIED
||
1392 ret
== ERROR_BADKEY
, /* Win95 */
1395 ret
= RegCreateKeyA(hkey_main
, "deleteme", &key
);
1396 ok(ret
== ERROR_SUCCESS
, "Could not create key, got %d\n", ret
);
1397 ret
= RegDeleteKeyA(key
, "");
1398 ok(ret
== ERROR_SUCCESS
, "RegDeleteKeyA failed, got %d\n", ret
);
1400 ret
= RegOpenKeyA(hkey_main
, "deleteme", &key
);
1401 ok(ret
== ERROR_FILE_NOT_FOUND
, "Key was not deleted, got %d\n", ret
);
1405 static void test_reg_save_key(void)
1409 ret
= RegSaveKeyA(hkey_main
, "saved_key", NULL
);
1410 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1413 static void test_reg_load_key(void)
1418 ret
= RegLoadKeyA(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1419 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1421 ret
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1422 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1424 RegCloseKey(hkHandle
);
1427 static void test_reg_unload_key(void)
1431 ret
= RegUnLoadKeyA(HKEY_LOCAL_MACHINE
, "Test");
1432 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1434 DeleteFileA("saved_key");
1435 DeleteFileA("saved_key.LOG");
1438 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1440 TOKEN_PRIVILEGES tp
;
1444 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1447 if(!LookupPrivilegeValueA(NULL
, privilege
, &luid
))
1449 CloseHandle(hToken
);
1453 tp
.PrivilegeCount
= 1;
1454 tp
.Privileges
[0].Luid
= luid
;
1457 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1459 tp
.Privileges
[0].Attributes
= 0;
1461 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1462 if (GetLastError() != ERROR_SUCCESS
)
1464 CloseHandle(hToken
);
1468 CloseHandle(hToken
);
1472 /* tests that show that RegConnectRegistry and
1473 OpenSCManager accept computer names without the
1474 \\ prefix (what MSDN says). */
1475 static void test_regconnectregistry( void)
1477 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1478 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1479 DWORD len
= sizeof(compName
) ;
1485 SetLastError(0xdeadbeef);
1486 ret
= GetComputerNameA(compName
, &len
);
1487 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1490 lstrcpyA(netwName
, "\\\\");
1491 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1493 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1495 retl
== ERROR_DLL_INIT_FAILED
||
1496 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1497 "RegConnectRegistryA failed err = %d\n", retl
);
1498 if( !retl
) RegCloseKey( hkey
);
1500 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1502 retl
== ERROR_DLL_INIT_FAILED
||
1503 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1504 "RegConnectRegistryA failed err = %d\n", retl
);
1505 if( !retl
) RegCloseKey( hkey
);
1507 SetLastError(0xdeadbeef);
1508 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1509 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1511 win_skip("OpenSCManagerA is not implemented\n");
1515 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1516 CloseServiceHandle( schnd
);
1518 SetLastError(0xdeadbeef);
1519 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1520 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1521 CloseServiceHandle( schnd
);
1525 static void test_reg_query_value(void)
1532 static const WCHAR expected
[] = {'d','a','t','a',0};
1534 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1535 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1537 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1538 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1540 /* try an invalid hkey */
1541 SetLastError(0xdeadbeef);
1543 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1544 ok(ret
== ERROR_INVALID_HANDLE
||
1545 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1546 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1547 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1548 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1550 /* try a NULL hkey */
1551 SetLastError(0xdeadbeef);
1553 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1554 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1555 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1556 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1558 /* try a NULL value */
1560 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1561 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1562 ok(size
== 5, "Expected 5, got %d\n", size
);
1564 /* try a NULL size */
1565 SetLastError(0xdeadbeef);
1567 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1568 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1569 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1570 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1572 /* try a NULL value and size */
1573 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1574 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1576 /* try a size too small */
1577 SetLastError(0xdeadbeef);
1580 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1581 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1582 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1583 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1584 ok(size
== 5, "Expected 5, got %d\n", size
);
1586 /* successfully read the value using 'subkey' */
1588 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1589 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1590 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1591 ok(size
== 5, "Expected 5, got %d\n", size
);
1593 /* successfully read the value using the subkey key */
1595 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1596 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1597 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1598 ok(size
== 5, "Expected 5, got %d\n", size
);
1600 /* unicode - try size too small */
1601 SetLastError(0xdeadbeef);
1604 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1605 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1607 win_skip("RegQueryValueW is not implemented\n");
1610 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1611 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1612 ok(!valW
[0], "Expected valW to be untouched\n");
1613 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1615 /* unicode - try size in WCHARS */
1616 SetLastError(0xdeadbeef);
1617 size
= sizeof(valW
) / sizeof(WCHAR
);
1618 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1619 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1620 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1621 ok(!valW
[0], "Expected valW to be untouched\n");
1622 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1624 /* unicode - successfully read the value */
1625 size
= sizeof(valW
);
1626 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1627 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1628 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1629 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1631 /* unicode - set the value without a NULL terminator */
1632 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1633 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1635 /* unicode - read the unterminated value, value is terminated for us */
1636 memset(valW
, 'a', sizeof(valW
));
1637 size
= sizeof(valW
);
1638 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1639 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1640 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1641 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1644 RegDeleteKeyA(subkey
, "");
1645 RegCloseKey(subkey
);
1648 static void test_string_termination(void)
1652 static const char string
[] = "FullString";
1655 DWORD insize
, outsize
, nsize
;
1657 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1658 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1660 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1661 insize
=sizeof(string
)-1;
1662 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1663 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1665 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1666 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1668 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1669 insize
=sizeof(string
)-2;
1670 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1671 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1673 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1674 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1675 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1677 /* RegQueryValueExA may return a string with no trailing '\0' */
1679 memset(buffer
, 0xbd, sizeof(buffer
));
1680 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1681 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1682 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1683 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1684 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1685 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1687 /* RegQueryValueExA adds a trailing '\0' if there is room */
1689 memset(buffer
, 0xbd, sizeof(buffer
));
1690 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1691 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1692 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1693 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1694 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1695 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1697 /* RegEnumValueA may return a string with no trailing '\0' */
1699 memset(buffer
, 0xbd, sizeof(buffer
));
1701 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1702 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1703 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1704 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1705 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1706 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1707 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1709 /* RegEnumValueA adds a trailing '\0' if there is room */
1711 memset(buffer
, 0xbd, sizeof(buffer
));
1713 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1714 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1715 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1716 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1717 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1718 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1719 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1721 RegDeleteKeyA(subkey
, "");
1722 RegCloseKey(subkey
);
1725 static void test_reg_delete_tree(void)
1727 CHAR buffer
[MAX_PATH
];
1728 HKEY subkey
, subkey2
;
1731 if(!pRegDeleteTreeA
) {
1732 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1736 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1737 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1738 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1739 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1740 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1741 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1742 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1743 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1744 ret
= RegCloseKey(subkey2
);
1745 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1747 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1748 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1749 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1750 "subkey2 was not deleted\n");
1752 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1753 "Default value of subkey not longer present\n");
1755 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1756 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1757 ret
= RegCloseKey(subkey2
);
1758 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1759 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1760 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1761 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1762 "subkey2 was not deleted\n");
1763 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1764 "Default value of subkey not longer present\n");
1766 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1767 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1768 ret
= RegCloseKey(subkey2
);
1769 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1770 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1771 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1772 ret
= RegCloseKey(subkey2
);
1773 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1774 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1775 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1776 ret
= pRegDeleteTreeA(subkey
, NULL
);
1777 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1778 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1779 "subkey was deleted\n");
1780 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1781 "subkey2 was not deleted\n");
1782 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1783 "subkey3 was not deleted\n");
1785 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1786 ok(ret
== ERROR_SUCCESS
,
1787 "Default value of subkey is not present\n");
1788 ok(!buffer
[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1790 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1791 "Value is still present\n");
1793 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1794 ok(ret
== ERROR_FILE_NOT_FOUND
,
1795 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1798 static void test_rw_order(void)
1802 static const char keyname
[] = "test_rw_order";
1804 DWORD values
, value_len
, value_name_max_len
;
1807 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1808 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1809 if(ret
!= ERROR_SUCCESS
) {
1810 skip("Couldn't create key. Skipping.\n");
1814 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1815 "RegSetValueExA for value \"A\" failed\n");
1816 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1817 "RegSetValueExA for value \"C\" failed\n");
1818 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1819 "RegSetValueExA for value \"D\" failed\n");
1820 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1821 "RegSetValueExA for value \"B\" failed\n");
1823 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1824 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1825 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1827 /* Value enumeration preserves RegSetValueEx call order */
1829 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1830 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1832 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1833 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1835 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1836 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1838 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1839 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1841 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1844 static void test_symlinks(void)
1846 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1847 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1849 UNICODE_STRING target_str
;
1853 DWORD target_len
, type
, len
, dw
, err
;
1855 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1857 win_skip( "Can't perform symlink tests\n" );
1861 pRtlFormatCurrentUserKeyPath( &target_str
);
1863 target_len
= target_str
.Length
+ sizeof(targetW
);
1864 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1865 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1866 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1868 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1869 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1870 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1872 /* REG_SZ is not allowed */
1873 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1874 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1875 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1876 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1877 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1878 /* other values are not allowed */
1879 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1880 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1882 /* try opening the target through the link */
1884 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1885 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1887 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1888 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1891 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1892 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1895 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1896 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1898 len
= sizeof(buffer
);
1899 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1900 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1901 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1903 len
= sizeof(buffer
);
1904 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1905 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1907 /* REG_LINK can be created in non-link keys */
1908 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1909 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1910 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1911 len
= sizeof(buffer
);
1912 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1913 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1914 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1915 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1916 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1920 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1921 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1923 len
= sizeof(buffer
);
1924 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1925 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1926 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1928 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1929 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1932 /* now open the symlink itself */
1934 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1935 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1936 len
= sizeof(buffer
);
1937 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1938 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1939 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1942 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1943 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1944 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1945 len
= sizeof(buffer
);
1946 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1947 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1948 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1951 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1952 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1953 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1955 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1956 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1957 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1959 err
= RegDeleteKeyA( hkey_main
, "target" );
1960 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1962 err
= RegDeleteKeyA( hkey_main
, "link" );
1963 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1965 status
= pNtDeleteKey( link
);
1966 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1967 RegCloseKey( link
);
1969 HeapFree( GetProcessHeap(), 0, target
);
1970 pRtlFreeUnicodeString( &target_str
);
1973 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1976 DWORD err
, type
, dw
, len
= sizeof(dw
);
1978 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1979 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1980 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1982 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1983 if (err
== ERROR_FILE_NOT_FOUND
)
1986 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1991 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1993 DWORD dw
= get_key_value( root
, name
, flags
);
1994 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1996 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1998 static void test_redirection(void)
2000 DWORD err
, type
, dw
, len
;
2001 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
2002 BOOL is_vista
= FALSE
;
2003 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
2008 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
2010 skip( "Not on Wow64, no redirection\n" );
2015 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2016 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
2017 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2019 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2020 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
2021 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2023 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2024 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
2025 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2027 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2028 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
2029 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2032 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2033 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2036 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2037 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2041 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2042 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2043 ok( dw
== 32, "wrong value %u\n", dw
);
2047 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2048 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2049 ok( dw
== 64, "wrong value %u\n", dw
);
2051 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2052 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2053 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2057 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2058 /* the new (and simpler) Win7 mechanism doesn't */
2059 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2061 trace( "using Vista-style Wow6432Node handling\n" );
2064 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2065 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2066 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2067 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2068 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2069 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2073 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
2075 trace( "using Vista-style Wow6432Node handling\n" );
2078 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2079 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2085 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2086 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2087 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2088 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2089 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2090 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2091 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2092 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2093 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
2094 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
2095 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2098 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2099 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2100 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2101 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2102 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2103 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2104 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2105 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2106 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2111 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2112 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2113 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2114 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2115 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2116 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
);
2117 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2118 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2121 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2122 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2123 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2124 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2125 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2126 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
);
2127 todo_wine
ok( dw
== 32 || broken(dw
== 64) /* vista */, "wrong value %u\n", dw
);
2128 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
);
2129 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2133 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
2134 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2137 /* KEY_WOW64 flags have no effect on 64-bit */
2138 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2139 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2140 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2141 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2145 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2146 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2147 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2148 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2151 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2152 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2153 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2154 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2155 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2156 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2161 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2162 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2163 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2164 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2165 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2166 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2167 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2170 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2171 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2172 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2173 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2174 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2175 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2179 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2180 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2181 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2182 check_key_value( key
, "Winetest", 0, 32 );
2183 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2184 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2189 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2190 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2191 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2192 dw
= get_key_value( key
, "Winetest", 0 );
2193 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2194 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2195 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2198 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2199 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2200 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2201 check_key_value( key
, "Winetest", 0, 32 );
2202 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2203 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2207 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2208 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2209 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2210 check_key_value( key
, "Winetest", 0, ptr_size
);
2211 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2212 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2213 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2214 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2219 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2220 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2221 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2222 dw
= get_key_value( key
, "Winetest", 0 );
2223 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2224 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2225 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2226 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2229 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2230 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2231 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2232 check_key_value( key
, "Winetest", 0, 32 );
2233 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2234 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2238 if (pRegDeleteKeyExA
)
2240 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2241 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2242 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2243 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2244 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2245 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2249 err
= RegDeleteKeyA( key32
, "" );
2250 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2251 err
= RegDeleteKeyA( key64
, "" );
2252 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2253 RegDeleteKeyA( key64
, "" );
2254 RegDeleteKeyA( root64
, "" );
2256 RegCloseKey( key32
);
2257 RegCloseKey( key64
);
2258 RegCloseKey( root32
);
2259 RegCloseKey( root64
);
2261 /* open key in native bit mode */
2262 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2263 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2265 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2267 /* write subkey in opposite bit mode */
2268 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2269 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2271 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2273 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2274 if(err
!= ERROR_SUCCESS
){
2275 win_skip("Can't write to registry\n");
2276 RegCloseKey(op_key
);
2277 RegCloseKey(native
);
2282 /* verify subkey is not present in native mode */
2283 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2284 ok(err
== ERROR_FILE_NOT_FOUND
||
2285 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2288 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2289 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2291 RegCloseKey(op_key
);
2292 RegCloseKey(native
);
2295 static void test_classesroot(void)
2297 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2299 DWORD type
= REG_SZ
;
2300 static CHAR buffer
[8];
2303 /* create a key in the user's classes */
2304 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2307 RegCloseKey( hkey
);
2309 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2310 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2311 if (res
== ERROR_ACCESS_DENIED
)
2313 skip("not enough privileges to add a user class\n");
2316 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2318 /* try to open that key in hkcr */
2319 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2320 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2321 todo_wine
ok(res
== ERROR_SUCCESS
||
2322 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2323 "test key not found in hkcr: %d\n", res
);
2326 skip("HKCR key merging not supported\n");
2328 RegCloseKey( hkey
);
2332 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2334 /* set a value in user's classes */
2335 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2336 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2338 /* try to find the value in hkcr */
2339 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2340 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2341 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2343 /* modify the value in hkcr */
2344 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2345 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2347 /* check if the value is also modified in user's classes */
2348 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2349 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2350 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2352 /* set a value in hkcr */
2353 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2354 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2356 /* try to find the value in user's classes */
2357 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2358 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2359 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2361 /* modify the value in user's classes */
2362 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2363 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2365 /* check if the value is also modified in hkcr */
2366 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2367 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2368 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2373 RegCloseKey( hkey
);
2374 RegCloseKey( hkcr
);
2376 /* create a key in the hklm classes */
2377 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2380 RegCloseKey( hklm
);
2382 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2383 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2384 if (res
== ERROR_ACCESS_DENIED
)
2386 skip("not enough privileges to add a system class\n");
2389 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2391 /* try to open that key in hkcr */
2392 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2393 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2394 ok(res
== ERROR_SUCCESS
,
2395 "test key not found in hkcr: %d\n", res
);
2396 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2400 RegCloseKey( hklm
);
2404 /* set a value in hklm classes */
2405 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2406 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2408 /* try to find the value in hkcr */
2409 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2410 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2411 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2413 /* modify the value in hkcr */
2414 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2415 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2417 /* check that the value is modified in hklm classes */
2418 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2419 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2420 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2422 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2423 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2424 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2426 /* try to open that key in hkcr */
2427 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2428 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2429 ok(res
== ERROR_SUCCESS
,
2430 "test key not found in hkcr: %d\n", res
);
2431 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2433 /* set a value in user's classes */
2434 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2435 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2437 /* try to find the value in hkcr */
2438 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2439 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2440 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2442 /* modify the value in hklm */
2443 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2444 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2446 /* check that the value is not overwritten in hkcr or user's classes */
2447 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2448 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2449 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2450 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2451 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2452 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2454 /* modify the value in hkcr */
2455 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2456 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2458 /* check that the value is overwritten in hklm and user's classes */
2459 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2460 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2461 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2462 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2463 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2464 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2466 /* create a subkey in hklm */
2467 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2468 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2469 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2470 /* try to open that subkey in hkcr */
2471 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2472 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2473 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2475 /* set a value in hklm classes */
2476 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2477 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2479 /* try to find the value in hkcr */
2480 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2481 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2482 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2484 /* modify the value in hkcr */
2485 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2486 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2488 /* check that the value is modified in hklm classes */
2489 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2490 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2491 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2493 /* create a subkey in user's classes */
2494 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2495 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2496 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2498 /* set a value in user's classes */
2499 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2500 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2502 /* try to find the value in hkcr */
2503 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2504 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2505 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2507 /* modify the value in hklm */
2508 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2509 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2511 /* check that the value is not overwritten in hkcr or user's classes */
2512 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2513 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2514 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2515 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2516 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2517 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2519 /* modify the value in hkcr */
2520 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2521 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2523 /* check that the value is not overwritten in hklm, but in user's classes */
2524 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2525 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2526 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2527 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2528 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2529 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2531 /* new subkey in hkcr */
2532 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2533 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2534 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2535 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2536 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2538 /* try to open that new subkey in user's classes and hklm */
2539 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2540 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2542 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2543 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2544 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2546 /* check that the value is present in hklm */
2547 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2548 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2549 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2552 RegCloseKey( hkeysub1
);
2553 RegCloseKey( hklmsub1
);
2555 /* delete subkey1 from hkcr (should point at user's classes) */
2556 res
= RegDeleteKeyA(hkcr
, "subkey1");
2557 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2559 /* confirm key was removed in hkey but not hklm */
2560 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2561 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2562 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2563 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2564 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2566 /* delete subkey1 from hkcr again (which should now point at hklm) */
2567 res
= RegDeleteKeyA(hkcr
, "subkey1");
2568 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2570 /* confirm hkey was removed in hklm */
2571 RegCloseKey( hklmsub1
);
2572 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2573 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2579 delete_key( hkeysub1
);
2580 delete_key( hklmsub1
);
2581 delete_key( hkcrsub1
);
2582 delete_key( hklmsub2
);
2583 delete_key( hkcrsub2
);
2584 RegCloseKey( hkey
);
2585 RegCloseKey( hklm
);
2586 RegCloseKey( hkcr
);
2587 RegCloseKey( hkeysub1
);
2588 RegCloseKey( hklmsub1
);
2589 RegCloseKey( hkcrsub1
);
2590 RegCloseKey( hklmsub2
);
2591 RegCloseKey( hkcrsub2
);
2594 static void test_classesroot_enum(void)
2596 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2598 static CHAR buffer
[2];
2601 /* prepare initial testing env in HKCU */
2602 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2605 RegCloseKey( hkcu
);
2607 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2608 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2610 if (res
!= ERROR_SUCCESS
)
2612 skip("failed to add a user class\n");
2616 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2617 todo_wine
ok(res
== ERROR_SUCCESS
||
2618 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2619 "test key not found in hkcr: %d\n", res
);
2622 skip("HKCR key merging not supported\n");
2624 RegCloseKey( hkcu
);
2628 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2629 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2630 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2631 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2632 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2633 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2634 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2635 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2637 /* test on values in HKCU */
2638 size
= sizeof(buffer
);
2639 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2640 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2641 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2642 size
= sizeof(buffer
);
2643 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2644 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2645 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2646 size
= sizeof(buffer
);
2647 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2648 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2650 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2651 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2652 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2653 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2654 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2655 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2656 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2657 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2659 /* prepare test env in HKLM */
2660 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2663 RegCloseKey( hklm
);
2666 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2667 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2669 if (res
== ERROR_ACCESS_DENIED
)
2671 RegCloseKey( hkcusub
[0] );
2672 RegCloseKey( hkcusub
[1] );
2674 RegCloseKey( hkcu
);
2675 RegCloseKey( hkcr
);
2676 skip("not enough privileges to add a system class\n");
2680 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2681 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2682 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2683 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2684 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2685 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2686 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2687 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2689 /* test on values/keys in both HKCU and HKLM */
2690 size
= sizeof(buffer
);
2691 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2692 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2693 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2694 size
= sizeof(buffer
);
2695 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2696 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2697 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2698 size
= sizeof(buffer
);
2699 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2700 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2701 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2702 size
= sizeof(buffer
);
2703 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2704 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2706 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2707 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2708 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2709 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2710 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2711 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2712 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2713 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2714 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2715 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2716 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2718 /* delete values/keys from HKCU to test only on HKLM */
2719 RegCloseKey( hkcusub
[0] );
2720 RegCloseKey( hkcusub
[1] );
2722 RegCloseKey( hkcu
);
2724 size
= sizeof(buffer
);
2725 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2726 ok(res
== ERROR_KEY_DELETED
||
2727 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2728 "expected ERROR_KEY_DELETED, got %d\n", res
);
2729 size
= sizeof(buffer
);
2730 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2731 ok(res
== ERROR_KEY_DELETED
||
2732 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2733 "expected ERROR_KEY_DELETED, got %d\n", res
);
2735 /* reopen HKCR handle */
2736 RegCloseKey( hkcr
);
2737 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2738 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2739 if (res
) goto cleanup
;
2741 /* test on values/keys in HKLM */
2742 size
= sizeof(buffer
);
2743 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2744 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2745 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2746 size
= sizeof(buffer
);
2747 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2748 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2749 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2750 size
= sizeof(buffer
);
2751 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2752 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2754 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2755 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2756 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2757 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2758 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2759 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2760 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2761 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2764 RegCloseKey( hklmsub
[0] );
2765 RegCloseKey( hklmsub
[1] );
2767 RegCloseKey( hklm
);
2768 RegCloseKey( hkcr
);
2771 static void test_classesroot_mask(void)
2776 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
2777 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2778 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
2779 "hkcr mask not set in %p\n", hkey
);
2780 RegCloseKey( hkey
);
2782 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
2783 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2784 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2785 RegCloseKey( hkey
);
2787 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
2788 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2789 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2790 RegCloseKey( hkey
);
2792 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
2793 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2794 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2795 RegCloseKey( hkey
);
2797 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
2798 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2799 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2800 RegCloseKey( hkey
);
2803 static void test_deleted_key(void)
2807 DWORD val_count
, type
;
2810 /* Open the test key, then delete it while it's open */
2811 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2813 delete_key( hkey_main
);
2815 val_count
= sizeof(value
);
2817 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2818 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2820 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2821 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2823 val_count
= sizeof(value
);
2825 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2826 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2828 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2829 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2831 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2832 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2834 RegCloseKey( hkey2
);
2836 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2837 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2839 RegCloseKey( hkey2
);
2841 res
= RegFlushKey( hkey
);
2842 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2844 RegCloseKey( hkey
);
2849 static void test_delete_value(void)
2854 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2855 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2857 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2858 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2860 res
= RegDeleteValueA( hkey_main
, "test" );
2861 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2863 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2864 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2866 res
= RegDeleteValueA( hkey_main
, "test" );
2867 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2869 memset(longname
, 'a', 400);
2871 res
= RegDeleteValueA( hkey_main
, longname
);
2872 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2873 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2876 static void test_delete_key_value(void)
2881 if (!pRegDeleteKeyValueA
)
2883 win_skip("RegDeleteKeyValue is not available.\n");
2887 ret
= pRegDeleteKeyValueA(NULL
, NULL
, NULL
);
2888 ok(ret
== ERROR_INVALID_HANDLE
, "got %d\n", ret
);
2890 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, NULL
);
2891 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2893 ret
= RegSetValueExA(hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2894 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2896 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2897 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2899 /* NULL subkey name means delete from open key */
2900 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, "test");
2901 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2903 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2904 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2906 /* now with real subkey */
2907 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &subkey
, NULL
);
2908 ok(!ret
, "failed with error %d\n", ret
);
2910 ret
= RegSetValueExA(subkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2911 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2913 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
2914 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2916 ret
= pRegDeleteKeyValueA(hkey_main
, "Subkey1", "test");
2917 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2919 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
2920 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2922 RegDeleteKeyA(subkey
, "");
2923 RegCloseKey(subkey
);
2926 START_TEST(registry
)
2928 /* Load pointers for functions that are not available in all Windows versions */
2934 create_test_entries();
2936 test_query_value_ex();
2938 test_reg_open_key();
2939 test_reg_create_key();
2940 test_reg_close_key();
2941 test_reg_delete_key();
2942 test_reg_query_value();
2943 test_string_termination();
2947 test_classesroot_enum();
2948 test_classesroot_mask();
2950 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2951 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2952 set_privileges(SE_RESTORE_NAME
, TRUE
))
2954 test_reg_save_key();
2955 test_reg_load_key();
2956 test_reg_unload_key();
2958 set_privileges(SE_BACKUP_NAME
, FALSE
);
2959 set_privileges(SE_RESTORE_NAME
, FALSE
);
2962 test_reg_delete_tree();
2965 test_delete_value();
2966 test_delete_key_value();
2969 delete_key( hkey_main
);
2971 test_regconnectregistry();