2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
34 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
36 static HKEY hkey_main
;
39 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
40 static const char * sTestpath2
= "%FOO%\\subdir1";
41 static const DWORD ptr_size
= 8 * sizeof(void*);
43 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
44 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
45 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
46 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
47 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
48 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
49 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
52 /* Debugging functions from wine/libs/wine/debug.c */
54 /* allocate some tmp string space */
55 /* FIXME: this is not 100% thread-safe */
56 static char *get_temp_buffer( int size
)
58 static char *list
[32];
63 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
65 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
67 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
68 if (ret
) list
[idx
] = ret
;
72 static const char *wine_debugstr_an( const char *str
, int n
)
74 static const char hex
[16] = "0123456789abcdef";
78 if (!((ULONG_PTR
)str
>> 16))
80 if (!str
) return "(null)";
81 res
= get_temp_buffer( 6 );
82 sprintf( res
, "#%04x", LOWORD(str
) );
85 if (n
== -1) n
= strlen(str
);
87 size
= 10 + min( 300, n
* 4 );
88 dst
= res
= get_temp_buffer( size
);
90 while (n
-- > 0 && dst
<= res
+ size
- 9)
92 unsigned char c
= *str
++;
95 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
96 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
97 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
98 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
99 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
101 if (c
>= ' ' && c
<= 126)
107 *dst
++ = hex
[(c
>> 4) & 0x0f];
108 *dst
++ = hex
[c
& 0x0f];
123 #define ADVAPI32_GET_PROC(func) \
124 p ## func = (void*)GetProcAddress(hadvapi32, #func)
126 static void InitFunctionPtrs(void)
128 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
129 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
130 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
132 /* This function was introduced with Windows 2003 SP1 */
133 ADVAPI32_GET_PROC(RegGetValueA
);
134 ADVAPI32_GET_PROC(RegDeleteTreeA
);
135 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
137 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
138 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
139 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
140 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
143 /* delete key and all its subkeys */
144 static DWORD
delete_key( HKEY hkey
)
149 if ((ret
= RegOpenKeyExA( hkey
, "", 0, KEY_ENUMERATE_SUB_KEYS
, &hkey
))) return ret
;
150 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
153 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
155 ret
= delete_key( tmp
);
160 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
161 RegDeleteKeyA( hkey
, "" );
166 static void setup_main_key(void)
168 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
170 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
173 #define lok ok_(__FILE__, line)
174 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
175 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
178 DWORD ret
, type
, cbData
;
184 /* When successful RegQueryValueExA() leaves GLE as is,
185 * so we must reset it to detect unimplemented functions.
187 SetLastError(0xdeadbeef);
188 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
189 GLE
= GetLastError();
190 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
191 /* It is wrong for the Ansi version to not be implemented */
192 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
193 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
195 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
196 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
197 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
199 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
200 memset(value
, 0xbd, cbData
+1);
202 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
203 GLE
= GetLastError();
204 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
207 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
208 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
212 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
213 wine_debugstr_an((char*)value
, cbData
), cbData
,
214 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
215 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
217 HeapFree(GetProcessHeap(), 0, value
);
220 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
221 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
224 DWORD ret
, type
, cbData
;
229 /* When successful RegQueryValueExW() leaves GLE as is,
230 * so we must reset it to detect unimplemented functions.
232 SetLastError(0xdeadbeef);
233 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
234 GLE
= GetLastError();
235 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
236 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
238 win_skip("RegQueryValueExW() is not implemented\n");
242 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
243 lok(cbData
== full_byte_len
,
244 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
246 /* Give enough space to overflow by one WCHAR */
247 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
248 memset(value
, 0xbd, cbData
+2);
250 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
251 GLE
= GetLastError();
252 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
255 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
256 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
257 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
259 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
260 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
261 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
262 HeapFree(GetProcessHeap(), 0, value
);
265 static void test_set_value(void)
269 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
270 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};
271 static const WCHAR emptyW
[] = {0};
272 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
273 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};
274 static const WCHAR substring2W
[] = {'T','h','i','s',0};
276 static const char name1A
[] = "CleanSingleString";
277 static const char name2A
[] = "SomeIntraZeroedString";
278 static const char emptyA
[] = "";
279 static const char string1A
[] = "ThisNeverBreaks";
280 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
281 static const char substring2A
[] = "This";
285 /* Crashes on NT4, Windows 2000 and XP SP1 */
286 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
287 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
290 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
291 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
292 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
293 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
295 /* RegSetValueA ignores the size passed in */
296 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
297 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
298 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
299 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
301 /* stops at first null */
302 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
303 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
304 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
305 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
307 /* only REG_SZ is supported on NT*/
308 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
309 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
311 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
312 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
314 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
315 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
317 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
318 * Surprisingly enough we're supposed to get zero bytes out of it.
320 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
321 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
322 test_hkey_main_Value_A(name1A
, NULL
, 0);
323 test_hkey_main_Value_W(name1W
, NULL
, 0);
325 /* test RegSetValueExA with an empty string */
326 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
327 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
328 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
329 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
331 /* test RegSetValueExA with off-by-one size */
332 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
333 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
334 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
335 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
337 /* test RegSetValueExA with normal string */
338 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
339 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
340 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
341 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
343 /* test RegSetValueExA with intrazeroed string */
344 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
345 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
346 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
347 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
351 /* Crashes on NT4, Windows 2000 and XP SP1 */
352 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
353 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
355 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
356 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
359 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
360 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
361 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
362 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
364 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
365 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
366 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
367 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
369 /* RegSetValueW ignores the size passed in */
370 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
371 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
372 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
373 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
375 /* stops at first null */
376 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
377 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
378 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
379 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
381 /* only REG_SZ is supported */
382 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
383 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
384 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
385 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
386 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
387 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
389 /* test RegSetValueExW with off-by-one size */
390 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
391 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
392 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
393 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
395 /* test RegSetValueExW with normal string */
396 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
397 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
398 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
399 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
401 /* test RegSetValueExW with intrazeroed string */
402 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
403 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
404 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
405 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
407 /* test RegSetValueExW with data = 1 */
408 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
409 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
410 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
411 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
414 static void create_test_entries(void)
416 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
418 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
419 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
421 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
422 "RegSetValueExA failed\n");
423 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
424 "RegSetValueExA failed\n");
425 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
426 "RegSetValueExA failed\n");
427 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
428 "RegSetValueExA failed\n");
429 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
430 "RegSetValueExA failed\n");
431 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
432 "RegSetValueExA failed\n");
433 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
434 "RegSetValueExA failed\n");
437 static void test_enum_value(void)
441 char value
[20], data
[20];
442 WCHAR valueW
[20], dataW
[20];
443 DWORD val_count
, data_count
, type
;
444 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
445 static const WCHAR testW
[] = {'T','e','s','t',0};
446 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
448 /* create the working key for new 'Test' value */
449 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
450 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
452 /* check NULL data with zero length */
453 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
454 if (GetVersion() & 0x80000000)
455 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
457 ok( !res
, "RegSetValueExA returned %d\n", res
);
458 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
459 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
460 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
461 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
463 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
464 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
466 /* overflow both name and data */
470 strcpy( value
, "xxxxxxxxxx" );
471 strcpy( data
, "xxxxxxxxxx" );
472 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
473 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
474 ok( val_count
== 2, "val_count set to %d\n", val_count
);
475 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
476 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
477 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
478 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
484 strcpy( value
, "xxxxxxxxxx" );
485 strcpy( data
, "xxxxxxxxxx" );
486 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
487 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
488 ok( val_count
== 3, "val_count set to %d\n", val_count
);
489 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
490 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
491 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
492 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
493 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
494 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
495 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
497 /* overflow empty name */
501 strcpy( value
, "xxxxxxxxxx" );
502 strcpy( data
, "xxxxxxxxxx" );
503 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
504 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
505 ok( val_count
== 0, "val_count set to %d\n", val_count
);
506 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
507 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
508 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
509 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
510 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
511 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
517 strcpy( value
, "xxxxxxxxxx" );
518 strcpy( data
, "xxxxxxxxxx" );
519 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
520 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
521 ok( val_count
== 20, "val_count set to %d\n", val_count
);
522 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
523 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
524 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
525 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
531 strcpy( value
, "xxxxxxxxxx" );
532 strcpy( data
, "xxxxxxxxxx" );
533 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
534 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
535 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
536 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
537 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
538 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
539 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
543 SetLastError(0xdeadbeef);
544 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
545 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
547 win_skip("RegSetValueExW is not implemented\n");
550 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
552 /* overflow both name and data */
556 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
557 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
558 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
559 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
560 ok( val_count
== 2, "val_count set to %d\n", val_count
);
561 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
562 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
563 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
564 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
570 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
571 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
572 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
573 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
574 ok( val_count
== 3, "val_count set to %d\n", val_count
);
575 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
576 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
577 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
578 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
584 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
585 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
586 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
587 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
588 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
589 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
590 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
591 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
592 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
598 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
599 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
600 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
601 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
602 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
603 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
604 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
605 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
606 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
609 RegDeleteKeyA(test_key
, "");
610 RegCloseKey(test_key
);
613 static void test_query_value_ex(void)
620 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
621 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
622 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
623 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
627 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
628 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
629 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
631 size
= sizeof(buffer
);
632 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
633 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
634 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
637 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
638 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
641 static void test_get_value(void)
648 CHAR expanded
[] = "bar\\subdir1";
649 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
653 win_skip("RegGetValue not available on this platform\n");
657 /* Invalid parameter */
658 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
659 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
661 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
662 size
= type
= dw
= 0xdeadbeef;
663 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
664 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
665 ok(size
== 4, "size=%d\n", size
);
666 ok(type
== REG_DWORD
, "type=%d\n", type
);
667 ok(dw
== 0x12345678, "dw=%d\n", dw
);
669 /* Query by subkey-name */
670 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
671 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
673 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
674 size
= type
= dw
= 0xdeadbeef;
675 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
676 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
677 /* Although the function failed all values are retrieved */
678 ok(size
== 4, "size=%d\n", size
);
679 ok(type
== REG_DWORD
, "type=%d\n", type
);
680 ok(dw
== 0x12345678, "dw=%d\n", dw
);
682 /* Test RRF_ZEROONFAILURE */
683 type
= dw
= 0xdeadbeef; size
= 4;
684 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
685 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
686 /* Again all values are retrieved ... */
687 ok(size
== 4, "size=%d\n", size
);
688 ok(type
== REG_DWORD
, "type=%d\n", type
);
689 /* ... except the buffer, which is zeroed out */
690 ok(dw
== 0, "dw=%d\n", dw
);
692 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
693 type
= size
= 0xbadbeef;
694 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
695 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
696 ok(size
== 4, "size=%d\n", size
);
697 ok(type
== REG_DWORD
, "type=%d\n", type
);
699 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
700 size
= type
= dw
= 0xdeadbeef;
701 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
702 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
703 ok(size
== 4, "size=%d\n", size
);
704 ok(type
== REG_DWORD
, "type=%d\n", type
);
705 ok(dw
== 0x12345678, "dw=%d\n", dw
);
707 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
708 size
= type
= dw
= 0xdeadbeef;
709 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
710 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
711 ok(size
== 4, "size=%d\n", size
);
712 ok(type
== REG_BINARY
, "type=%d\n", type
);
713 ok(dw
== 0x12345678, "dw=%d\n", dw
);
715 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
716 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
717 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
718 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
719 ok(size
== 8, "size=%d\n", size
);
720 ok(type
== REG_BINARY
, "type=%d\n", type
);
721 ok(qw
[0] == 0x12345678 &&
722 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
724 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
725 type
= dw
= 0xdeadbeef; size
= 4;
726 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
727 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
728 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
729 ok(size
== 8, "size=%d\n", size
);
731 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
732 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
733 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
734 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
735 ok(size
== 8, "size=%d\n", size
);
736 ok(type
== REG_BINARY
, "type=%d\n", type
);
737 ok(qw
[0] == 0x12345678 &&
738 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
740 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
741 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
742 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
743 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
744 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
745 ok(type
== REG_SZ
, "type=%d\n", type
);
746 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
748 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
749 type
= 0xdeadbeef; size
= 0;
750 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
751 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
752 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
753 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
754 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
755 ok(type
== REG_SZ
, "type=%d\n", type
);
757 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
758 strcpy(buf
, sTestpath1
);
761 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
762 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
763 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
765 size
== 1, /* win2k3 */
767 ok(type
== REG_SZ
, "type=%d\n", type
);
768 ok(!strcmp(sTestpath1
, buf
) ||
770 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
772 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
773 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
774 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
775 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
776 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
777 ok(type
== REG_SZ
, "type=%d\n", type
);
778 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
780 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
782 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
783 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
784 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
785 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
786 (size
== strlen(sTestpath2
)+1),
787 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
789 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
790 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
791 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
792 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
793 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
794 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
795 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
796 ok(type
== REG_SZ
, "type=%d\n", type
);
797 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
799 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
800 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
801 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
802 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
803 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
804 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
805 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
806 ok(type
== REG_SZ
, "type=%d\n", type
);
807 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
809 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
810 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
811 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
812 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
813 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
814 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
815 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
817 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
819 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
820 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
821 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
822 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
823 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
825 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
826 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
827 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
829 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
830 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
831 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
832 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
834 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
835 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
836 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
837 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
838 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
839 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
840 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
841 ok(type
== REG_SZ
, "type=%d\n", type
);
842 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
845 static void test_reg_open_key(void)
848 HKEY hkResult
= NULL
;
849 HKEY hkPreserve
= NULL
;
850 HKEY hkRoot64
= NULL
;
851 HKEY hkRoot32
= NULL
;
853 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
855 EXPLICIT_ACCESSA access
;
857 SECURITY_DESCRIPTOR
*sd
;
859 /* successful open */
860 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
861 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
862 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
863 hkPreserve
= hkResult
;
865 /* open same key twice */
866 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
867 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
868 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
869 ok(hkResult
!= NULL
, "hkResult != NULL\n");
870 RegCloseKey(hkResult
);
872 /* open nonexistent key
873 * check that hkResult is set to NULL
875 hkResult
= hkPreserve
;
876 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
877 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
878 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
880 /* open the same nonexistent key again to make sure the key wasn't created */
881 hkResult
= hkPreserve
;
882 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
883 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
884 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
886 /* send in NULL lpSubKey
887 * check that hkResult receives the value of hKey
889 hkResult
= hkPreserve
;
890 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
891 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
892 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
894 /* send empty-string in lpSubKey */
895 hkResult
= hkPreserve
;
896 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
897 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
898 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
900 /* send in NULL lpSubKey and NULL hKey
901 * hkResult is set to NULL
903 hkResult
= hkPreserve
;
904 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
905 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
906 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
908 /* only send NULL hKey
909 * the value of hkResult remains unchanged
911 hkResult
= hkPreserve
;
912 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
913 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
914 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
915 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
916 RegCloseKey(hkResult
);
918 /* send in NULL hkResult */
919 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
920 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
922 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
923 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
925 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
926 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
928 /* beginning backslash character */
929 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
930 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
931 broken(ret
== ERROR_SUCCESS
), /* wow64 */
932 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
933 if (!ret
) RegCloseKey(hkResult
);
936 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
937 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
938 ret
== ERROR_BAD_PATHNAME
, /* NT */
939 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
940 RegCloseKey(hkResult
);
944 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
945 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
946 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
947 RegCloseKey(hkResult
);
950 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
951 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
952 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
953 RegCloseKey(hkResult
);
955 /* check special HKEYs on 64bit
956 * only the lower 4 bytes of the supplied key are used
960 /* HKEY_CURRENT_USER */
961 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
962 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
963 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
964 RegCloseKey(hkResult
);
966 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
967 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
968 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
969 RegCloseKey(hkResult
);
971 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
972 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
973 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
974 RegCloseKey(hkResult
);
976 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
977 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
978 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
979 RegCloseKey(hkResult
);
981 /* HKEY_LOCAL_MACHINE */
982 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
983 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
984 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
985 RegCloseKey(hkResult
);
988 /* Try using WOW64 flags when opening a key with a DACL set to verify that
989 * the registry access check is performed correctly. Redirection isn't
990 * being tested, so the tests don't care about whether the process is
991 * running under WOW64. */
992 if (!pIsWow64Process
)
994 win_skip("WOW64 flags are not recognized\n");
998 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
999 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1000 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1001 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1003 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1004 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1005 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1006 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1008 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1009 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1011 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1013 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1014 access
.grfAccessMode
= SET_ACCESS
;
1015 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1016 access
.Trustee
.pMultipleTrustee
= NULL
;
1017 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1018 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1019 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1020 access
.Trustee
.ptstrName
= (char *)world_sid
;
1022 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1023 ok(ret
== ERROR_SUCCESS
,
1024 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1026 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1027 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1029 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1031 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1033 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1035 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1036 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1038 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1040 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1042 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1045 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1046 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1047 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1048 RegCloseKey(hkResult
);
1051 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1052 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1053 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1054 RegCloseKey(hkResult
);
1056 HeapFree(GetProcessHeap(), 0, sd
);
1059 RegDeleteKeyA(hkRoot64
, "");
1060 RegCloseKey(hkRoot64
);
1061 RegDeleteKeyA(hkRoot32
, "");
1062 RegCloseKey(hkRoot32
);
1065 static void test_reg_create_key(void)
1069 HKEY hkRoot64
= NULL
;
1070 HKEY hkRoot32
= NULL
;
1073 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1075 EXPLICIT_ACCESSA access
;
1077 SECURITY_DESCRIPTOR
*sd
;
1079 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1080 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1081 /* should succeed: all versions of Windows ignore the access rights
1082 * to the parent handle */
1083 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1084 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1087 RegDeleteKeyA(hkey2
, "");
1088 RegDeleteKeyA(hkey1
, "");
1092 /* test creation of volatile keys */
1093 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1094 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1095 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1096 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1097 if (!ret
) RegCloseKey( hkey2
);
1098 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1099 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1101 /* should succeed if the key already exists */
1102 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1103 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1106 RegDeleteKeyA(hkey2
, "");
1107 RegDeleteKeyA(hkey1
, "");
1111 /* beginning backslash character */
1112 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1113 if (!(GetVersion() & 0x80000000))
1114 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1116 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1117 RegDeleteKeyA(hkey1
, NULL
);
1121 /* WOW64 flags - open an existing key */
1123 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1124 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1125 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1129 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1130 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1131 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1134 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1135 * the registry access check is performed correctly. Redirection isn't
1136 * being tested, so the tests don't care about whether the process is
1137 * running under WOW64. */
1138 if (!pIsWow64Process
)
1140 win_skip("WOW64 flags are not recognized\n");
1144 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1145 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1146 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1147 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1149 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1150 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1151 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1152 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1154 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1155 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1157 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1159 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1160 access
.grfAccessMode
= SET_ACCESS
;
1161 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1162 access
.Trustee
.pMultipleTrustee
= NULL
;
1163 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1164 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1165 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1166 access
.Trustee
.ptstrName
= (char *)world_sid
;
1168 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1169 ok(ret
== ERROR_SUCCESS
,
1170 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1172 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1173 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1175 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1177 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1179 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1181 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1182 bRet
= SetKernelObjectSecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1184 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1186 bRet
= SetKernelObjectSecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1188 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1191 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1192 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1193 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1194 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1198 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1199 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1200 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1201 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1204 HeapFree(GetProcessHeap(), 0, sd
);
1207 RegDeleteKeyA(hkRoot64
, "");
1208 RegCloseKey(hkRoot64
);
1209 RegDeleteKeyA(hkRoot32
, "");
1210 RegCloseKey(hkRoot32
);
1213 static void test_reg_close_key(void)
1218 /* successfully close key
1219 * hkHandle remains changed after call to RegCloseKey
1221 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1222 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1223 ret
= RegCloseKey(hkHandle
);
1224 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1226 /* try to close the key twice */
1227 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1228 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1229 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1231 /* try to close a NULL handle */
1232 ret
= RegCloseKey(NULL
);
1233 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1234 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1236 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1237 * win98 doesn't give a new handle when the same key is opened.
1238 * Not re-opening will make some next tests fail.
1240 if (hkey_main
== hkHandle
)
1242 trace("The main handle is most likely closed, so re-opening\n");
1243 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1247 static void test_reg_delete_key(void)
1251 ret
= RegDeleteKeyA(hkey_main
, NULL
);
1253 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1254 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1255 * Not re-creating will make some next tests fail.
1257 if (ret
== ERROR_SUCCESS
)
1259 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1260 " re-creating the main key\n");
1264 ok(ret
== ERROR_INVALID_PARAMETER
||
1265 ret
== ERROR_ACCESS_DENIED
||
1266 ret
== ERROR_BADKEY
, /* Win95 */
1270 static void test_reg_save_key(void)
1274 ret
= RegSaveKeyA(hkey_main
, "saved_key", NULL
);
1275 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1278 static void test_reg_load_key(void)
1283 ret
= RegLoadKeyA(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1284 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1286 ret
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1287 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1289 RegCloseKey(hkHandle
);
1292 static void test_reg_unload_key(void)
1296 ret
= RegUnLoadKeyA(HKEY_LOCAL_MACHINE
, "Test");
1297 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1299 DeleteFileA("saved_key");
1300 DeleteFileA("saved_key.LOG");
1303 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1305 TOKEN_PRIVILEGES tp
;
1309 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1312 if(!LookupPrivilegeValueA(NULL
, privilege
, &luid
))
1314 CloseHandle(hToken
);
1318 tp
.PrivilegeCount
= 1;
1319 tp
.Privileges
[0].Luid
= luid
;
1322 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1324 tp
.Privileges
[0].Attributes
= 0;
1326 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1327 if (GetLastError() != ERROR_SUCCESS
)
1329 CloseHandle(hToken
);
1333 CloseHandle(hToken
);
1337 /* tests that show that RegConnectRegistry and
1338 OpenSCManager accept computer names without the
1339 \\ prefix (what MSDN says). */
1340 static void test_regconnectregistry( void)
1342 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1343 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1344 DWORD len
= sizeof(compName
) ;
1350 SetLastError(0xdeadbeef);
1351 ret
= GetComputerNameA(compName
, &len
);
1352 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1355 lstrcpyA(netwName
, "\\\\");
1356 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1358 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1360 retl
== ERROR_DLL_INIT_FAILED
||
1361 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1362 "RegConnectRegistryA failed err = %d\n", retl
);
1363 if( !retl
) RegCloseKey( hkey
);
1365 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1367 retl
== ERROR_DLL_INIT_FAILED
||
1368 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1369 "RegConnectRegistryA failed err = %d\n", retl
);
1370 if( !retl
) RegCloseKey( hkey
);
1372 SetLastError(0xdeadbeef);
1373 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1374 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1376 win_skip("OpenSCManagerA is not implemented\n");
1380 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1381 CloseServiceHandle( schnd
);
1383 SetLastError(0xdeadbeef);
1384 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1385 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1386 CloseServiceHandle( schnd
);
1390 static void test_reg_query_value(void)
1397 static const WCHAR expected
[] = {'d','a','t','a',0};
1399 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1400 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1402 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1403 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1405 /* try an invalid hkey */
1406 SetLastError(0xdeadbeef);
1408 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1409 ok(ret
== ERROR_INVALID_HANDLE
||
1410 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1411 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1412 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1413 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1415 /* try a NULL hkey */
1416 SetLastError(0xdeadbeef);
1418 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1419 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1420 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1421 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1423 /* try a NULL value */
1425 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1426 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1427 ok(size
== 5, "Expected 5, got %d\n", size
);
1429 /* try a NULL size */
1430 SetLastError(0xdeadbeef);
1432 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1433 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1434 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1435 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1437 /* try a NULL value and size */
1438 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1439 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1441 /* try a size too small */
1442 SetLastError(0xdeadbeef);
1445 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1446 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1447 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1448 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1449 ok(size
== 5, "Expected 5, got %d\n", size
);
1451 /* successfully read the value using 'subkey' */
1453 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1454 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1455 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1456 ok(size
== 5, "Expected 5, got %d\n", size
);
1458 /* successfully read the value using the subkey key */
1460 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1461 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1462 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1463 ok(size
== 5, "Expected 5, got %d\n", size
);
1465 /* unicode - try size too small */
1466 SetLastError(0xdeadbeef);
1469 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1470 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1472 win_skip("RegQueryValueW is not implemented\n");
1475 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1476 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1477 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1478 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1480 /* unicode - try size in WCHARS */
1481 SetLastError(0xdeadbeef);
1482 size
= sizeof(valW
) / sizeof(WCHAR
);
1483 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1484 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1485 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1486 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1487 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1489 /* unicode - successfully read the value */
1490 size
= sizeof(valW
);
1491 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1492 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1493 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1494 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1496 /* unicode - set the value without a NULL terminator */
1497 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1498 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1500 /* unicode - read the unterminated value, value is terminated for us */
1501 memset(valW
, 'a', sizeof(valW
));
1502 size
= sizeof(valW
);
1503 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1504 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1505 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1506 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1509 RegDeleteKeyA(subkey
, "");
1510 RegCloseKey(subkey
);
1513 static void test_string_termination(void)
1517 static const char string
[] = "FullString";
1520 DWORD insize
, outsize
, nsize
;
1522 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1523 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1525 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1526 insize
=sizeof(string
)-1;
1527 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1528 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1530 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1531 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1533 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1534 insize
=sizeof(string
)-2;
1535 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1536 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1538 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1539 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1540 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1542 /* RegQueryValueExA may return a string with no trailing '\0' */
1544 memset(buffer
, 0xbd, sizeof(buffer
));
1545 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1546 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1547 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1548 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1549 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1550 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1552 /* RegQueryValueExA adds a trailing '\0' if there is room */
1554 memset(buffer
, 0xbd, sizeof(buffer
));
1555 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1556 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1557 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1558 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1559 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1560 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1562 /* RegEnumValueA may return a string with no trailing '\0' */
1564 memset(buffer
, 0xbd, sizeof(buffer
));
1566 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1567 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1568 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1569 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1570 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1571 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1572 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1574 /* RegEnumValueA adds a trailing '\0' if there is room */
1576 memset(buffer
, 0xbd, sizeof(buffer
));
1578 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1579 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1580 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1581 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1582 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1583 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1584 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1586 RegDeleteKeyA(subkey
, "");
1587 RegCloseKey(subkey
);
1590 static void test_reg_delete_tree(void)
1592 CHAR buffer
[MAX_PATH
];
1593 HKEY subkey
, subkey2
;
1596 if(!pRegDeleteTreeA
) {
1597 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1601 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1602 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1603 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1604 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1605 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1606 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1607 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1608 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1609 ret
= RegCloseKey(subkey2
);
1610 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1612 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1613 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1614 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1615 "subkey2 was not deleted\n");
1617 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1618 "Default value of subkey not longer present\n");
1620 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1621 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1622 ret
= RegCloseKey(subkey2
);
1623 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1624 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1625 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1626 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1627 "subkey2 was not deleted\n");
1628 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1629 "Default value of subkey not longer present\n");
1631 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1632 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1633 ret
= RegCloseKey(subkey2
);
1634 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1635 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1636 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1637 ret
= RegCloseKey(subkey2
);
1638 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1639 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1640 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1641 ret
= pRegDeleteTreeA(subkey
, NULL
);
1642 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1643 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1644 "subkey was deleted\n");
1645 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1646 "subkey2 was not deleted\n");
1647 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1648 "subkey3 was not deleted\n");
1650 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1651 ok(ret
== ERROR_SUCCESS
,
1652 "Default value of subkey is not present\n");
1653 ok(!lstrlenA(buffer
),
1654 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1656 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1657 "Value is still present\n");
1659 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1660 ok(ret
== ERROR_FILE_NOT_FOUND
,
1661 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1664 static void test_rw_order(void)
1668 static const char keyname
[] = "test_rw_order";
1670 DWORD values
, value_len
, value_name_max_len
;
1673 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1674 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1675 if(ret
!= ERROR_SUCCESS
) {
1676 skip("Couldn't create key. Skipping.\n");
1680 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1681 "RegSetValueExA for value \"A\" failed\n");
1682 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1683 "RegSetValueExA for value \"C\" failed\n");
1684 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1685 "RegSetValueExA for value \"D\" failed\n");
1686 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1687 "RegSetValueExA for value \"B\" failed\n");
1689 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1690 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1691 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1693 /* Value enumeration preserves RegSetValueEx call order */
1695 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1696 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1698 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1699 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1701 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1702 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1704 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1705 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1707 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1710 static void test_symlinks(void)
1712 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1713 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1715 UNICODE_STRING target_str
;
1719 DWORD target_len
, type
, len
, dw
, err
;
1721 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1723 win_skip( "Can't perform symlink tests\n" );
1727 pRtlFormatCurrentUserKeyPath( &target_str
);
1729 target_len
= target_str
.Length
+ sizeof(targetW
);
1730 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1731 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1732 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1734 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1735 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1736 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1738 /* REG_SZ is not allowed */
1739 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1740 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1741 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1742 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1743 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1744 /* other values are not allowed */
1745 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1746 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1748 /* try opening the target through the link */
1750 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1751 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1753 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1754 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1757 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1758 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1761 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1762 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1764 len
= sizeof(buffer
);
1765 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1766 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1767 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1769 len
= sizeof(buffer
);
1770 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1771 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1773 /* REG_LINK can be created in non-link keys */
1774 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1775 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1776 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1777 len
= sizeof(buffer
);
1778 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1779 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1780 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1781 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1782 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1786 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1787 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1789 len
= sizeof(buffer
);
1790 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1791 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1792 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1794 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1795 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1798 /* now open the symlink itself */
1800 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1801 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1802 len
= sizeof(buffer
);
1803 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1804 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1805 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1808 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1809 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1810 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1811 len
= sizeof(buffer
);
1812 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1813 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1814 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1817 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1818 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1819 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1821 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1822 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1823 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1825 err
= RegDeleteKeyA( hkey_main
, "target" );
1826 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1828 err
= RegDeleteKeyA( hkey_main
, "link" );
1829 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1831 status
= pNtDeleteKey( link
);
1832 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1833 RegCloseKey( link
);
1835 HeapFree( GetProcessHeap(), 0, target
);
1836 pRtlFreeUnicodeString( &target_str
);
1839 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1842 DWORD err
, type
, dw
, len
= sizeof(dw
);
1844 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1845 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1846 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1848 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1849 if (err
== ERROR_FILE_NOT_FOUND
)
1852 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1857 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1859 DWORD dw
= get_key_value( root
, name
, flags
);
1860 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1862 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1864 static void test_redirection(void)
1866 DWORD err
, type
, dw
, len
;
1867 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
1868 BOOL is_vista
= FALSE
;
1869 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
1874 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
1876 skip( "Not on Wow64, no redirection\n" );
1881 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1882 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
1883 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1885 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1886 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
1887 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1889 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1890 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
1891 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1893 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1894 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
1895 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1898 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1899 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1902 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1903 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1907 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1908 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1909 ok( dw
== 32, "wrong value %u\n", dw
);
1913 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1914 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1915 ok( dw
== 64, "wrong value %u\n", dw
);
1917 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1918 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1919 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1923 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1924 /* the new (and simpler) Win7 mechanism doesn't */
1925 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1927 trace( "using Vista-style Wow6432Node handling\n" );
1930 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1931 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1932 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1933 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1934 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1935 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1939 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
1941 trace( "using Vista-style Wow6432Node handling\n" );
1944 check_key_value( key
, "Wine\\Winetest", 0, 64 );
1945 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1951 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1952 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1953 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1954 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
1955 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
1956 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1957 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1958 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1959 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
1960 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
1961 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1964 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
1965 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1966 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1967 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1968 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1969 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1970 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
1971 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
1972 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
1976 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
1977 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1980 /* KEY_WOW64 flags have no effect on 64-bit */
1981 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1982 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1983 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1984 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1988 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
1989 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1990 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1991 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
1994 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
1995 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1996 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1997 check_key_value( key
, "Wine\\Winetest", 0, 32 );
1998 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
1999 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2004 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2005 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2006 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2007 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2008 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2009 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2010 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2013 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2014 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2015 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2016 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2017 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2018 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2022 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2023 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2024 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2025 check_key_value( key
, "Winetest", 0, 32 );
2026 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2027 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2032 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2033 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2034 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2035 dw
= get_key_value( key
, "Winetest", 0 );
2036 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2037 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2038 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2041 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2042 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2043 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2044 check_key_value( key
, "Winetest", 0, 32 );
2045 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2046 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2050 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2051 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2052 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2053 check_key_value( key
, "Winetest", 0, ptr_size
);
2054 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2055 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2056 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2057 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2062 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2063 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2064 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2065 dw
= get_key_value( key
, "Winetest", 0 );
2066 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2067 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2068 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2069 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2072 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2073 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2074 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2075 check_key_value( key
, "Winetest", 0, 32 );
2076 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2077 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2081 if (pRegDeleteKeyExA
)
2083 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2084 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2085 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2086 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2087 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2088 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2092 err
= RegDeleteKeyA( key32
, "" );
2093 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2094 err
= RegDeleteKeyA( key64
, "" );
2095 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2096 RegDeleteKeyA( key64
, "" );
2097 RegDeleteKeyA( root64
, "" );
2099 RegCloseKey( key32
);
2100 RegCloseKey( key64
);
2101 RegCloseKey( root32
);
2102 RegCloseKey( root64
);
2104 /* open key in native bit mode */
2105 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2106 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2108 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2110 /* write subkey in opposite bit mode */
2111 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2112 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2114 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2116 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2117 if(err
!= ERROR_SUCCESS
){
2118 win_skip("Can't write to registry\n");
2119 RegCloseKey(op_key
);
2120 RegCloseKey(native
);
2125 /* verify subkey is not present in native mode */
2126 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2127 ok(err
== ERROR_FILE_NOT_FOUND
||
2128 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2131 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2132 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2134 RegCloseKey(op_key
);
2135 RegCloseKey(native
);
2138 static void test_classesroot(void)
2140 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2142 DWORD type
= REG_SZ
;
2143 static CHAR buffer
[8];
2146 /* create a key in the user's classes */
2147 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2150 RegCloseKey( hkey
);
2152 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2153 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2154 if (res
== ERROR_ACCESS_DENIED
)
2156 skip("not enough privileges to add a user class\n");
2159 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2161 /* try to open that key in hkcr */
2162 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2163 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2164 todo_wine
ok(res
== ERROR_SUCCESS
||
2165 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2166 "test key not found in hkcr: %d\n", res
);
2169 skip("HKCR key merging not supported\n");
2171 RegCloseKey( hkey
);
2175 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2177 /* set a value in user's classes */
2178 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2179 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2181 /* try to find the value in hkcr */
2182 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2183 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2184 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2186 /* modify the value in hkcr */
2187 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2188 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2190 /* check if the value is also modified in user's classes */
2191 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2192 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2193 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2195 /* set a value in hkcr */
2196 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2197 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2199 /* try to find the value in user's classes */
2200 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2201 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2202 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2204 /* modify the value in user's classes */
2205 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2206 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2208 /* check if the value is also modified in hkcr */
2209 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2210 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2211 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2216 RegCloseKey( hkey
);
2217 RegCloseKey( hkcr
);
2219 /* create a key in the hklm classes */
2220 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2223 RegCloseKey( hklm
);
2225 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2226 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2227 if (res
== ERROR_ACCESS_DENIED
)
2229 skip("not enough privileges to add a system class\n");
2232 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2234 /* try to open that key in hkcr */
2235 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2236 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2237 ok(res
== ERROR_SUCCESS
,
2238 "test key not found in hkcr: %d\n", res
);
2239 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2243 RegCloseKey( hklm
);
2247 /* set a value in hklm classes */
2248 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2249 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2251 /* try to find the value in hkcr */
2252 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2253 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2254 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2256 /* modify the value in hkcr */
2257 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2258 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2260 /* check that the value is modified in hklm classes */
2261 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2262 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2263 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2265 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2266 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2267 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2269 /* try to open that key in hkcr */
2270 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2271 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2272 ok(res
== ERROR_SUCCESS
,
2273 "test key not found in hkcr: %d\n", res
);
2274 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2276 /* set a value in user's classes */
2277 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2278 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2280 /* try to find the value in hkcr */
2281 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2282 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2283 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2285 /* modify the value in hklm */
2286 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2287 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2289 /* check that the value is not overwritten in hkcr or user's classes */
2290 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2291 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2292 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2293 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2294 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2295 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2297 /* modify the value in hkcr */
2298 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2299 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2301 /* check that the value is overwritten in hklm and user's classes */
2302 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2303 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2304 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2305 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2306 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2307 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2309 /* create a subkey in hklm */
2310 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2311 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2312 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2313 /* try to open that subkey in hkcr */
2314 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2315 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2316 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2318 /* set a value in hklm classes */
2319 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2320 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2322 /* try to find the value in hkcr */
2323 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2324 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2325 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2327 /* modify the value in hkcr */
2328 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2329 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2331 /* check that the value is modified in hklm classes */
2332 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2333 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2334 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2336 /* create a subkey in user's classes */
2337 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2338 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2339 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2341 /* set a value in user's classes */
2342 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2343 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2345 /* try to find the value in hkcr */
2346 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2347 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2348 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2350 /* modify the value in hklm */
2351 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2352 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2354 /* check that the value is not overwritten in hkcr or user's classes */
2355 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2356 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2357 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2358 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2359 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2360 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2362 /* modify the value in hkcr */
2363 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2364 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2366 /* check that the value is not overwritten in hklm, but in user's classes */
2367 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2368 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2369 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2370 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2371 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2372 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2374 /* new subkey in hkcr */
2375 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2376 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2377 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2378 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2379 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2381 /* try to open that new subkey in user's classes and hklm */
2382 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2383 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2385 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2386 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2387 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2389 /* check that the value is present in hklm */
2390 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2391 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2392 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2395 RegCloseKey( hkeysub1
);
2396 RegCloseKey( hklmsub1
);
2398 /* delete subkey1 from hkcr (should point at user's classes) */
2399 res
= RegDeleteKeyA(hkcr
, "subkey1");
2400 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2402 /* confirm key was removed in hkey but not hklm */
2403 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2404 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2405 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2406 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2407 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2409 /* delete subkey1 from hkcr again (which should now point at hklm) */
2410 res
= RegDeleteKeyA(hkcr
, "subkey1");
2411 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2413 /* confirm hkey was removed in hklm */
2414 RegCloseKey( hklmsub1
);
2415 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2416 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2422 delete_key( hkeysub1
);
2423 delete_key( hklmsub1
);
2424 delete_key( hkcrsub1
);
2425 delete_key( hklmsub2
);
2426 delete_key( hkcrsub2
);
2427 RegCloseKey( hkey
);
2428 RegCloseKey( hklm
);
2429 RegCloseKey( hkcr
);
2430 RegCloseKey( hkeysub1
);
2431 RegCloseKey( hklmsub1
);
2432 RegCloseKey( hkcrsub1
);
2433 RegCloseKey( hklmsub2
);
2434 RegCloseKey( hkcrsub2
);
2437 static void test_classesroot_enum(void)
2439 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2441 static CHAR buffer
[2];
2444 /* prepare initial testing env in HKCU */
2445 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2448 RegCloseKey( hkcu
);
2450 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2451 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2453 if (res
!= ERROR_SUCCESS
)
2455 skip("failed to add a user class\n");
2459 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2460 todo_wine
ok(res
== ERROR_SUCCESS
||
2461 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2462 "test key not found in hkcr: %d\n", res
);
2465 skip("HKCR key merging not supported\n");
2467 RegCloseKey( hkcu
);
2471 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2472 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2473 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2474 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2475 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2476 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2477 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2478 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2480 /* test on values in HKCU */
2481 size
= sizeof(buffer
);
2482 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2483 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2484 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2485 size
= sizeof(buffer
);
2486 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2487 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2488 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2489 size
= sizeof(buffer
);
2490 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2491 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2493 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2494 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2495 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2496 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2497 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2498 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2499 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2500 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2502 /* prepare test env in HKLM */
2503 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2506 RegCloseKey( hklm
);
2509 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2510 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2512 if (res
== ERROR_ACCESS_DENIED
)
2514 RegCloseKey( hkcusub
[0] );
2515 RegCloseKey( hkcusub
[1] );
2517 RegCloseKey( hkcu
);
2518 RegCloseKey( hkcr
);
2519 skip("not enough privileges to add a system class\n");
2523 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2524 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2525 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2526 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2527 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2528 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2529 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2530 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2532 /* test on values/keys in both HKCU and HKLM */
2533 size
= sizeof(buffer
);
2534 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2535 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2536 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2537 size
= sizeof(buffer
);
2538 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2539 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2540 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2541 size
= sizeof(buffer
);
2542 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2543 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2544 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2545 size
= sizeof(buffer
);
2546 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2547 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2549 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2550 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2551 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2552 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2553 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2554 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2555 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2556 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2557 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2558 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2559 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2561 /* delete values/keys from HKCU to test only on HKLM */
2562 RegCloseKey( hkcusub
[0] );
2563 RegCloseKey( hkcusub
[1] );
2565 RegCloseKey( hkcu
);
2567 size
= sizeof(buffer
);
2568 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2569 ok(res
== ERROR_KEY_DELETED
||
2570 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2571 "expected ERROR_KEY_DELETED, got %d\n", res
);
2572 size
= sizeof(buffer
);
2573 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2574 ok(res
== ERROR_KEY_DELETED
||
2575 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2576 "expected ERROR_KEY_DELETED, got %d\n", res
);
2578 /* reopen HKCR handle */
2579 RegCloseKey( hkcr
);
2580 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2581 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2582 if (res
) goto cleanup
;
2584 /* test on values/keys in HKLM */
2585 size
= sizeof(buffer
);
2586 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2587 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2588 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2589 size
= sizeof(buffer
);
2590 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2591 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2592 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2593 size
= sizeof(buffer
);
2594 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2595 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2597 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2598 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2599 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2600 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2601 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2602 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2603 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2604 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2607 RegCloseKey( hklmsub
[0] );
2608 RegCloseKey( hklmsub
[1] );
2610 RegCloseKey( hklm
);
2611 RegCloseKey( hkcr
);
2614 static void test_classesroot_mask(void)
2619 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
2620 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2621 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
2622 "hkcr mask not set in %p\n", hkey
);
2623 RegCloseKey( hkey
);
2625 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
2626 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2627 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2628 RegCloseKey( hkey
);
2630 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
2631 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2632 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2633 RegCloseKey( hkey
);
2635 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
2636 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2637 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2638 RegCloseKey( hkey
);
2640 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
2641 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2642 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2643 RegCloseKey( hkey
);
2646 static void test_deleted_key(void)
2650 DWORD val_count
, type
;
2653 /* Open the test key, then delete it while it's open */
2654 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2656 delete_key( hkey_main
);
2658 val_count
= sizeof(value
);
2660 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2661 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2663 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2664 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2666 val_count
= sizeof(value
);
2668 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2669 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2671 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2672 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2674 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2675 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2677 RegCloseKey( hkey2
);
2679 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2680 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2682 RegCloseKey( hkey2
);
2684 res
= RegFlushKey( hkey
);
2685 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2687 RegCloseKey( hkey
);
2692 static void test_delete_value(void)
2697 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2698 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2700 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2701 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2703 res
= RegDeleteValueA( hkey_main
, "test" );
2704 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2706 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2707 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2709 res
= RegDeleteValueA( hkey_main
, "test" );
2710 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2712 memset(longname
, 'a', 400);
2714 res
= RegDeleteValueA( hkey_main
, longname
);
2715 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2716 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2719 START_TEST(registry
)
2721 /* Load pointers for functions that are not available in all Windows versions */
2726 create_test_entries();
2728 test_query_value_ex();
2730 test_reg_open_key();
2731 test_reg_create_key();
2732 test_reg_close_key();
2733 test_reg_delete_key();
2734 test_reg_query_value();
2735 test_string_termination();
2739 test_classesroot_enum();
2740 test_classesroot_mask();
2742 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2743 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2744 set_privileges(SE_RESTORE_NAME
, TRUE
))
2746 test_reg_save_key();
2747 test_reg_load_key();
2748 test_reg_unload_key();
2750 set_privileges(SE_BACKUP_NAME
, FALSE
);
2751 set_privileges(SE_RESTORE_NAME
, FALSE
);
2754 test_reg_delete_tree();
2757 test_delete_value();
2760 delete_key( hkey_main
);
2762 test_regconnectregistry();