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_reg_query_info(void)
1677 char classbuffer
[32];
1678 WCHAR classbufferW
[32];
1679 char expectbuffer
[32];
1680 WCHAR expectbufferW
[32];
1681 char subkey_class
[] = "subkey class";
1682 WCHAR subkey_classW
[] = {'s','u','b','k','e','y',' ','c','l','a','s','s',0};
1683 char subsubkey_class
[] = "subsubkey class";
1685 DWORD subkeys
, maxsubkeylen
, maxclasslen
;
1686 DWORD values
, maxvaluenamelen
, maxvaluelen
;
1690 ret
= RegCreateKeyExA(hkey_main
, "subkey", 0, subkey_class
, 0, KEY_ALL_ACCESS
, NULL
, &subkey
, NULL
);
1691 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1693 /* all parameters NULL */
1694 ret
= RegQueryInfoKeyA(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1695 ok(ret
== ERROR_INVALID_HANDLE
, "ret = %d\n", ret
);
1697 ret
= RegQueryInfoKeyW(NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1698 ok(ret
== ERROR_INVALID_HANDLE
, "ret = %d\n", ret
);
1700 /* not requesting any information */
1701 ret
= RegQueryInfoKeyA(subkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1702 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1704 ret
= RegQueryInfoKeyW(subkey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1705 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1707 /* class without length is invalid */
1708 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1709 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1710 ok(ret
== ERROR_INVALID_PARAMETER
, "ret = %d\n", ret
);
1711 ok(classbuffer
[0] == 0x55, "classbuffer[0] = 0x%x\n", classbuffer
[0]);
1713 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1714 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1715 ok(ret
== ERROR_INVALID_PARAMETER
, "ret = %d\n", ret
);
1716 ok(classbufferW
[0] == 0x5555, "classbufferW[0] = 0x%x\n", classbufferW
[0]);
1719 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1720 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1721 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1722 ok(subkeys
== 0, "subkeys = %u\n", subkeys
);
1723 ok(maxsubkeylen
== 0, "maxsubkeylen = %u\n", maxsubkeylen
);
1724 ok(maxclasslen
== 0, "maxclasslen = %u\n", maxclasslen
);
1725 ok(values
== 0, "values = %u\n", values
);
1726 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1727 ok(maxvaluelen
== 0, "maxvaluelen = %u\n", maxvaluelen
);
1728 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1729 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1730 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1732 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1733 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1734 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1735 ok(subkeys
== 0, "subkeys = %u\n", subkeys
);
1736 ok(maxsubkeylen
== 0, "maxsubkeylen = %u\n", maxsubkeylen
);
1737 ok(maxclasslen
== 0, "maxclasslen = %u\n", maxclasslen
);
1738 ok(values
== 0, "values = %u\n", values
);
1739 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1740 ok(maxvaluelen
== 0, "maxvaluelen = %u\n", maxvaluelen
);
1741 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1742 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1743 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1745 ret
= RegCreateKeyExA(subkey
, "subsubkey", 0, subsubkey_class
, 0, KEY_ALL_ACCESS
, NULL
, &subsubkey
, NULL
);
1746 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1748 ret
= RegSetValueExA(subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"data", 5);
1749 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1751 /* with subkey & default value */
1752 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1753 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1754 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1755 ok(subkeys
== 1, "subkeys = %u\n", subkeys
);
1756 ok(maxsubkeylen
== strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen
);
1757 ok(maxclasslen
== strlen(subsubkey_class
), "maxclasslen = %u\n", maxclasslen
);
1758 ok(values
== 1, "values = %u\n", values
);
1759 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1760 ok(maxvaluelen
== sizeof("data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1761 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1762 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1763 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1765 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1766 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1767 ok(classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1768 ok(subkeys
== 1, "subkeys = %u\n", subkeys
);
1769 ok(maxsubkeylen
== strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen
);
1770 ok(maxclasslen
== strlen(subsubkey_class
), "maxclasslen = %u\n", maxclasslen
);
1771 ok(values
== 1, "values = %u\n", values
);
1772 ok(maxvaluenamelen
== 0, "maxvaluenamelen = %u\n", maxvaluenamelen
);
1773 ok(maxvaluelen
== sizeof("data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1774 ok(sdlen
!= 0, "sdlen = %u\n", sdlen
);
1775 ok(lastwrite
.dwLowDateTime
!= 0, "lastwrite.dwLowDateTime = %u\n", lastwrite
.dwLowDateTime
);
1776 ok(lastwrite
.dwHighDateTime
!= 0, "lastwrite.dwHighDateTime = %u\n", lastwrite
.dwHighDateTime
);
1778 ret
= RegSetValueExA(subkey
, "value one", 0, REG_SZ
, (const BYTE
*)"first value data", 17);
1779 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1781 ret
= RegSetValueExA(subkey
, "value 2", 0, REG_SZ
, (const BYTE
*)"second value data", 18);
1782 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1784 /* with named value */
1785 ret
= RegQueryInfoKeyA(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1786 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1787 ok(values
== 3, "values = %u\n", values
);
1788 ok(maxvaluenamelen
== strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen
);
1789 ok(maxvaluelen
== sizeof("second value data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1791 ret
= RegQueryInfoKeyW(subkey
, NULL
, &classlen
, NULL
, &subkeys
, &maxsubkeylen
, &maxclasslen
, &values
, &maxvaluenamelen
, &maxvaluelen
, &sdlen
, &lastwrite
);
1792 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1793 ok(values
== 3, "values = %u\n", values
);
1794 ok(maxvaluenamelen
== strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen
);
1795 ok(maxvaluelen
== sizeof("second value data") * sizeof(WCHAR
), "maxvaluelen = %u\n", maxvaluelen
);
1797 /* class name with zero size buffer */
1798 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1800 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1801 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1802 ok(classlen
== strlen(subkey_class
) /* win2k */ ||
1803 classlen
== 0, "classlen = %u\n", classlen
);
1804 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1805 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)), "classbuffer was modified\n");
1807 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1809 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1810 todo_wine
ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1811 ok(classlen
== strlen(subkey_class
) /* win2k */ ||
1812 classlen
== 0, "classlen = %u\n", classlen
);
1813 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1814 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1816 /* class name with one char buffer */
1817 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1819 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1820 ok(ret
== ERROR_MORE_DATA
, "ret = %d\n", ret
);
1821 todo_wine
ok(classlen
== 0, "classlen = %u\n", classlen
);
1822 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1823 expectbuffer
[0] = 0;
1824 todo_wine
ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)), "classbuffer was modified\n");
1826 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1828 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1829 todo_wine
ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "ret = %d\n", ret
);
1830 ok(classlen
== 0 /* win8 */ ||
1831 classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1832 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1833 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1835 /* class name with buffer one char too small */
1836 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1837 classlen
= sizeof(subkey_class
) - 1;
1838 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1839 ok(ret
== ERROR_MORE_DATA
, "ret = %d\n", ret
);
1840 todo_wine
ok(classlen
== sizeof(subkey_class
) - 2, "classlen = %u\n", classlen
);
1841 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1842 strcpy(expectbuffer
, subkey_class
);
1843 expectbuffer
[sizeof(subkey_class
) - 2] = 0;
1844 expectbuffer
[sizeof(subkey_class
) - 1] = 0x55;
1845 todo_wine
ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)),
1846 "classbuffer = %.*s, expected %s\n",
1847 (int)sizeof(classbuffer
), classbuffer
, expectbuffer
);
1849 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1850 classlen
= sizeof(subkey_class
) - 1;
1851 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1852 todo_wine
ok(ret
== ERROR_INSUFFICIENT_BUFFER
, "ret = %d\n", ret
);
1853 ok(classlen
== sizeof(subkey_class
) - 2 /* win8 */ ||
1854 classlen
== strlen(subkey_class
), "classlen = %u\n", classlen
);
1855 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1856 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)), "classbufferW was modified\n");
1858 /* class name with large enough buffer */
1859 memset(classbuffer
, 0x55, sizeof(classbuffer
));
1860 classlen
= sizeof(subkey_class
);
1861 ret
= RegQueryInfoKeyA(subkey
, classbuffer
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1862 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1863 ok(classlen
== sizeof(subkey_class
) - 1, "classlen = %u\n", classlen
);
1864 memset(expectbuffer
, 0x55, sizeof(expectbuffer
));
1865 strcpy(expectbuffer
, subkey_class
);
1866 ok(!memcmp(classbuffer
, expectbuffer
, sizeof(classbuffer
)),
1867 "classbuffer = \"%.*s\", expected %s\n",
1868 (int)sizeof(classbuffer
), classbuffer
, expectbuffer
);
1870 memset(classbufferW
, 0x55, sizeof(classbufferW
));
1871 classlen
= sizeof(subkey_class
);
1872 ret
= RegQueryInfoKeyW(subkey
, classbufferW
, &classlen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1873 ok(ret
== ERROR_SUCCESS
, "ret = %d\n", ret
);
1874 ok(classlen
== sizeof(subkey_class
) - 1, "classlen = %u\n", classlen
);
1875 memset(expectbufferW
, 0x55, sizeof(expectbufferW
));
1876 lstrcpyW(expectbufferW
, subkey_classW
);
1877 ok(!memcmp(classbufferW
, expectbufferW
, sizeof(classbufferW
)),
1878 "classbufferW = %s, expected %s\n",
1879 wine_dbgstr_wn(classbufferW
, sizeof(classbufferW
) / sizeof(WCHAR
)), wine_dbgstr_w(expectbufferW
));
1881 RegDeleteKeyA(subsubkey
, "");
1882 RegCloseKey(subsubkey
);
1883 RegDeleteKeyA(subkey
, "");
1884 RegCloseKey(subkey
);
1887 static void test_string_termination(void)
1891 static const char string
[] = "FullString";
1894 DWORD insize
, outsize
, nsize
;
1896 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1897 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1899 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1900 insize
=sizeof(string
)-1;
1901 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1902 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1904 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1905 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1907 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1908 insize
=sizeof(string
)-2;
1909 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1910 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1912 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1913 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1914 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1916 /* RegQueryValueExA may return a string with no trailing '\0' */
1918 memset(buffer
, 0xbd, sizeof(buffer
));
1919 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1920 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1921 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1922 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1923 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1924 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1926 /* RegQueryValueExA adds a trailing '\0' if there is room */
1928 memset(buffer
, 0xbd, sizeof(buffer
));
1929 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1930 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1931 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1932 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1933 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1934 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1936 /* RegEnumValueA may return a string with no trailing '\0' */
1938 memset(buffer
, 0xbd, sizeof(buffer
));
1940 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1941 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1942 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1943 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1944 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1945 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1946 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1948 /* RegEnumValueA adds a trailing '\0' if there is room */
1950 memset(buffer
, 0xbd, sizeof(buffer
));
1952 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1953 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1954 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1955 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1956 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1957 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1958 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1960 RegDeleteKeyA(subkey
, "");
1961 RegCloseKey(subkey
);
1964 static void test_reg_delete_tree(void)
1966 CHAR buffer
[MAX_PATH
];
1967 HKEY subkey
, subkey2
;
1970 if(!pRegDeleteTreeA
) {
1971 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1975 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1976 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1977 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1978 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1979 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1980 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1981 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1982 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1983 ret
= RegCloseKey(subkey2
);
1984 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1986 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1987 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1988 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1989 "subkey2 was not deleted\n");
1991 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1992 "Default value of subkey not longer present\n");
1994 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1995 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1996 ret
= RegCloseKey(subkey2
);
1997 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1998 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1999 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2000 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
2001 "subkey2 was not deleted\n");
2002 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
2003 "Default value of subkey not longer present\n");
2005 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
2006 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2007 ret
= RegCloseKey(subkey2
);
2008 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2009 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
2010 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2011 ret
= RegCloseKey(subkey2
);
2012 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2013 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
2014 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2015 ret
= pRegDeleteTreeA(subkey
, NULL
);
2016 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
2017 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
2018 "subkey was deleted\n");
2019 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
2020 "subkey2 was not deleted\n");
2021 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
2022 "subkey3 was not deleted\n");
2024 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
2025 ok(ret
== ERROR_SUCCESS
,
2026 "Default value of subkey is not present\n");
2027 ok(!buffer
[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
2029 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
2030 "Value is still present\n");
2032 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
2033 ok(ret
== ERROR_FILE_NOT_FOUND
,
2034 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
2037 static void test_rw_order(void)
2041 static const char keyname
[] = "test_rw_order";
2043 DWORD values
, value_len
, value_name_max_len
;
2046 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
2047 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
2048 if(ret
!= ERROR_SUCCESS
) {
2049 skip("Couldn't create key. Skipping.\n");
2053 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2054 "RegSetValueExA for value \"A\" failed\n");
2055 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2056 "RegSetValueExA for value \"C\" failed\n");
2057 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2058 "RegSetValueExA for value \"D\" failed\n");
2059 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
2060 "RegSetValueExA for value \"B\" failed\n");
2062 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
2063 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
2064 ok(values
== 4, "Expected 4 values, got %u\n", values
);
2066 /* Value enumeration preserves RegSetValueEx call order */
2068 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2069 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
2071 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2072 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
2074 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2075 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
2077 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
2078 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
2080 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
2083 static void test_symlinks(void)
2085 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
2086 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
2088 UNICODE_STRING target_str
;
2092 DWORD target_len
, type
, len
, dw
, err
;
2094 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
2096 win_skip( "Can't perform symlink tests\n" );
2100 pRtlFormatCurrentUserKeyPath( &target_str
);
2102 target_len
= target_str
.Length
+ sizeof(targetW
);
2103 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
2104 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
2105 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
2107 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
2108 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
2109 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
2111 /* REG_SZ is not allowed */
2112 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
2113 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
2114 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
2115 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2116 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2117 /* other values are not allowed */
2118 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2119 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
2121 /* try opening the target through the link */
2123 err
= RegOpenKeyA( hkey_main
, "link", &key
);
2124 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
2126 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2127 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2130 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2131 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2134 err
= RegOpenKeyA( hkey_main
, "link", &key
);
2135 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
2137 len
= sizeof(buffer
);
2138 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
2139 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
2140 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
2142 len
= sizeof(buffer
);
2143 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2144 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
2146 /* REG_LINK can be created in non-link keys */
2147 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
2148 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
2149 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
2150 len
= sizeof(buffer
);
2151 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2152 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2153 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2154 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
2155 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
2159 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2160 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2162 len
= sizeof(buffer
);
2163 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
2164 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2165 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
2167 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2168 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
2171 /* now open the symlink itself */
2173 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
2174 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
2175 len
= sizeof(buffer
);
2176 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2177 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2178 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2181 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
2182 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2183 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
2184 len
= sizeof(buffer
);
2185 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
2186 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
2187 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
2190 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
2191 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2192 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
2194 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
2195 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2196 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
2198 err
= RegDeleteKeyA( hkey_main
, "target" );
2199 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
2201 err
= RegDeleteKeyA( hkey_main
, "link" );
2202 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
2204 status
= pNtDeleteKey( link
);
2205 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
2206 RegCloseKey( link
);
2208 HeapFree( GetProcessHeap(), 0, target
);
2209 pRtlFreeUnicodeString( &target_str
);
2212 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
2215 DWORD err
, type
, dw
, len
= sizeof(dw
);
2217 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2218 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
2219 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
2221 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2222 if (err
== ERROR_FILE_NOT_FOUND
)
2225 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
2230 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
2232 DWORD dw
= get_key_value( root
, name
, flags
);
2233 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
2235 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
2237 static void test_redirection(void)
2239 DWORD err
, type
, dw
, len
;
2240 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
2241 BOOL is_vista
= FALSE
;
2242 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
2247 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
2249 skip( "Not on Wow64, no redirection\n" );
2254 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2255 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
2256 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2258 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2259 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
2260 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2262 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2263 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
2264 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2266 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
2267 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
2268 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2271 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2272 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2275 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
2276 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
2280 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2281 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2282 ok( dw
== 32, "wrong value %u\n", dw
);
2286 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2287 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2288 ok( dw
== 64, "wrong value %u\n", dw
);
2290 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2291 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2292 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2296 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2297 /* the new (and simpler) Win7 mechanism doesn't */
2298 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2300 trace( "using Vista-style Wow6432Node handling\n" );
2303 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2304 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2305 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2306 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2307 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2308 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2312 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
2314 trace( "using Vista-style Wow6432Node handling\n" );
2317 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2318 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2324 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2325 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2326 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2327 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2328 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2329 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2330 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2331 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2332 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
2333 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
2334 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2337 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2338 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2339 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2340 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2341 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2342 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2343 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2344 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2345 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2350 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2351 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2352 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2353 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2354 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2355 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
);
2356 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2357 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2360 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2361 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2362 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2363 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2364 dw
= get_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
);
2365 ok( dw
== 32 || broken(dw
== 64) /* vista */, "wrong value %u\n", dw
);
2366 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2370 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
2371 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2374 /* KEY_WOW64 flags have no effect on 64-bit */
2375 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2376 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2377 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2378 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2382 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2383 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2384 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2385 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2388 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2389 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2390 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2391 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2392 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2393 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2398 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2399 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2400 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2401 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2402 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2403 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2404 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2407 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2408 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2409 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2410 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2411 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2412 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2416 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2417 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2418 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2419 check_key_value( key
, "Winetest", 0, 32 );
2420 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2421 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2426 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2427 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2428 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2429 dw
= get_key_value( key
, "Winetest", 0 );
2430 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2431 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2432 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2435 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2436 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2437 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2438 check_key_value( key
, "Winetest", 0, 32 );
2439 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2440 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2444 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2445 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2446 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2447 check_key_value( key
, "Winetest", 0, ptr_size
);
2448 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2449 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2450 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2451 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2456 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2457 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2458 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2459 dw
= get_key_value( key
, "Winetest", 0 );
2460 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2461 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2462 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2463 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2466 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2467 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2468 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2469 check_key_value( key
, "Winetest", 0, 32 );
2470 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2471 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2475 if (pRegDeleteKeyExA
)
2477 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2478 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2479 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2480 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2481 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2482 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2486 err
= RegDeleteKeyA( key32
, "" );
2487 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2488 err
= RegDeleteKeyA( key64
, "" );
2489 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2490 RegDeleteKeyA( key64
, "" );
2491 RegDeleteKeyA( root64
, "" );
2493 RegCloseKey( key32
);
2494 RegCloseKey( key64
);
2495 RegCloseKey( root32
);
2496 RegCloseKey( root64
);
2498 /* open key in native bit mode */
2499 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2500 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2502 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2504 /* write subkey in opposite bit mode */
2505 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2506 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2508 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2510 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2511 if(err
!= ERROR_SUCCESS
){
2512 win_skip("Can't write to registry\n");
2513 RegCloseKey(op_key
);
2514 RegCloseKey(native
);
2519 /* verify subkey is not present in native mode */
2520 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2521 ok(err
== ERROR_FILE_NOT_FOUND
||
2522 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2525 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2526 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2528 RegCloseKey(op_key
);
2529 RegCloseKey(native
);
2532 static void test_classesroot(void)
2534 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2536 DWORD type
= REG_SZ
;
2537 static CHAR buffer
[8];
2540 /* create a key in the user's classes */
2541 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2544 RegCloseKey( hkey
);
2546 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2547 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2548 if (res
== ERROR_ACCESS_DENIED
)
2550 skip("not enough privileges to add a user class\n");
2553 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2555 /* try to open that key in hkcr */
2556 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2557 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2558 todo_wine
ok(res
== ERROR_SUCCESS
||
2559 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2560 "test key not found in hkcr: %d\n", res
);
2563 skip("HKCR key merging not supported\n");
2565 RegCloseKey( hkey
);
2569 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2571 /* set a value in user's classes */
2572 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2573 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2575 /* try to find the value in hkcr */
2576 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2577 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2578 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2580 /* modify the value in hkcr */
2581 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2582 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2584 /* check if the value is also modified in user's classes */
2585 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2586 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2587 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2589 /* set a value in hkcr */
2590 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2591 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2593 /* try to find the value in user's classes */
2594 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2595 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2596 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2598 /* modify the value in user's classes */
2599 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2600 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2602 /* check if the value is also modified in hkcr */
2603 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2604 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2605 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2610 RegCloseKey( hkey
);
2611 RegCloseKey( hkcr
);
2613 /* create a key in the hklm classes */
2614 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2617 RegCloseKey( hklm
);
2619 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2620 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2621 if (res
== ERROR_ACCESS_DENIED
)
2623 skip("not enough privileges to add a system class\n");
2626 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2628 /* try to open that key in hkcr */
2629 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2630 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2631 ok(res
== ERROR_SUCCESS
,
2632 "test key not found in hkcr: %d\n", res
);
2633 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2637 RegCloseKey( hklm
);
2641 /* set a value in hklm classes */
2642 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2643 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2645 /* try to find the value in hkcr */
2646 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2647 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2648 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2650 /* modify the value in hkcr */
2651 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2652 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2654 /* check that the value is modified in hklm classes */
2655 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2656 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2657 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2659 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2660 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2661 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2663 /* try to open that key in hkcr */
2664 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2665 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2666 ok(res
== ERROR_SUCCESS
,
2667 "test key not found in hkcr: %d\n", res
);
2668 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2670 /* set a value in user's classes */
2671 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2672 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2674 /* try to find the value in hkcr */
2675 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2676 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2677 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2679 /* modify the value in hklm */
2680 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2681 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2683 /* check that the value is not overwritten in hkcr or user's classes */
2684 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2685 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2686 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2687 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2688 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2689 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2691 /* modify the value in hkcr */
2692 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2693 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2695 /* check that the value is overwritten in hklm and user's classes */
2696 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2697 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2698 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2699 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2700 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2701 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2703 /* create a subkey in hklm */
2704 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2705 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2706 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2707 /* try to open that subkey in hkcr */
2708 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2709 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2710 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2712 /* set a value in hklm classes */
2713 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2714 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2716 /* try to find the value in hkcr */
2717 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2718 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2719 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2721 /* modify the value in hkcr */
2722 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2723 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2725 /* check that the value is modified in hklm classes */
2726 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2727 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2728 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2730 /* create a subkey in user's classes */
2731 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2732 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2733 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2735 /* set a value in user's classes */
2736 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2737 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2739 /* try to find the value in hkcr */
2740 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2741 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2742 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2744 /* modify the value in hklm */
2745 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2746 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2748 /* check that the value is not overwritten in hkcr or user's classes */
2749 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2750 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2751 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2752 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2753 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2754 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2756 /* modify the value in hkcr */
2757 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2758 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2760 /* check that the value is not overwritten in hklm, but in user's classes */
2761 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2762 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2763 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2764 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2765 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2766 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2768 /* new subkey in hkcr */
2769 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2770 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2771 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2772 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2773 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2775 /* try to open that new subkey in user's classes and hklm */
2776 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2777 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2779 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2780 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2781 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2783 /* check that the value is present in hklm */
2784 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2785 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2786 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2789 RegCloseKey( hkeysub1
);
2790 RegCloseKey( hklmsub1
);
2792 /* delete subkey1 from hkcr (should point at user's classes) */
2793 res
= RegDeleteKeyA(hkcr
, "subkey1");
2794 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2796 /* confirm key was removed in hkey but not hklm */
2797 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2798 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2799 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2800 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2801 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2803 /* delete subkey1 from hkcr again (which should now point at hklm) */
2804 res
= RegDeleteKeyA(hkcr
, "subkey1");
2805 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2807 /* confirm hkey was removed in hklm */
2808 RegCloseKey( hklmsub1
);
2809 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2810 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2816 delete_key( hkeysub1
);
2817 delete_key( hklmsub1
);
2818 delete_key( hkcrsub1
);
2819 delete_key( hklmsub2
);
2820 delete_key( hkcrsub2
);
2821 RegCloseKey( hkey
);
2822 RegCloseKey( hklm
);
2823 RegCloseKey( hkcr
);
2824 RegCloseKey( hkeysub1
);
2825 RegCloseKey( hklmsub1
);
2826 RegCloseKey( hkcrsub1
);
2827 RegCloseKey( hklmsub2
);
2828 RegCloseKey( hkcrsub2
);
2831 static void test_classesroot_enum(void)
2833 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2835 static CHAR buffer
[2];
2838 /* prepare initial testing env in HKCU */
2839 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2842 RegCloseKey( hkcu
);
2844 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2845 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2847 if (res
!= ERROR_SUCCESS
)
2849 skip("failed to add a user class\n");
2853 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2854 todo_wine
ok(res
== ERROR_SUCCESS
||
2855 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2856 "test key not found in hkcr: %d\n", res
);
2859 skip("HKCR key merging not supported\n");
2861 RegCloseKey( hkcu
);
2865 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2866 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2867 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2868 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2869 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2870 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2871 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2872 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2874 /* test on values in HKCU */
2875 size
= sizeof(buffer
);
2876 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2877 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2878 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2879 size
= sizeof(buffer
);
2880 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2881 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2882 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2883 size
= sizeof(buffer
);
2884 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2885 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2887 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2888 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2889 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2890 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2891 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2892 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2893 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2894 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2896 /* prepare test env in HKLM */
2897 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2900 RegCloseKey( hklm
);
2903 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2904 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2906 if (res
== ERROR_ACCESS_DENIED
)
2908 RegCloseKey( hkcusub
[0] );
2909 RegCloseKey( hkcusub
[1] );
2911 RegCloseKey( hkcu
);
2912 RegCloseKey( hkcr
);
2913 skip("not enough privileges to add a system class\n");
2917 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2918 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2919 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2920 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2921 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2922 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2923 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2924 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2926 /* test on values/keys in both HKCU and HKLM */
2927 size
= sizeof(buffer
);
2928 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2929 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2930 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2931 size
= sizeof(buffer
);
2932 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2933 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2934 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2935 size
= sizeof(buffer
);
2936 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2937 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2938 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2939 size
= sizeof(buffer
);
2940 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2941 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2943 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2944 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2945 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2946 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2947 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2948 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2949 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2950 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2951 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2952 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2953 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2955 /* delete values/keys from HKCU to test only on HKLM */
2956 RegCloseKey( hkcusub
[0] );
2957 RegCloseKey( hkcusub
[1] );
2959 RegCloseKey( hkcu
);
2961 size
= sizeof(buffer
);
2962 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2963 ok(res
== ERROR_KEY_DELETED
||
2964 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2965 "expected ERROR_KEY_DELETED, got %d\n", res
);
2966 size
= sizeof(buffer
);
2967 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2968 ok(res
== ERROR_KEY_DELETED
||
2969 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2970 "expected ERROR_KEY_DELETED, got %d\n", res
);
2972 /* reopen HKCR handle */
2973 RegCloseKey( hkcr
);
2974 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2975 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2976 if (res
) goto cleanup
;
2978 /* test on values/keys in HKLM */
2979 size
= sizeof(buffer
);
2980 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2981 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2982 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2983 size
= sizeof(buffer
);
2984 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2985 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2986 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2987 size
= sizeof(buffer
);
2988 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2989 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2991 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2992 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2993 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2994 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2995 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2996 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2997 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2998 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
3001 RegCloseKey( hklmsub
[0] );
3002 RegCloseKey( hklmsub
[1] );
3004 RegCloseKey( hklm
);
3005 RegCloseKey( hkcr
);
3008 static void test_classesroot_mask(void)
3013 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
3014 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3015 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
3016 "hkcr mask not set in %p\n", hkey
);
3017 RegCloseKey( hkey
);
3019 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
3020 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3021 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3022 RegCloseKey( hkey
);
3024 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
3025 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3026 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3027 RegCloseKey( hkey
);
3029 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
3030 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3031 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3032 RegCloseKey( hkey
);
3034 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
3035 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
3036 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
3037 RegCloseKey( hkey
);
3040 static void test_deleted_key(void)
3044 DWORD val_count
, type
;
3047 /* Open the test key, then delete it while it's open */
3048 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
3050 delete_key( hkey_main
);
3052 val_count
= sizeof(value
);
3054 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
3055 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3057 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
3058 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3060 val_count
= sizeof(value
);
3062 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
3063 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3065 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3066 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3068 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
3069 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3071 RegCloseKey( hkey2
);
3073 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
3074 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3076 RegCloseKey( hkey2
);
3078 res
= RegFlushKey( hkey
);
3079 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
3081 RegCloseKey( hkey
);
3086 static void test_delete_value(void)
3091 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
3092 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3094 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3095 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3097 res
= RegDeleteValueA( hkey_main
, "test" );
3098 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
3100 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3101 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3103 res
= RegDeleteValueA( hkey_main
, "test" );
3104 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3106 memset(longname
, 'a', 400);
3108 res
= RegDeleteValueA( hkey_main
, longname
);
3109 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
3110 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
3113 static void test_delete_key_value(void)
3118 if (!pRegDeleteKeyValueA
)
3120 win_skip("RegDeleteKeyValue is not available.\n");
3124 ret
= pRegDeleteKeyValueA(NULL
, NULL
, NULL
);
3125 ok(ret
== ERROR_INVALID_HANDLE
, "got %d\n", ret
);
3127 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, NULL
);
3128 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3130 ret
= RegSetValueExA(hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3131 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3133 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3134 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3136 /* NULL subkey name means delete from open key */
3137 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, "test");
3138 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3140 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
3141 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3143 /* now with real subkey */
3144 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &subkey
, NULL
);
3145 ok(!ret
, "failed with error %d\n", ret
);
3147 ret
= RegSetValueExA(subkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
3148 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3150 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
3151 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3153 ret
= pRegDeleteKeyValueA(hkey_main
, "Subkey1", "test");
3154 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
3156 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
3157 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
3159 RegDeleteKeyA(subkey
, "");
3160 RegCloseKey(subkey
);
3163 START_TEST(registry
)
3165 /* Load pointers for functions that are not available in all Windows versions */
3171 create_test_entries();
3173 test_query_value_ex();
3175 test_reg_open_key();
3176 test_reg_create_key();
3177 test_reg_close_key();
3178 test_reg_delete_key();
3179 test_reg_query_value();
3180 test_reg_query_info();
3181 test_string_termination();
3185 test_classesroot_enum();
3186 test_classesroot_mask();
3188 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
3189 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
3190 set_privileges(SE_RESTORE_NAME
, TRUE
))
3192 test_reg_save_key();
3193 test_reg_load_key();
3194 test_reg_unload_key();
3196 set_privileges(SE_BACKUP_NAME
, FALSE
);
3197 set_privileges(SE_RESTORE_NAME
, FALSE
);
3200 test_reg_delete_tree();
3203 test_delete_value();
3204 test_delete_key_value();
3207 delete_key( hkey_main
);
3209 test_regconnectregistry();