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
22 #define WIN32_NO_STATUS
23 #define WIN32_LEAN_AND_MEAN
28 #include "wine/test.h"
31 #include "wine/winternl.h"
37 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
39 static HKEY hkey_main
;
42 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
43 static const char * sTestpath2
= "%FOO%\\subdir1";
44 static const DWORD ptr_size
= 8 * sizeof(void*);
46 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
47 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
48 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
49 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
50 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
51 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
52 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
53 static LONG (WINAPI
*pRegDeleteKeyValueA
)(HKEY
,LPCSTR
,LPCSTR
);
54 static LONG (WINAPI
*pRegSetKeyValueW
)(HKEY
,LPCWSTR
,LPCWSTR
,DWORD
,const void*,DWORD
);
56 static BOOL limited_user
;
59 /* Debugging functions from wine/libs/wine/debug.c */
61 /* allocate some tmp string space */
62 /* FIXME: this is not 100% thread-safe */
63 static char *get_temp_buffer( int size
)
65 static char *list
[32];
70 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
72 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
74 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
75 if (ret
) list
[idx
] = ret
;
79 static const char *wine_debugstr_an( const char *str
, int n
)
81 static const char hex
[16] = "0123456789abcdef";
85 if (!((ULONG_PTR
)str
>> 16))
87 if (!str
) return "(null)";
88 res
= get_temp_buffer( 6 );
89 sprintf( res
, "#%04x", LOWORD(str
) );
92 if (n
== -1) n
= strlen(str
);
94 size
= 10 + min( 300, n
* 4 );
95 dst
= res
= get_temp_buffer( size
);
97 while (n
-- > 0 && dst
<= res
+ size
- 9)
99 unsigned char c
= *str
++;
102 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
103 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
104 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
105 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
106 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
108 if (c
>= ' ' && c
<= 126)
114 *dst
++ = hex
[(c
>> 4) & 0x0f];
115 *dst
++ = hex
[c
& 0x0f];
130 #define ADVAPI32_GET_PROC(func) \
131 p ## func = (void*)GetProcAddress(hadvapi32, #func)
133 static void InitFunctionPtrs(void)
135 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
136 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
137 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
139 /* This function was introduced with Windows 2003 SP1 */
140 ADVAPI32_GET_PROC(RegGetValueA
);
141 ADVAPI32_GET_PROC(RegDeleteTreeA
);
142 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
143 ADVAPI32_GET_PROC(RegDeleteKeyValueA
);
144 ADVAPI32_GET_PROC(RegSetKeyValueW
);
146 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
147 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
148 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
149 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
152 /* delete key and all its subkeys */
153 static DWORD
delete_key( HKEY hkey
)
158 if ((ret
= RegOpenKeyExA( hkey
, "", 0, KEY_ENUMERATE_SUB_KEYS
, &hkey
))) return ret
;
159 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
162 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
164 ret
= delete_key( tmp
);
169 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
170 RegDeleteKeyA( hkey
, "" );
175 static void setup_main_key(void)
177 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
179 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
182 static void check_user_privs(void)
185 HKEY hkey
= (HKEY
)0xdeadbeef;
187 ret
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WRITE
, &hkey
);
188 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_ACCESS_DENIED
, "expected success or access denied, got %i\n", ret
);
189 if (ret
== ERROR_SUCCESS
)
191 ok(hkey
!= NULL
, "RegOpenKeyExA succeeded but returned NULL hkey\n");
196 ok(hkey
== NULL
, "RegOpenKeyExA failed but returned hkey %p\n", hkey
);
198 trace("running as limited user\n");
202 #define lok ok_(__FILE__, line)
203 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
204 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
207 DWORD ret
, type
, cbData
;
213 /* When successful RegQueryValueExA() leaves GLE as is,
214 * so we must reset it to detect unimplemented functions.
216 SetLastError(0xdeadbeef);
217 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
218 GLE
= GetLastError();
219 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
220 /* It is wrong for the Ansi version to not be implemented */
221 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
222 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
224 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
225 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
226 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
228 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
229 memset(value
, 0xbd, cbData
+1);
231 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
232 GLE
= GetLastError();
233 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
236 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
237 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
241 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
242 wine_debugstr_an((char*)value
, cbData
), cbData
,
243 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
244 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
246 HeapFree(GetProcessHeap(), 0, value
);
249 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
250 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
253 DWORD ret
, type
, cbData
;
258 /* When successful RegQueryValueExW() leaves GLE as is,
259 * so we must reset it to detect unimplemented functions.
261 SetLastError(0xdeadbeef);
262 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
263 GLE
= GetLastError();
264 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
265 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
267 win_skip("RegQueryValueExW() is not implemented\n");
271 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
272 lok(cbData
== full_byte_len
,
273 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
275 /* Give enough space to overflow by one WCHAR */
276 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
277 memset(value
, 0xbd, cbData
+2);
279 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
280 GLE
= GetLastError();
281 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
284 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
285 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
286 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
288 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
289 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
290 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
291 HeapFree(GetProcessHeap(), 0, value
);
294 static void test_set_value(void)
298 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
299 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};
300 static const WCHAR emptyW
[] = {0};
301 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
302 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};
303 static const WCHAR substring2W
[] = {'T','h','i','s',0};
305 static const char name1A
[] = "CleanSingleString";
306 static const char name2A
[] = "SomeIntraZeroedString";
307 static const char emptyA
[] = "";
308 static const char string1A
[] = "ThisNeverBreaks";
309 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
310 static const char substring2A
[] = "This";
314 /* Crashes on NT4, Windows 2000 and XP SP1 */
315 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
316 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
319 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
320 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
321 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
322 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
324 /* RegSetValueA ignores the size passed in */
325 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
326 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
327 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
328 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
330 /* stops at first null */
331 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
332 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
333 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
334 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
336 /* only REG_SZ is supported on NT*/
337 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
338 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
340 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
341 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
343 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
344 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
346 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
347 * Surprisingly enough we're supposed to get zero bytes out of it.
349 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
350 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
351 test_hkey_main_Value_A(name1A
, NULL
, 0);
352 test_hkey_main_Value_W(name1W
, NULL
, 0);
354 /* test RegSetValueExA with an empty string */
355 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
356 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
357 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
358 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
360 /* test RegSetValueExA with off-by-one size */
361 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
362 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
363 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
364 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
366 /* test RegSetValueExA with normal string */
367 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
368 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
369 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
370 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
372 /* test RegSetValueExA with intrazeroed string */
373 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
374 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
375 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
376 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
380 /* Crashes on NT4, Windows 2000 and XP SP1 */
381 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
382 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
384 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
385 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
388 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
389 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
390 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
391 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
393 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
394 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
395 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
396 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
398 /* RegSetValueW ignores the size passed in */
399 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
400 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
401 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
402 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
404 /* stops at first null */
405 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
406 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
407 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
408 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
410 /* only REG_SZ is supported */
411 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
412 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
413 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
414 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
415 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
416 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
418 /* test RegSetValueExW with off-by-one size */
419 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
420 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
421 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
422 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
424 /* test RegSetValueExW with normal string */
425 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
426 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
427 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
428 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
430 /* test RegSetValueExW with intrazeroed string */
431 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
432 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
433 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
434 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
436 /* test RegSetValueExW with data = 1 */
437 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
438 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
439 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
440 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
442 if (pRegGetValueA
) /* avoid a crash on Windows 2000 */
444 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_SZ
, NULL
, 4);
445 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
447 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_SZ
, NULL
, 0);
448 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
450 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_DWORD
, NULL
, 4);
451 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
453 ret
= RegSetValueExW(hkey_main
, NULL
, 0, REG_DWORD
, NULL
, 0);
454 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
458 if (!pRegSetKeyValueW
)
459 win_skip("RegSetKeyValue() is not supported.\n");
462 static const WCHAR subkeyW
[] = {'s','u','b','k','e','y',0};
466 ret
= pRegSetKeyValueW(hkey_main
, NULL
, name1W
, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
467 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
468 test_hkey_main_Value_A(name1A
, string2A
, sizeof(string2A
));
469 test_hkey_main_Value_W(name1W
, string2W
, sizeof(string2W
));
471 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
472 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
474 ret
= RegOpenKeyExW(hkey_main
, subkeyW
, 0, KEY_QUERY_VALUE
, &subkey
);
475 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
477 ret
= RegQueryValueExW(subkey
, name1W
, 0, &type
, NULL
, &len
);
478 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
479 ok(len
== sizeof(string1W
), "got %d\n", len
);
480 ok(type
== REG_SZ
, "got type %d\n", type
);
482 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 0);
483 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
485 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 4);
486 ok(ret
== ERROR_NOACCESS
, "got %d\n", ret
);
488 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_DWORD
, NULL
, 4);
489 ok(ret
== ERROR_NOACCESS
, "got %d\n", ret
);
495 static void create_test_entries(void)
497 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
499 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
500 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
502 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
503 "RegSetValueExA failed\n");
504 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
505 "RegSetValueExA failed\n");
506 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
507 "RegSetValueExA failed\n");
508 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
509 "RegSetValueExA failed\n");
510 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
511 "RegSetValueExA failed\n");
512 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
513 "RegSetValueExA failed\n");
514 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
515 "RegSetValueExA failed\n");
518 static void test_enum_value(void)
522 char value
[20], data
[20];
523 WCHAR valueW
[20], dataW
[20];
524 DWORD val_count
, data_count
, type
;
525 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
526 static const WCHAR testW
[] = {'T','e','s','t',0};
527 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
529 /* create the working key for new 'Test' value */
530 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
531 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
533 /* check NULL data with zero length */
534 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
535 if (GetVersion() & 0x80000000)
536 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
538 ok( !res
, "RegSetValueExA returned %d\n", res
);
539 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
540 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
541 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
542 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
544 /* test reading the value and data without setting them */
548 strcpy( value
, "xxxxxxxxxx" );
549 strcpy( data
, "xxxxxxxxxx" );
550 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
551 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
552 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
553 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
554 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
555 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
556 ok( !strcmp( data
, "xxxxxxxxxx" ), "data is '%s' instead of xxxxxxxxxx\n", data
);
561 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
562 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
563 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
564 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
565 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
566 ok( data_count
== 0, "data_count set to %d instead of 0\n", data_count
);
567 ok( type
== REG_BINARY
, "type %d is not REG_BINARY\n", type
);
568 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
569 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data is not 'xxxxxxxxxx'\n" );
571 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
572 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
574 /* overflow both name and data */
578 strcpy( value
, "xxxxxxxxxx" );
579 strcpy( data
, "xxxxxxxxxx" );
580 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
581 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
582 ok( val_count
== 2, "val_count set to %d\n", val_count
);
583 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
584 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
585 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
586 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
592 strcpy( value
, "xxxxxxxxxx" );
593 strcpy( data
, "xxxxxxxxxx" );
594 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
595 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
596 ok( val_count
== 3, "val_count set to %d\n", val_count
);
597 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
598 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
599 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
600 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
601 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
602 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
603 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
605 /* overflow empty name */
609 strcpy( value
, "xxxxxxxxxx" );
610 strcpy( data
, "xxxxxxxxxx" );
611 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
612 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
613 ok( val_count
== 0, "val_count set to %d\n", val_count
);
614 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
615 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
616 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
617 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
618 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
619 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
625 strcpy( value
, "xxxxxxxxxx" );
626 strcpy( data
, "xxxxxxxxxx" );
627 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
628 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
629 ok( val_count
== 20, "val_count set to %d\n", val_count
);
630 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
631 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
632 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
633 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
639 strcpy( value
, "xxxxxxxxxx" );
640 strcpy( data
, "xxxxxxxxxx" );
641 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
642 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
643 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
644 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
645 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
646 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
647 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
651 SetLastError(0xdeadbeef);
652 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
653 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
655 win_skip("RegSetValueExW is not implemented\n");
658 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
660 /* overflow both name and data */
664 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
665 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
666 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
667 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
668 ok( val_count
== 2, "val_count set to %d\n", val_count
);
669 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
670 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
671 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
672 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
678 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
679 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
680 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
681 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
682 ok( val_count
== 3, "val_count set to %d\n", val_count
);
683 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
684 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
685 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
686 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
692 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
693 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
694 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
695 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
696 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
697 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
698 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
699 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
700 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
706 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
707 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
708 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
709 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
710 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
711 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
712 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
713 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
714 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
717 RegDeleteKeyA(test_key
, "");
718 RegCloseKey(test_key
);
721 static void test_query_value_ex(void)
728 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
729 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
730 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
731 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
735 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
736 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
737 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
739 size
= sizeof(buffer
);
740 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
741 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
742 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
745 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
746 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
749 static void test_get_value(void)
756 CHAR expanded
[] = "bar\\subdir1";
757 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
761 win_skip("RegGetValue not available on this platform\n");
765 /* Invalid parameter */
766 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
767 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
769 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
770 size
= type
= dw
= 0xdeadbeef;
771 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
772 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
773 ok(size
== 4, "size=%d\n", size
);
774 ok(type
== REG_DWORD
, "type=%d\n", type
);
775 ok(dw
== 0x12345678, "dw=%d\n", dw
);
777 /* Query by subkey-name */
778 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
779 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
781 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
782 size
= type
= dw
= 0xdeadbeef;
783 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
784 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
785 /* Although the function failed all values are retrieved */
786 ok(size
== 4, "size=%d\n", size
);
787 ok(type
== REG_DWORD
, "type=%d\n", type
);
788 ok(dw
== 0x12345678, "dw=%d\n", dw
);
790 /* Test RRF_ZEROONFAILURE */
791 type
= dw
= 0xdeadbeef; size
= 4;
792 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
793 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
794 /* Again all values are retrieved ... */
795 ok(size
== 4, "size=%d\n", size
);
796 ok(type
== REG_DWORD
, "type=%d\n", type
);
797 /* ... except the buffer, which is zeroed out */
798 ok(dw
== 0, "dw=%d\n", dw
);
800 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
801 type
= size
= 0xbadbeef;
802 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
803 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
804 ok(size
== 4, "size=%d\n", size
);
805 ok(type
== REG_DWORD
, "type=%d\n", type
);
807 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
808 size
= type
= dw
= 0xdeadbeef;
809 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
810 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
811 ok(size
== 4, "size=%d\n", size
);
812 ok(type
== REG_DWORD
, "type=%d\n", type
);
813 ok(dw
== 0x12345678, "dw=%d\n", dw
);
815 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
816 size
= type
= dw
= 0xdeadbeef;
817 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
818 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
819 ok(size
== 4, "size=%d\n", size
);
820 ok(type
== REG_BINARY
, "type=%d\n", type
);
821 ok(dw
== 0x12345678, "dw=%d\n", dw
);
823 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
824 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
825 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
826 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
827 ok(size
== 8, "size=%d\n", size
);
828 ok(type
== REG_BINARY
, "type=%d\n", type
);
829 ok(qw
[0] == 0x12345678 &&
830 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
832 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
833 type
= dw
= 0xdeadbeef; size
= 4;
834 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
835 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
836 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
837 ok(size
== 8, "size=%d\n", size
);
839 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
840 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
841 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
842 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
843 ok(size
== 8, "size=%d\n", size
);
844 ok(type
== REG_BINARY
, "type=%d\n", type
);
845 ok(qw
[0] == 0x12345678 &&
846 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
848 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
849 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
850 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
851 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
852 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
853 ok(type
== REG_SZ
, "type=%d\n", type
);
854 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
856 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
857 type
= 0xdeadbeef; size
= 0;
858 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
859 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
860 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
861 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
862 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
863 ok(type
== REG_SZ
, "type=%d\n", type
);
865 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
866 strcpy(buf
, sTestpath1
);
869 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
870 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
871 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
873 size
== 1, /* win2k3 */
875 ok(type
== REG_SZ
, "type=%d\n", type
);
876 ok(!strcmp(sTestpath1
, buf
) ||
878 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
880 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
881 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
882 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
883 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
884 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
885 ok(type
== REG_SZ
, "type=%d\n", type
);
886 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
888 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
890 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
891 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
892 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
893 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
894 (size
== strlen(sTestpath2
)+1),
895 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
897 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
898 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
899 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
900 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
901 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
902 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
903 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
904 ok(type
== REG_SZ
, "type=%d\n", type
);
905 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
907 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
908 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
909 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
910 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
911 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
912 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
913 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
914 ok(type
== REG_SZ
, "type=%d\n", type
);
915 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
917 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
918 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
919 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
920 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
921 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
922 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
923 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
925 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
927 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
928 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
929 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
930 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
931 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
933 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
934 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
935 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
937 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
938 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
939 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
940 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
942 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
943 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
944 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
945 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
946 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
947 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
948 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
949 ok(type
== REG_SZ
, "type=%d\n", type
);
950 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
953 static void test_reg_open_key(void)
956 HKEY hkResult
= NULL
;
957 HKEY hkPreserve
= NULL
;
958 HKEY hkRoot64
= NULL
;
959 HKEY hkRoot32
= NULL
;
961 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
963 EXPLICIT_ACCESSA access
;
965 SECURITY_DESCRIPTOR
*sd
;
967 /* successful open */
968 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
969 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
970 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
971 hkPreserve
= hkResult
;
973 /* open same key twice */
974 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
975 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
976 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
977 ok(hkResult
!= NULL
, "hkResult != NULL\n");
978 RegCloseKey(hkResult
);
980 /* trailing slashes */
981 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test\\\\", &hkResult
);
982 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
983 RegCloseKey(hkResult
);
985 /* open nonexistent key
986 * check that hkResult is set to NULL
988 hkResult
= hkPreserve
;
989 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
990 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
991 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
993 /* open the same nonexistent key again to make sure the key wasn't created */
994 hkResult
= hkPreserve
;
995 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
996 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
997 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
999 /* send in NULL lpSubKey
1000 * check that hkResult receives the value of hKey
1002 hkResult
= hkPreserve
;
1003 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
1004 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1005 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
1007 /* send empty-string in lpSubKey */
1008 hkResult
= hkPreserve
;
1009 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
1010 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1011 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
1013 /* send in NULL lpSubKey and NULL hKey
1014 * hkResult is set to NULL
1016 hkResult
= hkPreserve
;
1017 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
1018 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1019 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
1021 /* only send NULL hKey
1022 * the value of hkResult remains unchanged
1024 hkResult
= hkPreserve
;
1025 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
1026 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1027 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1028 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
1029 RegCloseKey(hkResult
);
1031 /* send in NULL hkResult */
1032 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
1033 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1035 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
1036 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1038 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
1039 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1041 /* beginning backslash character */
1042 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
1043 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
1044 broken(ret
== ERROR_SUCCESS
), /* wow64 */
1045 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1046 if (!ret
) RegCloseKey(hkResult
);
1049 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
1050 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
1051 ret
== ERROR_BAD_PATHNAME
, /* NT */
1052 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1053 RegCloseKey(hkResult
);
1057 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
1058 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1059 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1060 RegCloseKey(hkResult
);
1063 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
1064 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1065 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1066 RegCloseKey(hkResult
);
1068 /* check special HKEYs on 64bit
1069 * only the lower 4 bytes of the supplied key are used
1073 /* HKEY_CURRENT_USER */
1074 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
1075 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1076 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1077 RegCloseKey(hkResult
);
1079 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
1080 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1081 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1082 RegCloseKey(hkResult
);
1084 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1085 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1086 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1087 RegCloseKey(hkResult
);
1089 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
1090 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1091 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1092 RegCloseKey(hkResult
);
1094 /* HKEY_LOCAL_MACHINE */
1095 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1096 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1097 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1098 RegCloseKey(hkResult
);
1101 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1102 * the registry access check is performed correctly. Redirection isn't
1103 * being tested, so the tests don't care about whether the process is
1104 * running under WOW64. */
1105 if (!pIsWow64Process
)
1107 win_skip("WOW64 flags are not recognized\n");
1111 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1112 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1114 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1115 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1117 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1118 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1120 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1121 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1123 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1124 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1126 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1127 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1129 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1130 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1132 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1134 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1135 access
.grfAccessMode
= SET_ACCESS
;
1136 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1137 access
.Trustee
.pMultipleTrustee
= NULL
;
1138 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1139 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1140 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1141 access
.Trustee
.ptstrName
= (char *)world_sid
;
1143 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1144 ok(ret
== ERROR_SUCCESS
,
1145 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1147 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1148 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1150 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1152 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1154 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1158 skip("not enough privileges to modify HKLM\n");
1164 error
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1165 ok(error
== ERROR_SUCCESS
,
1166 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1168 error
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1169 ok(error
== ERROR_SUCCESS
,
1170 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1173 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1174 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1175 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1176 RegCloseKey(hkResult
);
1179 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1180 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1181 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1182 RegCloseKey(hkResult
);
1185 HeapFree(GetProcessHeap(), 0, sd
);
1188 RegDeleteKeyA(hkRoot64
, "");
1189 RegCloseKey(hkRoot64
);
1190 RegDeleteKeyA(hkRoot32
, "");
1191 RegCloseKey(hkRoot32
);
1194 static void test_reg_create_key(void)
1198 HKEY hkRoot64
= NULL
;
1199 HKEY hkRoot32
= NULL
;
1202 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1204 EXPLICIT_ACCESSA access
;
1206 SECURITY_DESCRIPTOR
*sd
;
1208 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1209 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1210 /* should succeed: all versions of Windows ignore the access rights
1211 * to the parent handle */
1212 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1213 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1216 RegDeleteKeyA(hkey2
, "");
1217 RegDeleteKeyA(hkey1
, "");
1221 /* test creation of volatile keys */
1222 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1223 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1224 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1225 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1226 if (!ret
) RegCloseKey( hkey2
);
1227 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1228 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1230 /* should succeed if the key already exists */
1231 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1232 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1235 RegDeleteKeyA(hkey2
, "");
1236 RegDeleteKeyA(hkey1
, "");
1240 /* beginning backslash character */
1241 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1242 if (!(GetVersion() & 0x80000000))
1243 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1245 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1246 RegDeleteKeyA(hkey1
, "");
1250 /* trailing backslash characters */
1251 ret
= RegCreateKeyExA(hkey_main
, "Subkey4\\\\", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1252 ok(ret
== ERROR_SUCCESS
, "RegCreateKeyExA failed with error %d\n", ret
);
1253 RegDeleteKeyA(hkey1
, "");
1256 /* WOW64 flags - open an existing key */
1258 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1259 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1260 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1264 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1265 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1266 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1269 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1270 * the registry access check is performed correctly. Redirection isn't
1271 * being tested, so the tests don't care about whether the process is
1272 * running under WOW64. */
1273 if (!pIsWow64Process
)
1275 win_skip("WOW64 flags are not recognized\n");
1279 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1280 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1282 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1283 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1285 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1286 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1288 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1289 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1291 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1292 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1294 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1295 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1297 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1298 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1300 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1302 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1303 access
.grfAccessMode
= SET_ACCESS
;
1304 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1305 access
.Trustee
.pMultipleTrustee
= NULL
;
1306 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1307 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1308 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1309 access
.Trustee
.ptstrName
= (char *)world_sid
;
1311 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1312 ok(dwRet
== ERROR_SUCCESS
,
1313 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1315 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1316 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1318 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1320 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1322 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1326 skip("not enough privileges to modify HKLM\n");
1330 ret
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1331 ok(ret
== ERROR_SUCCESS
,
1332 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1334 ret
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1335 ok(ret
== ERROR_SUCCESS
,
1336 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1339 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1340 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1341 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1342 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1346 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1347 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1348 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1349 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1353 HeapFree(GetProcessHeap(), 0, sd
);
1356 RegDeleteKeyA(hkRoot64
, "");
1357 RegCloseKey(hkRoot64
);
1358 RegDeleteKeyA(hkRoot32
, "");
1359 RegCloseKey(hkRoot32
);
1362 static void test_reg_close_key(void)
1367 /* successfully close key
1368 * hkHandle remains changed after call to RegCloseKey
1370 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1371 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1372 ret
= RegCloseKey(hkHandle
);
1373 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1375 /* try to close the key twice */
1376 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1377 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1378 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1380 /* try to close a NULL handle */
1381 ret
= RegCloseKey(NULL
);
1382 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1383 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1385 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1386 * win98 doesn't give a new handle when the same key is opened.
1387 * Not re-opening will make some next tests fail.
1389 if (hkey_main
== hkHandle
)
1391 trace("The main handle is most likely closed, so re-opening\n");
1392 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1396 static void test_reg_delete_key(void)
1401 ret
= RegDeleteKeyA(hkey_main
, NULL
);
1403 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1404 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1405 * Not re-creating will make some next tests fail.
1407 if (ret
== ERROR_SUCCESS
)
1409 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1410 " re-creating the main key\n");
1414 ok(ret
== ERROR_INVALID_PARAMETER
||
1415 ret
== ERROR_ACCESS_DENIED
||
1416 ret
== ERROR_BADKEY
, /* Win95 */
1419 ret
= RegCreateKeyA(hkey_main
, "deleteme", &key
);
1420 ok(ret
== ERROR_SUCCESS
, "Could not create key, got %d\n", ret
);
1421 ret
= RegDeleteKeyA(key
, "");
1422 ok(ret
== ERROR_SUCCESS
, "RegDeleteKeyA failed, got %d\n", ret
);
1424 ret
= RegOpenKeyA(hkey_main
, "deleteme", &key
);
1425 ok(ret
== ERROR_FILE_NOT_FOUND
, "Key was not deleted, got %d\n", ret
);
1429 static void test_reg_save_key(void)
1433 ret
= RegSaveKeyA(hkey_main
, "saved_key", NULL
);
1434 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1437 static void test_reg_load_key(void)
1442 ret
= RegLoadKeyA(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1443 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1445 ret
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1446 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1448 RegCloseKey(hkHandle
);
1451 static void test_reg_unload_key(void)
1455 ret
= RegUnLoadKeyA(HKEY_LOCAL_MACHINE
, "Test");
1456 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1458 DeleteFileA("saved_key");
1459 DeleteFileA("saved_key.LOG");
1462 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1464 TOKEN_PRIVILEGES tp
;
1468 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1471 if(!LookupPrivilegeValueA(NULL
, privilege
, &luid
))
1473 CloseHandle(hToken
);
1477 tp
.PrivilegeCount
= 1;
1478 tp
.Privileges
[0].Luid
= luid
;
1481 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1483 tp
.Privileges
[0].Attributes
= 0;
1485 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1486 if (GetLastError() != ERROR_SUCCESS
)
1488 CloseHandle(hToken
);
1492 CloseHandle(hToken
);
1496 /* tests that show that RegConnectRegistry and
1497 OpenSCManager accept computer names without the
1498 \\ prefix (what MSDN says). */
1499 static void test_regconnectregistry( void)
1501 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1502 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1503 DWORD len
= sizeof(compName
) ;
1509 SetLastError(0xdeadbeef);
1510 ret
= GetComputerNameA(compName
, &len
);
1511 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1514 lstrcpyA(netwName
, "\\\\");
1515 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1517 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1519 retl
== ERROR_DLL_INIT_FAILED
||
1520 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1521 "RegConnectRegistryA failed err = %d\n", retl
);
1522 if( !retl
) RegCloseKey( hkey
);
1524 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1526 retl
== ERROR_DLL_INIT_FAILED
||
1527 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1528 "RegConnectRegistryA failed err = %d\n", retl
);
1529 if( !retl
) RegCloseKey( hkey
);
1531 SetLastError(0xdeadbeef);
1532 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1533 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1535 win_skip("OpenSCManagerA is not implemented\n");
1539 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1540 CloseServiceHandle( schnd
);
1542 SetLastError(0xdeadbeef);
1543 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1544 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1545 CloseServiceHandle( schnd
);
1549 static void test_reg_query_value(void)
1556 static const WCHAR expected
[] = {'d','a','t','a',0};
1558 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1559 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1561 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1562 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1564 /* try an invalid hkey */
1565 SetLastError(0xdeadbeef);
1567 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1568 ok(ret
== ERROR_INVALID_HANDLE
||
1569 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1570 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1571 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1572 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1574 /* try a NULL hkey */
1575 SetLastError(0xdeadbeef);
1577 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1578 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1579 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1580 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1582 /* try a NULL value */
1584 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1585 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1586 ok(size
== 5, "Expected 5, got %d\n", size
);
1588 /* try a NULL size */
1589 SetLastError(0xdeadbeef);
1591 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1592 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1593 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1594 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1596 /* try a NULL value and size */
1597 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1598 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1600 /* try a size too small */
1601 SetLastError(0xdeadbeef);
1604 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1605 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1606 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1607 ok(!val
[0], "Expected val to be untouched, got %s\n", val
);
1608 ok(size
== 5, "Expected 5, got %d\n", size
);
1610 /* successfully read the value using 'subkey' */
1612 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1613 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1614 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1615 ok(size
== 5, "Expected 5, got %d\n", size
);
1617 /* successfully read the value using the subkey key */
1619 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1620 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1621 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1622 ok(size
== 5, "Expected 5, got %d\n", size
);
1624 /* unicode - try size too small */
1625 SetLastError(0xdeadbeef);
1628 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1629 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1631 win_skip("RegQueryValueW is not implemented\n");
1634 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1635 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1636 ok(!valW
[0], "Expected valW to be untouched\n");
1637 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1639 /* unicode - try size in WCHARS */
1640 SetLastError(0xdeadbeef);
1641 size
= sizeof(valW
) / sizeof(WCHAR
);
1642 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1643 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1644 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1645 ok(!valW
[0], "Expected valW to be untouched\n");
1646 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1648 /* unicode - successfully read the value */
1649 size
= sizeof(valW
);
1650 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1651 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1652 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1653 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1655 /* unicode - set the value without a NULL terminator */
1656 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1657 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1659 /* unicode - read the unterminated value, value is terminated for us */
1660 memset(valW
, 'a', sizeof(valW
));
1661 size
= sizeof(valW
);
1662 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1663 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1664 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1665 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1668 RegDeleteKeyA(subkey
, "");
1669 RegCloseKey(subkey
);
1672 static void test_string_termination(void)
1676 static const char string
[] = "FullString";
1679 DWORD insize
, outsize
, nsize
;
1681 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1682 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1684 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1685 insize
=sizeof(string
)-1;
1686 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1687 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1689 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1690 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1692 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1693 insize
=sizeof(string
)-2;
1694 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1695 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1697 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1698 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1699 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1701 /* RegQueryValueExA may return a string with no trailing '\0' */
1703 memset(buffer
, 0xbd, sizeof(buffer
));
1704 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1705 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1706 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1707 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1708 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1709 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1711 /* RegQueryValueExA adds a trailing '\0' if there is room */
1713 memset(buffer
, 0xbd, sizeof(buffer
));
1714 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1715 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1716 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1717 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1718 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1719 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1721 /* RegEnumValueA may return a string with no trailing '\0' */
1723 memset(buffer
, 0xbd, sizeof(buffer
));
1725 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1726 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1727 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1728 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1729 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1730 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1731 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1733 /* RegEnumValueA adds a trailing '\0' if there is room */
1735 memset(buffer
, 0xbd, sizeof(buffer
));
1737 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1738 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1739 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1740 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1741 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1742 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1743 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1745 RegDeleteKeyA(subkey
, "");
1746 RegCloseKey(subkey
);
1749 static void test_reg_delete_tree(void)
1751 CHAR buffer
[MAX_PATH
];
1752 HKEY subkey
, subkey2
;
1755 if(!pRegDeleteTreeA
) {
1756 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1760 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1761 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1762 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1763 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1764 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1765 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1766 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1767 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1768 ret
= RegCloseKey(subkey2
);
1769 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1771 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1772 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1773 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1774 "subkey2 was not deleted\n");
1776 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1777 "Default value of subkey not longer present\n");
1779 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1780 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1781 ret
= RegCloseKey(subkey2
);
1782 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1783 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1784 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1785 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1786 "subkey2 was not deleted\n");
1787 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1788 "Default value of subkey not longer present\n");
1790 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1791 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1792 ret
= RegCloseKey(subkey2
);
1793 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1794 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1795 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1796 ret
= RegCloseKey(subkey2
);
1797 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1798 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1799 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1800 ret
= pRegDeleteTreeA(subkey
, NULL
);
1801 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1802 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1803 "subkey was deleted\n");
1804 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1805 "subkey2 was not deleted\n");
1806 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1807 "subkey3 was not deleted\n");
1809 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1810 ok(ret
== ERROR_SUCCESS
,
1811 "Default value of subkey is not present\n");
1812 ok(!buffer
[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1814 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1815 "Value is still present\n");
1817 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1818 ok(ret
== ERROR_FILE_NOT_FOUND
,
1819 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1822 static void test_rw_order(void)
1826 static const char keyname
[] = "test_rw_order";
1828 DWORD values
, value_len
, value_name_max_len
;
1831 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1832 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1833 if(ret
!= ERROR_SUCCESS
) {
1834 skip("Couldn't create key. Skipping.\n");
1838 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1839 "RegSetValueExA for value \"A\" failed\n");
1840 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1841 "RegSetValueExA for value \"C\" failed\n");
1842 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1843 "RegSetValueExA for value \"D\" failed\n");
1844 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1845 "RegSetValueExA for value \"B\" failed\n");
1847 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1848 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1849 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1851 /* Value enumeration preserves RegSetValueEx call order */
1853 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1854 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1856 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1857 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1859 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1860 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1862 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1863 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1865 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1868 static void test_symlinks(void)
1870 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1871 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1873 UNICODE_STRING target_str
;
1877 DWORD target_len
, type
, len
, dw
, err
;
1879 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1881 win_skip( "Can't perform symlink tests\n" );
1885 pRtlFormatCurrentUserKeyPath( &target_str
);
1887 target_len
= target_str
.Length
+ sizeof(targetW
);
1888 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1889 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1890 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1892 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1893 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1894 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1896 /* REG_SZ is not allowed */
1897 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1898 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1899 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1900 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1901 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1902 /* other values are not allowed */
1903 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1904 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1906 /* try opening the target through the link */
1908 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1909 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1911 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1912 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1915 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1916 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1919 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1920 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1922 len
= sizeof(buffer
);
1923 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1924 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1925 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1927 len
= sizeof(buffer
);
1928 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1929 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1931 /* REG_LINK can be created in non-link keys */
1932 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1933 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1934 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1935 len
= sizeof(buffer
);
1936 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1937 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1938 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1939 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1940 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1944 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1945 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1947 len
= sizeof(buffer
);
1948 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1949 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1950 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1952 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1953 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1956 /* now open the symlink itself */
1958 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1959 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1960 len
= sizeof(buffer
);
1961 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1962 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1963 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1966 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1967 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1968 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1969 len
= sizeof(buffer
);
1970 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1971 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1972 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1975 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1976 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1977 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1979 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1980 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1981 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1983 err
= RegDeleteKeyA( hkey_main
, "target" );
1984 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1986 err
= RegDeleteKeyA( hkey_main
, "link" );
1987 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1989 status
= pNtDeleteKey( link
);
1990 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1991 RegCloseKey( link
);
1993 HeapFree( GetProcessHeap(), 0, target
);
1994 pRtlFreeUnicodeString( &target_str
);
1997 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
2000 DWORD err
, type
, dw
, len
= sizeof(dw
);
2002 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2003 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
2004 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
2006 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2007 if (err
== ERROR_FILE_NOT_FOUND
)
2010 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
2015 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
2017 DWORD dw
= get_key_value( root
, name
, flags
);
2018 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
2020 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
2022 static void test_redirection(void)
2024 DWORD err
, type
, dw
, len
;
2025 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
2026 BOOL is_vista
= FALSE
;
2027 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
2032 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
2034 skip( "Not on Wow64, no redirection\n" );
2039 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2040 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
2041 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2043 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2044 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
2045 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2047 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2048 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
2049 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2051 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2052 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
2053 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2056 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2057 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2060 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2061 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2065 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2066 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2067 ok( dw
== 32, "wrong value %u\n", dw
);
2071 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2072 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2073 ok( dw
== 64, "wrong value %u\n", dw
);
2075 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2076 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2077 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2081 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2082 /* the new (and simpler) Win7 mechanism doesn't */
2083 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2085 trace( "using Vista-style Wow6432Node handling\n" );
2088 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2089 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2090 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2091 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2092 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2093 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2097 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
2099 trace( "using Vista-style Wow6432Node handling\n" );
2102 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2103 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2109 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2110 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2111 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2112 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2113 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2114 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2115 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2116 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2117 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
2118 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
2119 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2122 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2123 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2124 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2125 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2126 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2127 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2128 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2129 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2130 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2135 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2136 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2137 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2138 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2139 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2140 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
);
2141 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2142 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2145 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2146 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2147 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2148 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2149 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
);
2150 ok( dw
== 32 || broken(dw
== 64) /* vista */, "wrong value %u\n", dw
);
2151 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2155 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
2156 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2159 /* KEY_WOW64 flags have no effect on 64-bit */
2160 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2161 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2162 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2163 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2167 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2168 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2169 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2170 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2173 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2174 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2175 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2176 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2177 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2178 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2183 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2184 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2185 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2186 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2187 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2188 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2189 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2192 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2193 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2194 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2195 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2196 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2197 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2201 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2202 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2203 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2204 check_key_value( key
, "Winetest", 0, 32 );
2205 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2206 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2211 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2212 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2213 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2214 dw
= get_key_value( key
, "Winetest", 0 );
2215 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2216 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2217 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2220 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2221 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2222 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2223 check_key_value( key
, "Winetest", 0, 32 );
2224 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2225 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2229 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2230 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2231 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2232 check_key_value( key
, "Winetest", 0, ptr_size
);
2233 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2234 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2235 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2236 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2241 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2242 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2243 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2244 dw
= get_key_value( key
, "Winetest", 0 );
2245 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2246 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2247 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2248 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2251 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2252 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2253 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2254 check_key_value( key
, "Winetest", 0, 32 );
2255 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2256 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2260 if (pRegDeleteKeyExA
)
2262 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2263 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2264 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2265 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2266 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2267 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2271 err
= RegDeleteKeyA( key32
, "" );
2272 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2273 err
= RegDeleteKeyA( key64
, "" );
2274 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2275 RegDeleteKeyA( key64
, "" );
2276 RegDeleteKeyA( root64
, "" );
2278 RegCloseKey( key32
);
2279 RegCloseKey( key64
);
2280 RegCloseKey( root32
);
2281 RegCloseKey( root64
);
2283 /* open key in native bit mode */
2284 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2285 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2287 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2289 /* write subkey in opposite bit mode */
2290 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2291 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2293 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2295 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2296 if(err
!= ERROR_SUCCESS
){
2297 win_skip("Can't write to registry\n");
2298 RegCloseKey(op_key
);
2299 RegCloseKey(native
);
2304 /* verify subkey is not present in native mode */
2305 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2306 ok(err
== ERROR_FILE_NOT_FOUND
||
2307 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2310 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2311 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2313 RegCloseKey(op_key
);
2314 RegCloseKey(native
);
2317 static void test_classesroot(void)
2319 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2321 DWORD type
= REG_SZ
;
2322 static CHAR buffer
[8];
2325 /* create a key in the user's classes */
2326 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2329 RegCloseKey( hkey
);
2331 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2332 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2333 if (res
== ERROR_ACCESS_DENIED
)
2335 skip("not enough privileges to add a user class\n");
2338 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2340 /* try to open that key in hkcr */
2341 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2342 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2343 todo_wine
ok(res
== ERROR_SUCCESS
||
2344 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2345 "test key not found in hkcr: %d\n", res
);
2348 skip("HKCR key merging not supported\n");
2350 RegCloseKey( hkey
);
2354 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2356 /* set a value in user's classes */
2357 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2358 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2360 /* try to find the value in hkcr */
2361 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2362 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2363 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2365 /* modify the value in hkcr */
2366 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2367 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2369 /* check if the value is also modified in user's classes */
2370 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2371 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2372 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2374 /* set a value in hkcr */
2375 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2376 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2378 /* try to find the value in user's classes */
2379 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2380 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2381 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2383 /* modify the value in user's classes */
2384 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2385 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2387 /* check if the value is also modified in hkcr */
2388 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2389 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2390 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2395 RegCloseKey( hkey
);
2396 RegCloseKey( hkcr
);
2398 /* create a key in the hklm classes */
2399 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2402 RegCloseKey( hklm
);
2404 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2405 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2406 if (res
== ERROR_ACCESS_DENIED
)
2408 skip("not enough privileges to add a system class\n");
2411 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2413 /* try to open that key in hkcr */
2414 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2415 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2416 ok(res
== ERROR_SUCCESS
,
2417 "test key not found in hkcr: %d\n", res
);
2418 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2422 RegCloseKey( hklm
);
2426 /* set a value in hklm classes */
2427 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2428 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2430 /* try to find the value in hkcr */
2431 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2432 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2433 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2435 /* modify the value in hkcr */
2436 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2437 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2439 /* check that the value is modified in hklm classes */
2440 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2441 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2442 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2444 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2445 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2446 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2448 /* try to open that key in hkcr */
2449 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2450 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2451 ok(res
== ERROR_SUCCESS
,
2452 "test key not found in hkcr: %d\n", res
);
2453 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2455 /* set a value in user's classes */
2456 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2457 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2459 /* try to find the value in hkcr */
2460 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2461 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2462 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2464 /* modify the value in hklm */
2465 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2466 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2468 /* check that the value is not overwritten in hkcr or user's classes */
2469 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2470 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2471 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2472 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2473 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2474 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2476 /* modify the value in hkcr */
2477 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2478 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2480 /* check that the value is overwritten in hklm and user's classes */
2481 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2482 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2483 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2484 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2485 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2486 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2488 /* create a subkey in hklm */
2489 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2490 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2491 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2492 /* try to open that subkey in hkcr */
2493 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2494 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2495 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2497 /* set a value in hklm classes */
2498 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2499 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2501 /* try to find the value in hkcr */
2502 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2503 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2504 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2506 /* modify the value in hkcr */
2507 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2508 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2510 /* check that the value is modified in hklm classes */
2511 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2512 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2513 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2515 /* create a subkey in user's classes */
2516 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2517 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2518 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2520 /* set a value in user's classes */
2521 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2522 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2524 /* try to find the value in hkcr */
2525 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2526 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2527 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2529 /* modify the value in hklm */
2530 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2531 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2533 /* check that the value is not overwritten in hkcr or user's classes */
2534 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2535 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2536 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2537 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2538 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2539 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2541 /* modify the value in hkcr */
2542 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2543 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2545 /* check that the value is not overwritten in hklm, but in user's classes */
2546 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2547 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2548 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2549 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2550 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2551 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2553 /* new subkey in hkcr */
2554 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2555 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2556 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2557 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2558 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2560 /* try to open that new subkey in user's classes and hklm */
2561 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2562 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2564 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2565 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2566 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2568 /* check that the value is present in hklm */
2569 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2570 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2571 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2574 RegCloseKey( hkeysub1
);
2575 RegCloseKey( hklmsub1
);
2577 /* delete subkey1 from hkcr (should point at user's classes) */
2578 res
= RegDeleteKeyA(hkcr
, "subkey1");
2579 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2581 /* confirm key was removed in hkey but not hklm */
2582 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2583 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2584 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2585 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2586 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2588 /* delete subkey1 from hkcr again (which should now point at hklm) */
2589 res
= RegDeleteKeyA(hkcr
, "subkey1");
2590 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2592 /* confirm hkey was removed in hklm */
2593 RegCloseKey( hklmsub1
);
2594 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2595 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2601 delete_key( hkeysub1
);
2602 delete_key( hklmsub1
);
2603 delete_key( hkcrsub1
);
2604 delete_key( hklmsub2
);
2605 delete_key( hkcrsub2
);
2606 RegCloseKey( hkey
);
2607 RegCloseKey( hklm
);
2608 RegCloseKey( hkcr
);
2609 RegCloseKey( hkeysub1
);
2610 RegCloseKey( hklmsub1
);
2611 RegCloseKey( hkcrsub1
);
2612 RegCloseKey( hklmsub2
);
2613 RegCloseKey( hkcrsub2
);
2616 static void test_classesroot_enum(void)
2618 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2620 static CHAR buffer
[2];
2623 /* prepare initial testing env in HKCU */
2624 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2627 RegCloseKey( hkcu
);
2629 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2630 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2632 if (res
!= ERROR_SUCCESS
)
2634 skip("failed to add a user class\n");
2638 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2639 todo_wine
ok(res
== ERROR_SUCCESS
||
2640 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2641 "test key not found in hkcr: %d\n", res
);
2644 skip("HKCR key merging not supported\n");
2646 RegCloseKey( hkcu
);
2650 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2651 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2652 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2653 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2654 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2655 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2656 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2657 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2659 /* test on values in HKCU */
2660 size
= sizeof(buffer
);
2661 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2662 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2663 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2664 size
= sizeof(buffer
);
2665 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2666 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2667 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2668 size
= sizeof(buffer
);
2669 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2670 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2672 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2673 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2674 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2675 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2676 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2677 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2678 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2679 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2681 /* prepare test env in HKLM */
2682 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2685 RegCloseKey( hklm
);
2688 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2689 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2691 if (res
== ERROR_ACCESS_DENIED
)
2693 RegCloseKey( hkcusub
[0] );
2694 RegCloseKey( hkcusub
[1] );
2696 RegCloseKey( hkcu
);
2697 RegCloseKey( hkcr
);
2698 skip("not enough privileges to add a system class\n");
2702 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2703 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2704 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2705 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2706 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2707 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2708 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2709 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2711 /* test on values/keys in both HKCU and HKLM */
2712 size
= sizeof(buffer
);
2713 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2714 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2715 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2716 size
= sizeof(buffer
);
2717 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2718 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2719 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2720 size
= sizeof(buffer
);
2721 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2722 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2723 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2724 size
= sizeof(buffer
);
2725 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2726 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2728 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2729 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2730 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2731 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2732 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2733 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2734 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2735 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2736 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2737 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2738 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2740 /* delete values/keys from HKCU to test only on HKLM */
2741 RegCloseKey( hkcusub
[0] );
2742 RegCloseKey( hkcusub
[1] );
2744 RegCloseKey( hkcu
);
2746 size
= sizeof(buffer
);
2747 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2748 ok(res
== ERROR_KEY_DELETED
||
2749 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2750 "expected ERROR_KEY_DELETED, got %d\n", res
);
2751 size
= sizeof(buffer
);
2752 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2753 ok(res
== ERROR_KEY_DELETED
||
2754 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2755 "expected ERROR_KEY_DELETED, got %d\n", res
);
2757 /* reopen HKCR handle */
2758 RegCloseKey( hkcr
);
2759 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2760 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2761 if (res
) goto cleanup
;
2763 /* test on values/keys in HKLM */
2764 size
= sizeof(buffer
);
2765 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2766 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2767 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2768 size
= sizeof(buffer
);
2769 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2770 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2771 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2772 size
= sizeof(buffer
);
2773 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2774 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2776 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2777 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2778 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2779 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2780 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2781 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2782 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2783 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2786 RegCloseKey( hklmsub
[0] );
2787 RegCloseKey( hklmsub
[1] );
2789 RegCloseKey( hklm
);
2790 RegCloseKey( hkcr
);
2793 static void test_classesroot_mask(void)
2798 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
2799 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2800 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
2801 "hkcr mask not set in %p\n", hkey
);
2802 RegCloseKey( hkey
);
2804 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
2805 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2806 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2807 RegCloseKey( hkey
);
2809 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
2810 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2811 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2812 RegCloseKey( hkey
);
2814 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
2815 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2816 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2817 RegCloseKey( hkey
);
2819 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
2820 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2821 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2822 RegCloseKey( hkey
);
2825 static void test_deleted_key(void)
2829 DWORD val_count
, type
;
2832 /* Open the test key, then delete it while it's open */
2833 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2835 delete_key( hkey_main
);
2837 val_count
= sizeof(value
);
2839 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2840 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2842 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2843 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2845 val_count
= sizeof(value
);
2847 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2848 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2850 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2851 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2853 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2854 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2856 RegCloseKey( hkey2
);
2858 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2859 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2861 RegCloseKey( hkey2
);
2863 res
= RegFlushKey( hkey
);
2864 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2866 RegCloseKey( hkey
);
2871 static void test_delete_value(void)
2876 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2877 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2879 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2880 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2882 res
= RegDeleteValueA( hkey_main
, "test" );
2883 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2885 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2886 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2888 res
= RegDeleteValueA( hkey_main
, "test" );
2889 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2891 memset(longname
, 'a', 400);
2893 res
= RegDeleteValueA( hkey_main
, longname
);
2894 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2895 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2898 static void test_delete_key_value(void)
2903 if (!pRegDeleteKeyValueA
)
2905 win_skip("RegDeleteKeyValue is not available.\n");
2909 ret
= pRegDeleteKeyValueA(NULL
, NULL
, NULL
);
2910 ok(ret
== ERROR_INVALID_HANDLE
, "got %d\n", ret
);
2912 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, NULL
);
2913 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2915 ret
= RegSetValueExA(hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2916 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2918 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2919 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2921 /* NULL subkey name means delete from open key */
2922 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, "test");
2923 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2925 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2926 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2928 /* now with real subkey */
2929 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &subkey
, NULL
);
2930 ok(!ret
, "failed with error %d\n", ret
);
2932 ret
= RegSetValueExA(subkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2933 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2935 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
2936 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2938 ret
= pRegDeleteKeyValueA(hkey_main
, "Subkey1", "test");
2939 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2941 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
2942 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2944 RegDeleteKeyA(subkey
, "");
2945 RegCloseKey(subkey
);
2948 START_TEST(registry
)
2950 /* Load pointers for functions that are not available in all Windows versions */
2956 create_test_entries();
2958 test_query_value_ex();
2960 test_reg_open_key();
2961 test_reg_create_key();
2962 test_reg_close_key();
2963 test_reg_delete_key();
2964 test_reg_query_value();
2965 test_string_termination();
2969 test_classesroot_enum();
2970 test_classesroot_mask();
2972 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2973 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2974 set_privileges(SE_RESTORE_NAME
, TRUE
))
2976 test_reg_save_key();
2977 test_reg_load_key();
2978 test_reg_unload_key();
2980 set_privileges(SE_BACKUP_NAME
, FALSE
);
2981 set_privileges(SE_RESTORE_NAME
, FALSE
);
2984 test_reg_delete_tree();
2987 test_delete_value();
2988 test_delete_key_value();
2991 delete_key( hkey_main
);
2993 test_regconnectregistry();