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());
439 if (pRegGetValueA
) /* avoid a crash on Windows 2000 */
441 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_SZ
, NULL
, 4);
442 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
444 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_SZ
, NULL
, 0);
445 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
447 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_DWORD
, NULL
, 4);
448 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
450 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_DWORD
, NULL
, 0);
451 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
455 if (!pRegSetKeyValueW
)
456 win_skip("RegSetKeyValue() is not supported.\n");
459 static const WCHAR subkeyW
[] = {'s','u','b','k','e','y',0};
463 ret
= pRegSetKeyValueW(hkey_main
, NULL
, name1W
, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
464 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
465 test_hkey_main_Value_A(name1A
, string2A
, sizeof(string2A
));
466 test_hkey_main_Value_W(name1W
, string2W
, sizeof(string2W
));
468 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
469 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
471 ret
= RegOpenKeyExW(hkey_main
, subkeyW
, 0, KEY_QUERY_VALUE
, &subkey
);
472 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
474 ret
= RegQueryValueExW(subkey
, name1W
, 0, &type
, NULL
, &len
);
475 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
476 ok(len
== sizeof(string1W
), "got %d\n", len
);
477 ok(type
== REG_SZ
, "got type %d\n", type
);
479 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 0);
480 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
482 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 4);
483 ok(ret
== ERROR_NOACCESS
, "got %d\n", ret
);
485 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_DWORD
, NULL
, 4);
486 ok(ret
== ERROR_NOACCESS
, "got %d\n", ret
);
492 static void create_test_entries(void)
494 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
496 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
497 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
499 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
500 "RegSetValueExA failed\n");
501 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
502 "RegSetValueExA failed\n");
503 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
504 "RegSetValueExA failed\n");
505 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
506 "RegSetValueExA failed\n");
507 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
508 "RegSetValueExA failed\n");
509 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
510 "RegSetValueExA failed\n");
511 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
512 "RegSetValueExA failed\n");
515 static void test_enum_value(void)
519 char value
[20], data
[20];
520 WCHAR valueW
[20], dataW
[20];
521 DWORD val_count
, data_count
, type
;
522 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
523 static const WCHAR testW
[] = {'T','e','s','t',0};
524 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
526 /* create the working key for new 'Test' value */
527 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
528 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
530 /* check NULL data with zero length */
531 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
532 if (GetVersion() & 0x80000000)
533 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
535 ok( !res
, "RegSetValueExA returned %d\n", res
);
536 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
537 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
538 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
539 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
541 /* test reading the value and data without setting them */
545 strcpy( value
, "xxxxxxxxxx" );
546 strcpy( data
, "xxxxxxxxxx" );
547 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
548 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
549 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
550 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
551 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
552 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
553 ok( !strcmp( data
, "xxxxxxxxxx" ), "data is '%s' instead of xxxxxxxxxx\n", data
);
558 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
559 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
560 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
561 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
562 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
563 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
564 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
565 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
566 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data is not 'xxxxxxxxxx'\n" );
568 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
569 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
571 /* overflow both name and data */
575 strcpy( value
, "xxxxxxxxxx" );
576 strcpy( data
, "xxxxxxxxxx" );
577 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
578 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
579 ok( val_count
== 2, "val_count set to %d\n", val_count
);
580 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
581 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
582 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
583 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
589 strcpy( value
, "xxxxxxxxxx" );
590 strcpy( data
, "xxxxxxxxxx" );
591 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
592 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
593 ok( val_count
== 3, "val_count set to %d\n", val_count
);
594 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
595 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
596 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
597 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
598 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
599 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
600 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
602 /* overflow empty name */
606 strcpy( value
, "xxxxxxxxxx" );
607 strcpy( data
, "xxxxxxxxxx" );
608 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
609 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
610 ok( val_count
== 0, "val_count set to %d\n", val_count
);
611 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
612 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
613 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
614 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
615 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
616 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
622 strcpy( value
, "xxxxxxxxxx" );
623 strcpy( data
, "xxxxxxxxxx" );
624 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
625 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
626 ok( val_count
== 20, "val_count set to %d\n", val_count
);
627 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
628 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
629 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
630 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
636 strcpy( value
, "xxxxxxxxxx" );
637 strcpy( data
, "xxxxxxxxxx" );
638 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
639 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
640 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
641 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
642 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
643 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
644 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
648 SetLastError(0xdeadbeef);
649 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
650 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
652 win_skip("RegSetValueExW is not implemented\n");
655 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
657 /* overflow both name and data */
661 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
662 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
663 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
664 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
665 ok( val_count
== 2, "val_count set to %d\n", val_count
);
666 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
667 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
668 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
669 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
675 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
676 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
677 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
678 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
679 ok( val_count
== 3, "val_count set to %d\n", val_count
);
680 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
681 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
682 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
683 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
689 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
690 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
691 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
692 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
693 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
694 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
695 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
696 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
697 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
703 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
704 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
705 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
706 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
707 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
708 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
709 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
710 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
711 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
714 RegDeleteKeyA(test_key
, "");
715 RegCloseKey(test_key
);
718 static void test_query_value_ex(void)
725 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
726 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
727 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
728 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
732 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
733 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
734 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
736 size
= sizeof(buffer
);
737 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
738 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
739 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
742 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
743 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
746 static void test_get_value(void)
753 CHAR expanded
[] = "bar\\subdir1";
754 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
758 win_skip("RegGetValue not available on this platform\n");
762 /* Invalid parameter */
763 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
764 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
766 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
767 size
= type
= dw
= 0xdeadbeef;
768 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
769 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
770 ok(size
== 4, "size=%d\n", size
);
771 ok(type
== REG_DWORD
, "type=%d\n", type
);
772 ok(dw
== 0x12345678, "dw=%d\n", dw
);
774 /* Query by subkey-name */
775 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
776 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
778 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
779 size
= type
= dw
= 0xdeadbeef;
780 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
781 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
782 /* Although the function failed all values are retrieved */
783 ok(size
== 4, "size=%d\n", size
);
784 ok(type
== REG_DWORD
, "type=%d\n", type
);
785 ok(dw
== 0x12345678, "dw=%d\n", dw
);
787 /* Test RRF_ZEROONFAILURE */
788 type
= dw
= 0xdeadbeef; size
= 4;
789 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
790 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
791 /* Again all values are retrieved ... */
792 ok(size
== 4, "size=%d\n", size
);
793 ok(type
== REG_DWORD
, "type=%d\n", type
);
794 /* ... except the buffer, which is zeroed out */
795 ok(dw
== 0, "dw=%d\n", dw
);
797 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
798 type
= size
= 0xbadbeef;
799 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
800 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
801 ok(size
== 4, "size=%d\n", size
);
802 ok(type
== REG_DWORD
, "type=%d\n", type
);
804 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
805 size
= type
= dw
= 0xdeadbeef;
806 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
807 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
808 ok(size
== 4, "size=%d\n", size
);
809 ok(type
== REG_DWORD
, "type=%d\n", type
);
810 ok(dw
== 0x12345678, "dw=%d\n", dw
);
812 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
813 size
= type
= dw
= 0xdeadbeef;
814 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
815 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
816 ok(size
== 4, "size=%d\n", size
);
817 ok(type
== REG_BINARY
, "type=%d\n", type
);
818 ok(dw
== 0x12345678, "dw=%d\n", dw
);
820 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
821 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
822 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
823 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
824 ok(size
== 8, "size=%d\n", size
);
825 ok(type
== REG_BINARY
, "type=%d\n", type
);
826 ok(qw
[0] == 0x12345678 &&
827 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
829 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
830 type
= dw
= 0xdeadbeef; size
= 4;
831 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
832 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
833 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
834 ok(size
== 8, "size=%d\n", size
);
836 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
837 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
838 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
839 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
840 ok(size
== 8, "size=%d\n", size
);
841 ok(type
== REG_BINARY
, "type=%d\n", type
);
842 ok(qw
[0] == 0x12345678 &&
843 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
845 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
846 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
847 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
848 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
849 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
850 ok(type
== REG_SZ
, "type=%d\n", type
);
851 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
853 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
854 type
= 0xdeadbeef; size
= 0;
855 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
856 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
857 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
858 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
859 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
860 ok(type
== REG_SZ
, "type=%d\n", type
);
862 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
863 strcpy(buf
, sTestpath1
);
866 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
867 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
868 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
870 size
== 1, /* win2k3 */
872 ok(type
== REG_SZ
, "type=%d\n", type
);
873 ok(!strcmp(sTestpath1
, buf
) ||
875 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
877 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
878 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
879 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
880 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
881 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
882 ok(type
== REG_SZ
, "type=%d\n", type
);
883 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
885 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
887 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
888 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
889 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
890 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
891 (size
== strlen(sTestpath2
)+1),
892 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
894 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
895 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
896 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
897 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
898 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
899 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
900 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
901 ok(type
== REG_SZ
, "type=%d\n", type
);
902 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
904 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
905 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
906 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
907 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
908 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
909 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
910 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
911 ok(type
== REG_SZ
, "type=%d\n", type
);
912 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
914 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
915 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
916 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
917 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
918 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
919 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
920 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
922 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
924 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
925 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
926 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
927 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
928 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
930 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
931 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
932 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
934 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
935 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
936 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
937 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
939 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
940 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
941 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
942 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
943 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
944 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
945 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
946 ok(type
== REG_SZ
, "type=%d\n", type
);
947 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
950 static void test_reg_open_key(void)
953 HKEY hkResult
= NULL
;
954 HKEY hkPreserve
= NULL
;
955 HKEY hkRoot64
= NULL
;
956 HKEY hkRoot32
= NULL
;
958 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
960 EXPLICIT_ACCESSA access
;
962 SECURITY_DESCRIPTOR
*sd
;
964 /* successful open */
965 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
966 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
967 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
968 hkPreserve
= hkResult
;
970 /* open same key twice */
971 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
972 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
973 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
974 ok(hkResult
!= NULL
, "hkResult != NULL\n");
975 RegCloseKey(hkResult
);
977 /* trailing slashes */
978 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test\\\\", &hkResult
);
979 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
980 RegCloseKey(hkResult
);
982 /* open nonexistent key
983 * check that hkResult is set to NULL
985 hkResult
= hkPreserve
;
986 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
987 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
988 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
990 /* open the same nonexistent key again to make sure the key wasn't created */
991 hkResult
= hkPreserve
;
992 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
993 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
994 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
996 /* send in NULL lpSubKey
997 * check that hkResult receives the value of hKey
999 hkResult
= hkPreserve
;
1000 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
1001 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1002 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
1004 /* send empty-string in lpSubKey */
1005 hkResult
= hkPreserve
;
1006 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
1007 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1008 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
1010 /* send in NULL lpSubKey and NULL hKey
1011 * hkResult is set to NULL
1013 hkResult
= hkPreserve
;
1014 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
1015 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1016 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
1018 /* only send NULL hKey
1019 * the value of hkResult remains unchanged
1021 hkResult
= hkPreserve
;
1022 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
1023 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1024 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1025 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
1026 RegCloseKey(hkResult
);
1028 /* send in NULL hkResult */
1029 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
1030 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1032 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
1033 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1035 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
1036 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1038 /* beginning backslash character */
1039 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
1040 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
1041 broken(ret
== ERROR_SUCCESS
), /* wow64 */
1042 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1043 if (!ret
) RegCloseKey(hkResult
);
1046 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
1047 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
1048 ret
== ERROR_BAD_PATHNAME
, /* NT */
1049 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1050 RegCloseKey(hkResult
);
1054 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
1055 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1056 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1057 RegCloseKey(hkResult
);
1060 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
1061 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1062 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1063 RegCloseKey(hkResult
);
1065 /* check special HKEYs on 64bit
1066 * only the lower 4 bytes of the supplied key are used
1070 /* HKEY_CURRENT_USER */
1071 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "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
);
1076 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
1077 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1078 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1079 RegCloseKey(hkResult
);
1081 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1082 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1083 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1084 RegCloseKey(hkResult
);
1086 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
1087 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1088 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1089 RegCloseKey(hkResult
);
1091 /* HKEY_LOCAL_MACHINE */
1092 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1093 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1094 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1095 RegCloseKey(hkResult
);
1098 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1099 * the registry access check is performed correctly. Redirection isn't
1100 * being tested, so the tests don't care about whether the process is
1101 * running under WOW64. */
1102 if (!pIsWow64Process
)
1104 win_skip("WOW64 flags are not recognized\n");
1108 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1109 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1111 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1112 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1114 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1115 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1117 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1118 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1120 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1121 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1123 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1124 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1126 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1127 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1129 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1131 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1132 access
.grfAccessMode
= SET_ACCESS
;
1133 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1134 access
.Trustee
.pMultipleTrustee
= NULL
;
1135 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1136 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1137 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1138 access
.Trustee
.ptstrName
= (char *)world_sid
;
1140 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1141 ok(ret
== ERROR_SUCCESS
,
1142 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1144 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1145 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1147 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1149 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1151 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1155 skip("not enough privileges to modify HKLM\n");
1161 error
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1162 ok(error
== ERROR_SUCCESS
,
1163 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1165 error
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1166 ok(error
== ERROR_SUCCESS
,
1167 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1170 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1171 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1172 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1173 RegCloseKey(hkResult
);
1176 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1177 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1178 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1179 RegCloseKey(hkResult
);
1182 HeapFree(GetProcessHeap(), 0, sd
);
1185 RegDeleteKeyA(hkRoot64
, "");
1186 RegCloseKey(hkRoot64
);
1187 RegDeleteKeyA(hkRoot32
, "");
1188 RegCloseKey(hkRoot32
);
1191 static void test_reg_create_key(void)
1195 HKEY hkRoot64
= NULL
;
1196 HKEY hkRoot32
= NULL
;
1199 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1201 EXPLICIT_ACCESSA access
;
1203 SECURITY_DESCRIPTOR
*sd
;
1205 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1206 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1207 /* should succeed: all versions of Windows ignore the access rights
1208 * to the parent handle */
1209 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1210 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1213 RegDeleteKeyA(hkey2
, "");
1214 RegDeleteKeyA(hkey1
, "");
1218 /* test creation of volatile keys */
1219 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1220 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1221 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1222 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1223 if (!ret
) RegCloseKey( hkey2
);
1224 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1225 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1227 /* should succeed if the key already exists */
1228 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1229 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1232 RegDeleteKeyA(hkey2
, "");
1233 RegDeleteKeyA(hkey1
, "");
1237 /* beginning backslash character */
1238 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1239 if (!(GetVersion() & 0x80000000))
1240 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1242 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1243 RegDeleteKeyA(hkey1
, "");
1247 /* trailing backslash characters */
1248 ret
= RegCreateKeyExA(hkey_main
, "Subkey4\\\\", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1249 ok(ret
== ERROR_SUCCESS
, "RegCreateKeyExA failed with error %d\n", ret
);
1250 RegDeleteKeyA(hkey1
, "");
1253 /* WOW64 flags - open an existing key */
1255 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1256 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1257 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1261 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1262 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1263 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1266 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1267 * the registry access check is performed correctly. Redirection isn't
1268 * being tested, so the tests don't care about whether the process is
1269 * running under WOW64. */
1270 if (!pIsWow64Process
)
1272 win_skip("WOW64 flags are not recognized\n");
1276 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1277 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1279 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1280 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1282 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1283 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1285 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1286 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1288 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1289 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1291 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1292 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1294 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1295 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1297 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1299 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1300 access
.grfAccessMode
= SET_ACCESS
;
1301 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1302 access
.Trustee
.pMultipleTrustee
= NULL
;
1303 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1304 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1305 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1306 access
.Trustee
.ptstrName
= (char *)world_sid
;
1308 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1309 ok(dwRet
== ERROR_SUCCESS
,
1310 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1312 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1313 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1315 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1317 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1319 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1323 skip("not enough privileges to modify HKLM\n");
1327 ret
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1328 ok(ret
== ERROR_SUCCESS
,
1329 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1331 ret
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1332 ok(ret
== ERROR_SUCCESS
,
1333 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1336 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1337 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1338 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1339 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1343 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1344 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1345 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1346 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1350 HeapFree(GetProcessHeap(), 0, sd
);
1353 RegDeleteKeyA(hkRoot64
, "");
1354 RegCloseKey(hkRoot64
);
1355 RegDeleteKeyA(hkRoot32
, "");
1356 RegCloseKey(hkRoot32
);
1359 static void test_reg_close_key(void)
1364 /* successfully close key
1365 * hkHandle remains changed after call to RegCloseKey
1367 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1368 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1369 ret
= RegCloseKey(hkHandle
);
1370 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1372 /* try to close the key twice */
1373 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1374 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1375 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1377 /* try to close a NULL handle */
1378 ret
= RegCloseKey(NULL
);
1379 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1380 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1382 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1383 * win98 doesn't give a new handle when the same key is opened.
1384 * Not re-opening will make some next tests fail.
1386 if (hkey_main
== hkHandle
)
1388 trace("The main handle is most likely closed, so re-opening\n");
1389 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1393 static void test_reg_delete_key(void)
1398 ret
= RegDeleteKeyA(hkey_main
, NULL
);
1400 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1401 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1402 * Not re-creating will make some next tests fail.
1404 if (ret
== ERROR_SUCCESS
)
1406 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1407 " re-creating the main key\n");
1411 ok(ret
== ERROR_INVALID_PARAMETER
||
1412 ret
== ERROR_ACCESS_DENIED
||
1413 ret
== ERROR_BADKEY
, /* Win95 */
1416 ret
= RegCreateKeyA(hkey_main
, "deleteme", &key
);
1417 ok(ret
== ERROR_SUCCESS
, "Could not create key, got %d\n", ret
);
1418 ret
= RegDeleteKeyA(key
, "");
1419 ok(ret
== ERROR_SUCCESS
, "RegDeleteKeyA failed, got %d\n", ret
);
1421 ret
= RegOpenKeyA(hkey_main
, "deleteme", &key
);
1422 ok(ret
== ERROR_FILE_NOT_FOUND
, "Key was not deleted, got %d\n", ret
);
1426 static void test_reg_save_key(void)
1430 ret
= RegSaveKeyA(hkey_main
, "saved_key", NULL
);
1431 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1434 static void test_reg_load_key(void)
1439 ret
= RegLoadKeyA(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1440 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1442 ret
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1443 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1445 RegCloseKey(hkHandle
);
1448 static void test_reg_unload_key(void)
1452 ret
= RegUnLoadKeyA(HKEY_LOCAL_MACHINE
, "Test");
1453 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1455 DeleteFileA("saved_key");
1456 DeleteFileA("saved_key.LOG");
1459 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1461 TOKEN_PRIVILEGES tp
;
1465 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1468 if(!LookupPrivilegeValueA(NULL
, privilege
, &luid
))
1470 CloseHandle(hToken
);
1474 tp
.PrivilegeCount
= 1;
1475 tp
.Privileges
[0].Luid
= luid
;
1478 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1480 tp
.Privileges
[0].Attributes
= 0;
1482 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1483 if (GetLastError() != ERROR_SUCCESS
)
1485 CloseHandle(hToken
);
1489 CloseHandle(hToken
);
1493 /* tests that show that RegConnectRegistry and
1494 OpenSCManager accept computer names without the
1495 \\ prefix (what MSDN says). */
1496 static void test_regconnectregistry( void)
1498 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1499 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1500 DWORD len
= sizeof(compName
) ;
1506 SetLastError(0xdeadbeef);
1507 ret
= GetComputerNameA(compName
, &len
);
1508 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1511 lstrcpyA(netwName
, "\\\\");
1512 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1514 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1516 retl
== ERROR_DLL_INIT_FAILED
||
1517 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1518 "RegConnectRegistryA failed err = %d\n", retl
);
1519 if( !retl
) RegCloseKey( hkey
);
1521 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1523 retl
== ERROR_DLL_INIT_FAILED
||
1524 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1525 "RegConnectRegistryA failed err = %d\n", retl
);
1526 if( !retl
) RegCloseKey( hkey
);
1528 SetLastError(0xdeadbeef);
1529 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1530 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1532 win_skip("OpenSCManagerA is not implemented\n");
1536 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1537 CloseServiceHandle( schnd
);
1539 SetLastError(0xdeadbeef);
1540 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1541 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1542 CloseServiceHandle( schnd
);
1546 static void test_reg_query_value(void)
1553 static const WCHAR expected
[] = {'d','a','t','a',0};
1555 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1556 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1558 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1559 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1561 /* try an invalid hkey */
1562 SetLastError(0xdeadbeef);
1564 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1565 ok(ret
== ERROR_INVALID_HANDLE
||
1566 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1567 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1568 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1569 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1571 /* try a NULL hkey */
1572 SetLastError(0xdeadbeef);
1574 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1575 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1576 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1577 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1579 /* try a NULL value */
1581 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1582 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1583 ok(size
== 5, "Expected 5, got %d\n", size
);
1585 /* try a NULL size */
1586 SetLastError(0xdeadbeef);
1588 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1589 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1590 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1591 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1593 /* try a NULL value and size */
1594 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1595 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1597 /* try a size too small */
1598 SetLastError(0xdeadbeef);
1601 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1602 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1603 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1604 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1605 ok(size
== 5, "Expected 5, got %d\n", size
);
1607 /* successfully read the value using 'subkey' */
1609 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1610 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1611 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1612 ok(size
== 5, "Expected 5, got %d\n", size
);
1614 /* successfully read the value using the subkey key */
1616 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1617 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1618 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1619 ok(size
== 5, "Expected 5, got %d\n", size
);
1621 /* unicode - try size too small */
1622 SetLastError(0xdeadbeef);
1625 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1626 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1628 win_skip("RegQueryValueW is not implemented\n");
1631 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1632 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1633 ok(!valW
[0], "Expected valW to be untouched\n");
1634 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1636 /* unicode - try size in WCHARS */
1637 SetLastError(0xdeadbeef);
1638 size
= sizeof(valW
) / sizeof(WCHAR
);
1639 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1640 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1641 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1642 ok(!valW
[0], "Expected valW to be untouched\n");
1643 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1645 /* unicode - successfully read the value */
1646 size
= sizeof(valW
);
1647 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1648 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1649 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1650 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1652 /* unicode - set the value without a NULL terminator */
1653 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1654 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1656 /* unicode - read the unterminated value, value is terminated for us */
1657 memset(valW
, 'a', sizeof(valW
));
1658 size
= sizeof(valW
);
1659 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1660 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1661 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1662 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1665 RegDeleteKeyA(subkey
, "");
1666 RegCloseKey(subkey
);
1669 static void test_reg_query_info(void)
1674 char classbuffer
[32];
1675 WCHAR classbufferW
[32];
1676 char expectbuffer
[32];
1677 WCHAR expectbufferW
[32];
1678 char subkey_class
[] = "subkey class";
1679 WCHAR subkey_classW
[] = {'s','u','b','k','e','y',' ','c','l','a','s','s',0};
1680 char subsubkey_class
[] = "subsubkey class";
1682 DWORD subkeys
, maxsubkeylen
, maxclasslen
;
1683 DWORD values
, maxvaluenamelen
, maxvaluelen
;
1687 ret
= RegCreateKeyExA(hkey_main
, "subkey", 0, subkey_class
, 0, KEY_ALL_ACCESS
, NULL
, &subkey
, NULL
);
1688 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1690 /* all parameters NULL */
1691 ret
= RegQueryInfoKeyA(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1692 ok(ret
== ERROR_INVALID_HANDLE
, "ret = %d\n", ret
);
1694 ret
= RegQueryInfoKeyW(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1695 ok(ret
== ERROR_INVALID_HANDLE
, "ret = %d\n", ret
);
1697 /* not requesting any information */
1698 ret
= RegQueryInfoKeyA(subkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1699 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1701 ret
= RegQueryInfoKeyW(subkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1702 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1704 /* class without length is invalid */
1705 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1706 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1707 ok(ret
== ERROR_INVALID_PARAMETER
, "ret = %d\n", ret
);
1708 ok(classbuffer
[0] == 0x55, "classbuffer[0] = 0x%x\n", classbuffer
[0]);
1710 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1711 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1712 ok(ret
== ERROR_INVALID_PARAMETER
, "ret = %d\n", ret
);
1713 ok(classbufferW
[0] == 0x5555, "classbufferW[0] = 0x%x\n", classbufferW
[0]);
1716 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1717 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1718 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1719 ok(subkeys
== 0, "subkeys = %u\n", subkeys
);
1720 ok(maxsubkeylen
== 0, "maxsubkeylen = %u\n", maxsubkeylen
);
1721 ok(maxclasslen
== 0, "maxclasslen = %u\n", maxclasslen
);
1722 ok(values
== 0, "values = %u\n", values
);
1723 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1724 ok(maxvaluelen
== 0, "maxvaluelen = %u\n", maxvaluelen
);
1725 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1726 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1727 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1729 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1730 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1731 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1732 ok(subkeys
== 0, "subkeys = %u\n", subkeys
);
1733 ok(maxsubkeylen
== 0, "maxsubkeylen = %u\n", maxsubkeylen
);
1734 ok(maxclasslen
== 0, "maxclasslen = %u\n", maxclasslen
);
1735 ok(values
== 0, "values = %u\n", values
);
1736 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1737 ok(maxvaluelen
== 0, "maxvaluelen = %u\n", maxvaluelen
);
1738 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1739 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1740 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1742 ret
= RegCreateKeyExA(subkey
, "subsubkey", 0, subsubkey_class
, 0, KEY_ALL_ACCESS
, NULL
, &subsubkey
, NULL
);
1743 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1745 ret
= RegSetValueExA(subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"data", 5);
1746 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1748 /* with subkey & default value */
1749 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1750 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1751 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1752 ok(subkeys
== 1, "subkeys = %u\n", subkeys
);
1753 ok(maxsubkeylen
== strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen
);
1754 ok(maxclasslen
== strlen(subsubkey_class
), "maxclasslen = %u\n", maxclasslen
);
1755 ok(values
== 1, "values = %u\n", values
);
1756 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1757 ok(maxvaluelen
== sizeof("data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1758 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1759 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1760 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1762 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1763 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1764 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1765 ok(subkeys
== 1, "subkeys = %u\n", subkeys
);
1766 ok(maxsubkeylen
== strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen
);
1767 ok(maxclasslen
== strlen(subsubkey_class
), "maxclasslen = %u\n", maxclasslen
);
1768 ok(values
== 1, "values = %u\n", values
);
1769 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1770 ok(maxvaluelen
== sizeof("data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1771 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1772 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1773 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1775 ret
= RegSetValueExA(subkey
, "value one", 0, REG_SZ
, (const BYTE
*)"first value data", 17);
1776 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1778 ret
= RegSetValueExA(subkey
, "value 2", 0, REG_SZ
, (const BYTE
*)"second value data", 18);
1779 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1781 /* with named value */
1782 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1783 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1784 ok(values
== 3, "values = %u\n", values
);
1785 ok(maxvaluenamelen
== strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen
);
1786 ok(maxvaluelen
== sizeof("second value data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1788 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1789 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1790 ok(values
== 3, "values = %u\n", values
);
1791 ok(maxvaluenamelen
== strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen
);
1792 ok(maxvaluelen
== sizeof("second value data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1794 /* class name with zero size buffer */
1795 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1797 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1798 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1799 ok(classlen
== strlen(subkey_class
) /* win2k */ ||
1800 classlen
== 0, "classlen = %u\n", classlen
);
1801 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1802 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)), "classbuffer was modified\n");
1804 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1806 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1807 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1808 ok(classlen
== strlen(subkey_class
) /* win2k */ ||
1809 classlen
== 0, "classlen = %u\n", classlen
);
1810 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1811 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1813 /* class name with one char buffer */
1814 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1816 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1817 ok(ret
== ERROR_MORE_DATA
, "ret = %d\n", ret
);
1818 todo_wine
ok(classlen
== 0, "classlen = %u\n", classlen
);
1819 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1820 expectbuffer
[0] = 0;
1821 todo_wine
ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)), "classbuffer was modified\n");
1823 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1825 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1826 ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "ret = %d\n", ret
);
1827 ok(classlen
== 0 /* win8 */ ||
1828 classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1829 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1830 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1832 /* class name with buffer one char too small */
1833 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1834 classlen
= sizeof(subkey_class
) - 1;
1835 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1836 ok(ret
== ERROR_MORE_DATA
, "ret = %d\n", ret
);
1837 todo_wine
ok(classlen
== sizeof(subkey_class
) - 2, "classlen = %u\n", classlen
);
1838 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1839 strcpy(expectbuffer
, subkey_class
);
1840 expectbuffer
[sizeof(subkey_class
) - 2] = 0;
1841 expectbuffer
[sizeof(subkey_class
) - 1] = 0x55;
1842 todo_wine
ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)),
1843 "classbuffer = %.*s, expected %s\n",
1844 (int)sizeof(classbuffer
), classbuffer
, expectbuffer
);
1846 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1847 classlen
= sizeof(subkey_class
) - 1;
1848 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1849 ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "ret = %d\n", ret
);
1850 ok(classlen
== sizeof(subkey_class
) - 2 /* win8 */ ||
1851 classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1852 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1853 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1855 /* class name with large enough buffer */
1856 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1857 classlen
= sizeof(subkey_class
);
1858 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1859 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1860 ok(classlen
== sizeof(subkey_class
) - 1, "classlen = %u\n", classlen
);
1861 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1862 strcpy(expectbuffer
, subkey_class
);
1863 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)),
1864 "classbuffer = \"%.*s\", expected %s\n",
1865 (int)sizeof(classbuffer
), classbuffer
, expectbuffer
);
1867 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1868 classlen
= sizeof(subkey_class
);
1869 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1870 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1871 ok(classlen
== sizeof(subkey_class
) - 1, "classlen = %u\n", classlen
);
1872 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1873 lstrcpyW(expectbufferW
, subkey_classW
);
1874 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)),
1875 "classbufferW = %s, expected %s\n",
1876 wine_dbgstr_wn(classbufferW
, sizeof(classbufferW
) / sizeof(WCHAR
)), wine_dbgstr_w(expectbufferW
));
1878 RegDeleteKeyA(subsubkey
, "");
1879 RegCloseKey(subsubkey
);
1880 RegDeleteKeyA(subkey
, "");
1881 RegCloseKey(subkey
);
1884 static void test_string_termination(void)
1888 static const char string
[] = "FullString";
1891 DWORD insize
, outsize
, nsize
;
1893 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1894 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1896 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1897 insize
=sizeof(string
)-1;
1898 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1899 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1901 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1902 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1904 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1905 insize
=sizeof(string
)-2;
1906 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1907 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1909 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1910 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1911 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1913 /* RegQueryValueExA may return a string with no trailing '\0' */
1915 memset(buffer
, 0xbd, sizeof(buffer
));
1916 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1917 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1918 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1919 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1920 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1921 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1923 /* RegQueryValueExA adds a trailing '\0' if there is room */
1925 memset(buffer
, 0xbd, sizeof(buffer
));
1926 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1927 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1928 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1929 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1930 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1931 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1933 /* RegEnumValueA may return a string with no trailing '\0' */
1935 memset(buffer
, 0xbd, sizeof(buffer
));
1937 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1938 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1939 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1940 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1941 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1942 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1943 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1945 /* RegEnumValueA adds a trailing '\0' if there is room */
1947 memset(buffer
, 0xbd, sizeof(buffer
));
1949 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1950 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1951 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1952 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1953 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1954 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1955 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1957 RegDeleteKeyA(subkey
, "");
1958 RegCloseKey(subkey
);
1961 static void test_reg_delete_tree(void)
1963 CHAR buffer
[MAX_PATH
];
1964 HKEY subkey
, subkey2
;
1967 if(!pRegDeleteTreeA
) {
1968 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1972 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1973 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1974 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1975 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1976 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1977 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1978 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1979 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1980 ret
= RegCloseKey(subkey2
);
1981 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1983 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1984 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1985 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1986 "subkey2 was not deleted\n");
1988 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1989 "Default value of subkey not longer present\n");
1991 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1992 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1993 ret
= RegCloseKey(subkey2
);
1994 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1995 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1996 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1997 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1998 "subkey2 was not deleted\n");
1999 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
2000 "Default value of subkey not longer present\n");
2002 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
2003 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2004 ret
= RegCloseKey(subkey2
);
2005 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2006 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
2007 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2008 ret
= RegCloseKey(subkey2
);
2009 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2010 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
2011 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2012 ret
= pRegDeleteTreeA(subkey
, NULL
);
2013 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2014 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
2015 "subkey was deleted\n");
2016 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
2017 "subkey2 was not deleted\n");
2018 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
2019 "subkey3 was not deleted\n");
2021 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
2022 ok(ret
== ERROR_SUCCESS
,
2023 "Default value of subkey is not present\n");
2024 ok(!buffer
[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
2026 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
2027 "Value is still present\n");
2029 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
2030 ok(ret
== ERROR_FILE_NOT_FOUND
,
2031 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
2034 static void test_rw_order(void)
2038 static const char keyname
[] = "test_rw_order";
2040 DWORD values
, value_len
, value_name_max_len
;
2043 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
2044 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
2045 if(ret
!= ERROR_SUCCESS
) {
2046 skip("Couldn't create key. Skipping.\n");
2050 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2051 "RegSetValueExA for value \"A\" failed\n");
2052 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2053 "RegSetValueExA for value \"C\" failed\n");
2054 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2055 "RegSetValueExA for value \"D\" failed\n");
2056 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2057 "RegSetValueExA for value \"B\" failed\n");
2059 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
2060 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
2061 ok(values
== 4, "Expected 4 values, got %u\n", values
);
2063 /* Value enumeration preserves RegSetValueEx call order */
2065 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2066 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
2068 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2069 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
2071 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2072 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
2074 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2075 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
2077 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
2080 static void test_symlinks(void)
2082 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
2083 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
2085 UNICODE_STRING target_str
;
2089 DWORD target_len
, type
, len
, dw
, err
;
2091 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
2093 win_skip( "Can't perform symlink tests\n" );
2097 pRtlFormatCurrentUserKeyPath( &target_str
);
2099 target_len
= target_str
.Length
+ sizeof(targetW
);
2100 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
2101 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
2102 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
2104 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
2105 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
2106 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
2108 /* REG_SZ is not allowed */
2109 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
2110 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
2111 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
2112 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2113 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2114 /* other values are not allowed */
2115 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2116 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
2118 /* try opening the target through the link */
2120 err
= RegOpenKeyA( hkey_main
, "link", &key
);
2121 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
2123 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2124 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2127 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2128 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2131 err
= RegOpenKeyA( hkey_main
, "link", &key
);
2132 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
2134 len
= sizeof(buffer
);
2135 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
2136 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
2137 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
2139 len
= sizeof(buffer
);
2140 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2141 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
2143 /* REG_LINK can be created in non-link keys */
2144 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
2145 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2146 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2147 len
= sizeof(buffer
);
2148 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2149 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2150 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2151 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
2152 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
2156 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2157 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2159 len
= sizeof(buffer
);
2160 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
2161 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2162 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
2164 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2165 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
2168 /* now open the symlink itself */
2170 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
2171 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
2172 len
= sizeof(buffer
);
2173 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2174 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2175 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2178 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
2179 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2180 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2181 len
= sizeof(buffer
);
2182 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2183 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2184 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2187 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
2188 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2189 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
2191 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
2192 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2193 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
2195 err
= RegDeleteKeyA( hkey_main
, "target" );
2196 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
2198 err
= RegDeleteKeyA( hkey_main
, "link" );
2199 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
2201 status
= pNtDeleteKey( link
);
2202 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
2203 RegCloseKey( link
);
2205 HeapFree( GetProcessHeap(), 0, target
);
2206 pRtlFreeUnicodeString( &target_str
);
2209 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
2212 DWORD err
, type
, dw
, len
= sizeof(dw
);
2214 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2215 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
2216 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
2218 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2219 if (err
== ERROR_FILE_NOT_FOUND
)
2222 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
2227 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
2229 DWORD dw
= get_key_value( root
, name
, flags
);
2230 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
2232 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
2234 static void test_redirection(void)
2236 DWORD err
, type
, dw
, len
;
2237 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
2238 BOOL is_vista
= FALSE
;
2239 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
2244 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
2246 skip( "Not on Wow64, no redirection\n" );
2251 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2252 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
2253 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2255 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2256 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
2257 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2259 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2260 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
2261 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2263 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2264 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
2265 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2268 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2269 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2272 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2273 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2277 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2278 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2279 ok( dw
== 32, "wrong value %u\n", dw
);
2283 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2284 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2285 ok( dw
== 64, "wrong value %u\n", dw
);
2287 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2288 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2289 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2293 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2294 /* the new (and simpler) Win7 mechanism doesn't */
2295 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2297 trace( "using Vista-style Wow6432Node handling\n" );
2300 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2301 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2302 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2303 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2304 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2305 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2309 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
2311 trace( "using Vista-style Wow6432Node handling\n" );
2314 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2315 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2321 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2322 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2323 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2324 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2325 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2326 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2327 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2328 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2329 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
2330 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
2331 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2334 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2335 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2336 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2337 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2338 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2339 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2340 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2341 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2342 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2347 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2348 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2349 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2350 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2351 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2352 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
);
2353 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2354 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2357 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2358 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2359 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2360 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2361 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
);
2362 ok( dw
== 32 || broken(dw
== 64) /* vista */, "wrong value %u\n", dw
);
2363 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2367 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
2368 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2371 /* KEY_WOW64 flags have no effect on 64-bit */
2372 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2373 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2374 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2375 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2379 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2380 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2381 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2382 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2385 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2386 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2387 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2388 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2389 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2390 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2395 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2396 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2397 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2398 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2399 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2400 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2401 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2404 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2405 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2406 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2407 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2408 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2409 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2413 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2414 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2415 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2416 check_key_value( key
, "Winetest", 0, 32 );
2417 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2418 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2423 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2424 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2425 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2426 dw
= get_key_value( key
, "Winetest", 0 );
2427 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2428 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2429 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2432 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2433 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2434 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2435 check_key_value( key
, "Winetest", 0, 32 );
2436 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2437 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2441 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2442 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2443 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2444 check_key_value( key
, "Winetest", 0, ptr_size
);
2445 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2446 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2447 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2448 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2453 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2454 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2455 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2456 dw
= get_key_value( key
, "Winetest", 0 );
2457 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2458 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2459 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2460 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2463 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2464 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2465 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2466 check_key_value( key
, "Winetest", 0, 32 );
2467 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2468 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2472 if (pRegDeleteKeyExA
)
2474 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2475 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2476 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2477 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2478 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2479 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2483 err
= RegDeleteKeyA( key32
, "" );
2484 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2485 err
= RegDeleteKeyA( key64
, "" );
2486 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2487 RegDeleteKeyA( key64
, "" );
2488 RegDeleteKeyA( root64
, "" );
2490 RegCloseKey( key32
);
2491 RegCloseKey( key64
);
2492 RegCloseKey( root32
);
2493 RegCloseKey( root64
);
2495 /* open key in native bit mode */
2496 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2497 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2499 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2501 /* write subkey in opposite bit mode */
2502 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2503 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2505 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2507 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2508 if(err
!= ERROR_SUCCESS
){
2509 win_skip("Can't write to registry\n");
2510 RegCloseKey(op_key
);
2511 RegCloseKey(native
);
2516 /* verify subkey is not present in native mode */
2517 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2518 ok(err
== ERROR_FILE_NOT_FOUND
||
2519 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2522 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2523 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2525 RegCloseKey(op_key
);
2526 RegCloseKey(native
);
2529 static void test_classesroot(void)
2531 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2533 DWORD type
= REG_SZ
;
2534 static CHAR buffer
[8];
2537 /* create a key in the user's classes */
2538 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2541 RegCloseKey( hkey
);
2543 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2544 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2545 if (res
== ERROR_ACCESS_DENIED
)
2547 skip("not enough privileges to add a user class\n");
2550 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2552 /* try to open that key in hkcr */
2553 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2554 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2555 todo_wine
ok(res
== ERROR_SUCCESS
||
2556 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2557 "test key not found in hkcr: %d\n", res
);
2560 skip("HKCR key merging not supported\n");
2562 RegCloseKey( hkey
);
2566 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2568 /* set a value in user's classes */
2569 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2570 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2572 /* try to find the value in hkcr */
2573 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2574 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2575 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2577 /* modify the value in hkcr */
2578 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2579 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2581 /* check if the value is also modified in user's classes */
2582 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2583 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2584 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2586 /* set a value in hkcr */
2587 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2588 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2590 /* try to find the value in user's classes */
2591 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2592 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2593 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2595 /* modify the value in user's classes */
2596 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2597 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2599 /* check if the value is also modified in hkcr */
2600 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2601 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2602 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2607 RegCloseKey( hkey
);
2608 RegCloseKey( hkcr
);
2610 /* create a key in the hklm classes */
2611 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2614 RegCloseKey( hklm
);
2616 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2617 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2618 if (res
== ERROR_ACCESS_DENIED
)
2620 skip("not enough privileges to add a system class\n");
2623 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2625 /* try to open that key in hkcr */
2626 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2627 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2628 ok(res
== ERROR_SUCCESS
,
2629 "test key not found in hkcr: %d\n", res
);
2630 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2634 RegCloseKey( hklm
);
2638 /* set a value in hklm classes */
2639 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2640 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2642 /* try to find the value in hkcr */
2643 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2644 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2645 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2647 /* modify the value in hkcr */
2648 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2649 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2651 /* check that the value is modified in hklm classes */
2652 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2653 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2654 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2656 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2657 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2658 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2660 /* try to open that key in hkcr */
2661 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2662 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2663 ok(res
== ERROR_SUCCESS
,
2664 "test key not found in hkcr: %d\n", res
);
2665 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2667 /* set a value in user's classes */
2668 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2669 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2671 /* try to find the value in hkcr */
2672 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2673 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2674 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2676 /* modify the value in hklm */
2677 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2678 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2680 /* check that the value is not overwritten in hkcr or user's classes */
2681 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2682 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2683 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2684 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2685 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2686 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2688 /* modify the value in hkcr */
2689 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2690 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2692 /* check that the value is overwritten in hklm and user's classes */
2693 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2694 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2695 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2696 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2697 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2698 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2700 /* create a subkey in hklm */
2701 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2702 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2703 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2704 /* try to open that subkey in hkcr */
2705 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2706 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2707 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2709 /* set a value in hklm classes */
2710 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2711 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2713 /* try to find the value in hkcr */
2714 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2715 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2716 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2718 /* modify the value in hkcr */
2719 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2720 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2722 /* check that the value is modified in hklm classes */
2723 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2724 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2725 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2727 /* create a subkey in user's classes */
2728 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2729 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2730 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2732 /* set a value in user's classes */
2733 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2734 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2736 /* try to find the value in hkcr */
2737 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2738 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2739 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2741 /* modify the value in hklm */
2742 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2743 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2745 /* check that the value is not overwritten in hkcr or user's classes */
2746 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2747 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2748 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2749 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2750 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2751 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2753 /* modify the value in hkcr */
2754 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2755 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2757 /* check that the value is not overwritten in hklm, but in user's classes */
2758 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2759 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2760 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2761 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2762 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2763 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2765 /* new subkey in hkcr */
2766 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2767 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2768 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2769 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2770 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2772 /* try to open that new subkey in user's classes and hklm */
2773 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2774 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2776 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2777 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2778 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2780 /* check that the value is present in hklm */
2781 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2782 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2783 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2786 RegCloseKey( hkeysub1
);
2787 RegCloseKey( hklmsub1
);
2789 /* delete subkey1 from hkcr (should point at user's classes) */
2790 res
= RegDeleteKeyA(hkcr
, "subkey1");
2791 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2793 /* confirm key was removed in hkey but not hklm */
2794 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2795 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2796 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2797 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2798 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2800 /* delete subkey1 from hkcr again (which should now point at hklm) */
2801 res
= RegDeleteKeyA(hkcr
, "subkey1");
2802 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2804 /* confirm hkey was removed in hklm */
2805 RegCloseKey( hklmsub1
);
2806 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2807 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2813 delete_key( hkeysub1
);
2814 delete_key( hklmsub1
);
2815 delete_key( hkcrsub1
);
2816 delete_key( hklmsub2
);
2817 delete_key( hkcrsub2
);
2818 RegCloseKey( hkey
);
2819 RegCloseKey( hklm
);
2820 RegCloseKey( hkcr
);
2821 RegCloseKey( hkeysub1
);
2822 RegCloseKey( hklmsub1
);
2823 RegCloseKey( hkcrsub1
);
2824 RegCloseKey( hklmsub2
);
2825 RegCloseKey( hkcrsub2
);
2828 static void test_classesroot_enum(void)
2830 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2832 static CHAR buffer
[2];
2835 /* prepare initial testing env in HKCU */
2836 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2839 RegCloseKey( hkcu
);
2841 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2842 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2844 if (res
!= ERROR_SUCCESS
)
2846 skip("failed to add a user class\n");
2850 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2851 todo_wine
ok(res
== ERROR_SUCCESS
||
2852 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2853 "test key not found in hkcr: %d\n", res
);
2856 skip("HKCR key merging not supported\n");
2858 RegCloseKey( hkcu
);
2862 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2863 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2864 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2865 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2866 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2867 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2868 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2869 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2871 /* test on values in HKCU */
2872 size
= sizeof(buffer
);
2873 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2874 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2875 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2876 size
= sizeof(buffer
);
2877 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2878 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2879 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2880 size
= sizeof(buffer
);
2881 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2882 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2884 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2885 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2886 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2887 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2888 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2889 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2890 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2891 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2893 /* prepare test env in HKLM */
2894 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2897 RegCloseKey( hklm
);
2900 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2901 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2903 if (res
== ERROR_ACCESS_DENIED
)
2905 RegCloseKey( hkcusub
[0] );
2906 RegCloseKey( hkcusub
[1] );
2908 RegCloseKey( hkcu
);
2909 RegCloseKey( hkcr
);
2910 skip("not enough privileges to add a system class\n");
2914 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2915 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2916 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2917 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2918 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2919 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2920 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2921 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2923 /* test on values/keys in both HKCU and HKLM */
2924 size
= sizeof(buffer
);
2925 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2926 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2927 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2928 size
= sizeof(buffer
);
2929 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2930 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2931 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2932 size
= sizeof(buffer
);
2933 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2934 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2935 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2936 size
= sizeof(buffer
);
2937 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2938 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2940 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2941 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2942 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2943 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2944 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2945 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2946 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2947 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2948 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2949 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2950 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2952 /* delete values/keys from HKCU to test only on HKLM */
2953 RegCloseKey( hkcusub
[0] );
2954 RegCloseKey( hkcusub
[1] );
2956 RegCloseKey( hkcu
);
2958 size
= sizeof(buffer
);
2959 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2960 ok(res
== ERROR_KEY_DELETED
||
2961 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2962 "expected ERROR_KEY_DELETED, got %d\n", res
);
2963 size
= sizeof(buffer
);
2964 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2965 ok(res
== ERROR_KEY_DELETED
||
2966 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2967 "expected ERROR_KEY_DELETED, got %d\n", res
);
2969 /* reopen HKCR handle */
2970 RegCloseKey( hkcr
);
2971 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2972 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2973 if (res
) goto cleanup
;
2975 /* test on values/keys in HKLM */
2976 size
= sizeof(buffer
);
2977 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2978 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2979 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2980 size
= sizeof(buffer
);
2981 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2982 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2983 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2984 size
= sizeof(buffer
);
2985 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2986 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2988 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2989 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2990 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2991 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2992 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2993 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2994 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2995 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2998 RegCloseKey( hklmsub
[0] );
2999 RegCloseKey( hklmsub
[1] );
3001 RegCloseKey( hklm
);
3002 RegCloseKey( hkcr
);
3005 static void test_classesroot_mask(void)
3010 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
3011 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3012 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
3013 "hkcr mask not set in %p\n", hkey
);
3014 RegCloseKey( hkey
);
3016 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
3017 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3018 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3019 RegCloseKey( hkey
);
3021 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
3022 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3023 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3024 RegCloseKey( hkey
);
3026 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
3027 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3028 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3029 RegCloseKey( hkey
);
3031 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
3032 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3033 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3034 RegCloseKey( hkey
);
3037 static void test_deleted_key(void)
3041 DWORD val_count
, type
;
3044 /* Open the test key, then delete it while it's open */
3045 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
3047 delete_key( hkey_main
);
3049 val_count
= sizeof(value
);
3051 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
3052 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3054 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
3055 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3057 val_count
= sizeof(value
);
3059 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
3060 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3062 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3063 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3065 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
3066 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3068 RegCloseKey( hkey2
);
3070 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
3071 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3073 RegCloseKey( hkey2
);
3075 res
= RegFlushKey( hkey
);
3076 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3078 RegCloseKey( hkey
);
3083 static void test_delete_value(void)
3088 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
3089 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3091 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3092 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3094 res
= RegDeleteValueA( hkey_main
, "test" );
3095 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3097 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3098 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3100 res
= RegDeleteValueA( hkey_main
, "test" );
3101 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3103 memset(longname
, 'a', 400);
3105 res
= RegDeleteValueA( hkey_main
, longname
);
3106 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
3107 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3110 static void test_delete_key_value(void)
3115 if (!pRegDeleteKeyValueA
)
3117 win_skip("RegDeleteKeyValue is not available.\n");
3121 ret
= pRegDeleteKeyValueA(NULL
, NULL
, NULL
);
3122 ok(ret
== ERROR_INVALID_HANDLE
, "got %d\n", ret
);
3124 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, NULL
);
3125 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3127 ret
= RegSetValueExA(hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3128 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3130 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3131 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3133 /* NULL subkey name means delete from open key */
3134 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, "test");
3135 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3137 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3138 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3140 /* now with real subkey */
3141 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &subkey
, NULL
);
3142 ok(!ret
, "failed with error %d\n", ret
);
3144 ret
= RegSetValueExA(subkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3145 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3147 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
3148 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3150 ret
= pRegDeleteKeyValueA(hkey_main
, "Subkey1", "test");
3151 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3153 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
3154 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3156 RegDeleteKeyA(subkey
, "");
3157 RegCloseKey(subkey
);
3160 START_TEST(registry
)
3162 /* Load pointers for functions that are not available in all Windows versions */
3168 create_test_entries();
3170 test_query_value_ex();
3172 test_reg_open_key();
3173 test_reg_create_key();
3174 test_reg_close_key();
3175 test_reg_delete_key();
3176 test_reg_query_value();
3177 test_reg_query_info();
3178 test_string_termination();
3182 test_classesroot_enum();
3183 test_classesroot_mask();
3185 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
3186 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
3187 set_privileges(SE_RESTORE_NAME
, TRUE
))
3189 test_reg_save_key();
3190 test_reg_load_key();
3191 test_reg_unload_key();
3193 set_privileges(SE_BACKUP_NAME
, FALSE
);
3194 set_privileges(SE_RESTORE_NAME
, FALSE
);
3197 test_reg_delete_tree();
3200 test_delete_value();
3201 test_delete_key_value();
3204 delete_key( hkey_main
);
3206 test_regconnectregistry();