2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
23 #define WIN32_LEAN_AND_MEAN
28 #include "wine/test.h"
37 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
39 static HKEY hkey_main
;
42 static const char * sTestpath1
= "%LONGSYSTEMVAR%\\subdir1";
43 static const char * sTestpath2
= "%FOO%\\subdir1";
44 static const DWORD ptr_size
= 8 * sizeof(void*);
46 static DWORD (WINAPI
*pRegGetValueA
)(HKEY
,LPCSTR
,LPCSTR
,DWORD
,LPDWORD
,PVOID
,LPDWORD
);
47 static DWORD (WINAPI
*pRegDeleteTreeA
)(HKEY
,LPCSTR
);
48 static DWORD (WINAPI
*pRegDeleteKeyExA
)(HKEY
,LPCSTR
,REGSAM
,DWORD
);
49 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
,PBOOL
);
50 static NTSTATUS (WINAPI
* pNtDeleteKey
)(HANDLE
);
51 static NTSTATUS (WINAPI
* pRtlFormatCurrentUserKeyPath
)(UNICODE_STRING
*);
52 static NTSTATUS (WINAPI
* pRtlFreeUnicodeString
)(PUNICODE_STRING
);
53 static LONG (WINAPI
*pRegDeleteKeyValueA
)(HKEY
,LPCSTR
,LPCSTR
);
54 static LONG (WINAPI
*pRegSetKeyValueW
)(HKEY
,LPCWSTR
,LPCWSTR
,DWORD
,const void*,DWORD
);
56 static BOOL limited_user
;
59 /* Debugging functions from wine/libs/wine/debug.c */
61 /* allocate some tmp string space */
62 /* FIXME: this is not 100% thread-safe */
63 static char *get_temp_buffer( int size
)
65 static char *list
[32];
70 idx
= ++pos
% (sizeof(list
)/sizeof(list
[0]));
72 ret
= HeapReAlloc( GetProcessHeap(), 0, list
[idx
], size
);
74 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
75 if (ret
) list
[idx
] = ret
;
79 static const char *wine_debugstr_an( const char *str
, int n
)
81 static const char hex
[16] = "0123456789abcdef";
85 if (!((ULONG_PTR
)str
>> 16))
87 if (!str
) return "(null)";
88 res
= get_temp_buffer( 6 );
89 sprintf( res
, "#%04x", LOWORD(str
) );
92 if (n
== -1) n
= strlen(str
);
94 size
= 10 + min( 300, n
* 4 );
95 dst
= res
= get_temp_buffer( size
);
97 while (n
-- > 0 && dst
<= res
+ size
- 9)
99 unsigned char c
= *str
++;
102 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
103 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
104 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
105 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
106 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
108 if (c
>= ' ' && c
<= 126)
114 *dst
++ = hex
[(c
>> 4) & 0x0f];
115 *dst
++ = hex
[c
& 0x0f];
130 #define ADVAPI32_GET_PROC(func) \
131 p ## func = (void*)GetProcAddress(hadvapi32, #func)
133 static void InitFunctionPtrs(void)
135 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
136 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
137 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
139 /* This function was introduced with Windows 2003 SP1 */
140 ADVAPI32_GET_PROC(RegGetValueA
);
141 ADVAPI32_GET_PROC(RegDeleteTreeA
);
142 ADVAPI32_GET_PROC(RegDeleteKeyExA
);
143 ADVAPI32_GET_PROC(RegDeleteKeyValueA
);
144 ADVAPI32_GET_PROC(RegSetKeyValueW
);
146 pIsWow64Process
= (void *)GetProcAddress( hkernel32
, "IsWow64Process" );
147 pRtlFormatCurrentUserKeyPath
= (void *)GetProcAddress( hntdll
, "RtlFormatCurrentUserKeyPath" );
148 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
149 pNtDeleteKey
= (void *)GetProcAddress( hntdll
, "NtDeleteKey" );
152 /* delete key and all its subkeys */
153 static DWORD
delete_key( HKEY hkey
)
158 if ((ret
= RegOpenKeyExA( hkey
, "", 0, KEY_ENUMERATE_SUB_KEYS
, &hkey
))) return ret
;
159 while (!(ret
= RegEnumKeyA(hkey
, 0, name
, sizeof(name
))))
162 if (!(ret
= RegOpenKeyExA( hkey
, name
, 0, KEY_ENUMERATE_SUB_KEYS
, &tmp
)))
164 ret
= delete_key( tmp
);
169 if (ret
!= ERROR_NO_MORE_ITEMS
) return ret
;
170 RegDeleteKeyA( hkey
, "" );
175 static void setup_main_key(void)
177 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
)) delete_key( hkey_main
);
179 assert (!RegCreateKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
));
182 static void check_user_privs(void)
185 HKEY hkey
= (HKEY
)0xdeadbeef;
187 ret
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WRITE
, &hkey
);
188 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_ACCESS_DENIED
, "expected success or access denied, got %i\n", ret
);
189 if (ret
== ERROR_SUCCESS
)
191 ok(hkey
!= NULL
, "RegOpenKeyExA succeeded but returned NULL hkey\n");
196 ok(hkey
== NULL
, "RegOpenKeyExA failed but returned hkey %p\n", hkey
);
198 trace("running as limited user\n");
202 #define lok ok_(__FILE__, line)
203 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
204 static void _test_hkey_main_Value_A(int line
, LPCSTR name
, LPCSTR string
,
207 DWORD ret
, type
, cbData
;
213 /* When successful RegQueryValueExA() leaves GLE as is,
214 * so we must reset it to detect unimplemented functions.
216 SetLastError(0xdeadbeef);
217 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
218 GLE
= GetLastError();
219 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret
, GLE
);
220 /* It is wrong for the Ansi version to not be implemented */
221 ok(GLE
== 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE
);
222 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
) return;
224 str_byte_len
= (string
? lstrlenA(string
) : 0) + 1;
225 lok(type
== REG_SZ
, "RegQueryValueExA/1 returned type %d\n", type
);
226 lok(cbData
== full_byte_len
, "cbData=%d instead of %d or %d\n", cbData
, full_byte_len
, str_byte_len
);
228 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+1);
229 memset(value
, 0xbd, cbData
+1);
231 ret
= RegQueryValueExA(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
232 GLE
= GetLastError();
233 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret
, GLE
);
236 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
237 lok(*value
== 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData
, *value
);
241 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
242 wine_debugstr_an((char*)value
, cbData
), cbData
,
243 wine_debugstr_an(string
, full_byte_len
), full_byte_len
);
244 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData
, *(value
+cbData
));
246 HeapFree(GetProcessHeap(), 0, value
);
249 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
250 static void _test_hkey_main_Value_W(int line
, LPCWSTR name
, LPCWSTR string
,
253 DWORD ret
, type
, cbData
;
258 /* When successful RegQueryValueExW() leaves GLE as is,
259 * so we must reset it to detect unimplemented functions.
261 SetLastError(0xdeadbeef);
262 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, NULL
, &cbData
);
263 GLE
= GetLastError();
264 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret
, GLE
);
265 if(GLE
== ERROR_CALL_NOT_IMPLEMENTED
)
267 win_skip("RegQueryValueExW() is not implemented\n");
271 lok(type
== REG_SZ
, "RegQueryValueExW/1 returned type %d\n", type
);
272 lok(cbData
== full_byte_len
,
273 "cbData=%d instead of %d\n", cbData
, full_byte_len
);
275 /* Give enough space to overflow by one WCHAR */
276 value
= HeapAlloc(GetProcessHeap(), 0, cbData
+2);
277 memset(value
, 0xbd, cbData
+2);
279 ret
= RegQueryValueExW(hkey_main
, name
, NULL
, &type
, value
, &cbData
);
280 GLE
= GetLastError();
281 lok(ret
== ERROR_SUCCESS
, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret
, GLE
);
284 lok(memcmp(value
, string
, cbData
) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
285 wine_dbgstr_wn((WCHAR
*)value
, cbData
/ sizeof(WCHAR
)), cbData
,
286 wine_dbgstr_wn(string
, full_byte_len
/ sizeof(WCHAR
)), full_byte_len
);
288 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
289 lok(*(value
+cbData
) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData
, *(value
+cbData
));
290 lok(*(value
+cbData
+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData
, *(value
+cbData
+1));
291 HeapFree(GetProcessHeap(), 0, value
);
294 static void test_set_value(void)
298 static const WCHAR name1W
[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
299 static const WCHAR name2W
[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
300 static const WCHAR emptyW
[] = {0};
301 static const WCHAR string1W
[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
302 static const WCHAR string2W
[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
303 static const WCHAR substring2W
[] = {'T','h','i','s',0};
305 static const char name1A
[] = "CleanSingleString";
306 static const char name2A
[] = "SomeIntraZeroedString";
307 static const char emptyA
[] = "";
308 static const char string1A
[] = "ThisNeverBreaks";
309 static const char string2A
[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
310 static const char substring2A
[] = "This";
314 /* Crashes on NT4, Windows 2000 and XP SP1 */
315 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
316 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
319 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, sizeof(string1A
));
320 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
321 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
322 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
324 /* RegSetValueA ignores the size passed in */
325 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string1A
, 4);
326 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
327 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
328 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
330 /* stops at first null */
331 ret
= RegSetValueA(hkey_main
, NULL
, REG_SZ
, string2A
, sizeof(string2A
));
332 ok(ret
== ERROR_SUCCESS
, "RegSetValueA failed: %d, GLE=%d\n", ret
, GetLastError());
333 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
334 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
336 /* only REG_SZ is supported on NT*/
337 ret
= RegSetValueA(hkey_main
, NULL
, REG_BINARY
, string2A
, sizeof(string2A
));
338 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
340 ret
= RegSetValueA(hkey_main
, NULL
, REG_EXPAND_SZ
, string2A
, sizeof(string2A
));
341 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
343 ret
= RegSetValueA(hkey_main
, NULL
, REG_MULTI_SZ
, string2A
, sizeof(string2A
));
344 ok(ret
== ERROR_INVALID_PARAMETER
, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret
);
346 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
347 * Surprisingly enough we're supposed to get zero bytes out of it.
349 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, 0);
350 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
351 test_hkey_main_Value_A(name1A
, NULL
, 0);
352 test_hkey_main_Value_W(name1W
, NULL
, 0);
354 /* test RegSetValueExA with an empty string */
355 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)emptyA
, sizeof(emptyA
));
356 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
357 test_hkey_main_Value_A(name1A
, emptyA
, sizeof(emptyA
));
358 test_hkey_main_Value_W(name1W
, emptyW
, sizeof(emptyW
));
360 /* test RegSetValueExA with off-by-one size */
361 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
)-sizeof(string1A
[0]));
362 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
363 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
364 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
366 /* test RegSetValueExA with normal string */
367 ret
= RegSetValueExA(hkey_main
, name1A
, 0, REG_SZ
, (const BYTE
*)string1A
, sizeof(string1A
));
368 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
369 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
370 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
372 /* test RegSetValueExA with intrazeroed string */
373 ret
= RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)string2A
, sizeof(string2A
));
374 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%d\n", ret
, GetLastError());
375 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
376 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
380 /* Crashes on NT4, Windows 2000 and XP SP1 */
381 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, NULL
, 0);
382 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret
);
384 RegSetValueExA(hkey_main
, name2A
, 0, REG_SZ
, (const BYTE
*)1, 1);
385 RegSetValueExA(hkey_main
, name2A
, 0, REG_DWORD
, (const BYTE
*)1, 1);
388 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, sizeof(string1W
));
389 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
390 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
391 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
393 ret
= RegSetValueW(hkey_main
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
394 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
395 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
396 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
398 /* RegSetValueW ignores the size passed in */
399 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string1W
, 4 * sizeof(string1W
[0]));
400 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
401 test_hkey_main_Value_A(NULL
, string1A
, sizeof(string1A
));
402 test_hkey_main_Value_W(NULL
, string1W
, sizeof(string1W
));
404 /* stops at first null */
405 ret
= RegSetValueW(hkey_main
, NULL
, REG_SZ
, string2W
, sizeof(string2W
));
406 ok(ret
== ERROR_SUCCESS
, "RegSetValueW failed: %d, GLE=%d\n", ret
, GetLastError());
407 test_hkey_main_Value_A(NULL
, substring2A
, sizeof(substring2A
));
408 test_hkey_main_Value_W(NULL
, substring2W
, sizeof(substring2W
));
410 /* only REG_SZ is supported */
411 ret
= RegSetValueW(hkey_main
, NULL
, REG_BINARY
, string2W
, sizeof(string2W
));
412 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
413 ret
= RegSetValueW(hkey_main
, NULL
, REG_EXPAND_SZ
, string2W
, sizeof(string2W
));
414 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
415 ret
= RegSetValueW(hkey_main
, NULL
, REG_MULTI_SZ
, string2W
, sizeof(string2W
));
416 ok(ret
== ERROR_INVALID_PARAMETER
, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
418 /* test RegSetValueExW with off-by-one size */
419 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
)-sizeof(string1W
[0]));
420 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
421 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
422 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
424 /* test RegSetValueExW with normal string */
425 ret
= RegSetValueExW(hkey_main
, name1W
, 0, REG_SZ
, (const BYTE
*)string1W
, sizeof(string1W
));
426 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
427 test_hkey_main_Value_A(name1A
, string1A
, sizeof(string1A
));
428 test_hkey_main_Value_W(name1W
, string1W
, sizeof(string1W
));
430 /* test RegSetValueExW with intrazeroed string */
431 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
432 ok(ret
== ERROR_SUCCESS
, "RegSetValueExW failed: %d, GLE=%d\n", ret
, GetLastError());
433 test_hkey_main_Value_A(name2A
, string2A
, sizeof(string2A
));
434 test_hkey_main_Value_W(name2W
, string2W
, sizeof(string2W
));
436 /* test RegSetValueExW with data = 1 */
437 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_SZ
, (const BYTE
*)1, 1);
438 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
439 ret
= RegSetValueExW(hkey_main
, name2W
, 0, REG_DWORD
, (const BYTE
*)1, 1);
440 ok(ret
== ERROR_NOACCESS
, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret
, GetLastError());
443 if (!pRegSetKeyValueW
)
444 win_skip("RegSetKeyValue() is not supported.\n");
447 static const WCHAR subkeyW
[] = {'s','u','b','k','e','y',0};
451 ret
= pRegSetKeyValueW(hkey_main
, NULL
, name1W
, REG_SZ
, (const BYTE
*)string2W
, sizeof(string2W
));
452 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
453 test_hkey_main_Value_A(name1A
, string2A
, sizeof(string2A
));
454 test_hkey_main_Value_W(name1W
, string2W
, sizeof(string2W
));
456 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, string1W
, sizeof(string1W
));
457 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
459 ret
= RegOpenKeyExW(hkey_main
, subkeyW
, 0, KEY_QUERY_VALUE
, &subkey
);
460 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
462 ret
= RegQueryValueExW(subkey
, name1W
, 0, &type
, NULL
, &len
);
463 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
464 ok(len
== sizeof(string1W
), "got %d\n", len
);
465 ok(type
== REG_SZ
, "got type %d\n", type
);
467 ret
= pRegSetKeyValueW(hkey_main
, subkeyW
, name1W
, REG_SZ
, NULL
, 0);
468 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
474 static void create_test_entries(void)
476 static const DWORD qw
[2] = { 0x12345678, 0x87654321 };
478 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
479 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
481 ok(!RegSetValueExA(hkey_main
,"TP1_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
482 "RegSetValueExA failed\n");
483 ok(!RegSetValueExA(hkey_main
,"TP1_SZ",0,REG_SZ
, (const BYTE
*)sTestpath1
, strlen(sTestpath1
)+1),
484 "RegSetValueExA failed\n");
485 ok(!RegSetValueExA(hkey_main
,"TP1_ZB_SZ",0,REG_SZ
, (const BYTE
*)"", 0),
486 "RegSetValueExA failed\n");
487 ok(!RegSetValueExA(hkey_main
,"TP2_EXP_SZ",0,REG_EXPAND_SZ
, (const BYTE
*)sTestpath2
, strlen(sTestpath2
)+1),
488 "RegSetValueExA failed\n");
489 ok(!RegSetValueExA(hkey_main
,"DWORD",0,REG_DWORD
, (const BYTE
*)qw
, 4),
490 "RegSetValueExA failed\n");
491 ok(!RegSetValueExA(hkey_main
,"BIN32",0,REG_BINARY
, (const BYTE
*)qw
, 4),
492 "RegSetValueExA failed\n");
493 ok(!RegSetValueExA(hkey_main
,"BIN64",0,REG_BINARY
, (const BYTE
*)qw
, 8),
494 "RegSetValueExA failed\n");
497 static void test_enum_value(void)
501 char value
[20], data
[20];
502 WCHAR valueW
[20], dataW
[20];
503 DWORD val_count
, data_count
, type
;
504 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
505 static const WCHAR testW
[] = {'T','e','s','t',0};
506 static const WCHAR xxxW
[] = {'x','x','x','x','x','x','x','x',0};
508 /* create the working key for new 'Test' value */
509 res
= RegCreateKeyA( hkey_main
, "TestKey", &test_key
);
510 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
512 /* check NULL data with zero length */
513 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, NULL
, 0 );
514 if (GetVersion() & 0x80000000)
515 ok( res
== ERROR_INVALID_PARAMETER
, "RegSetValueExA returned %d\n", res
);
517 ok( !res
, "RegSetValueExA returned %d\n", res
);
518 res
= RegSetValueExA( test_key
, "Test", 0, REG_EXPAND_SZ
, NULL
, 0 );
519 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
520 res
= RegSetValueExA( test_key
, "Test", 0, REG_BINARY
, NULL
, 0 );
521 ok( ERROR_SUCCESS
== res
|| ERROR_INVALID_PARAMETER
== res
, "RegSetValueExA returned %d\n", res
);
523 res
= RegSetValueExA( test_key
, "Test", 0, REG_SZ
, (const BYTE
*)"foobar", 7 );
524 ok( res
== 0, "RegSetValueExA failed error %d\n", res
);
526 /* overflow both name and data */
530 strcpy( value
, "xxxxxxxxxx" );
531 strcpy( data
, "xxxxxxxxxx" );
532 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
533 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
534 ok( val_count
== 2, "val_count set to %d\n", val_count
);
535 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
536 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
537 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
538 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
544 strcpy( value
, "xxxxxxxxxx" );
545 strcpy( data
, "xxxxxxxxxx" );
546 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
547 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
548 ok( val_count
== 3, "val_count set to %d\n", val_count
);
549 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
550 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
551 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
552 ok( !strcmp( value
, "Te" ) || !strcmp( value
, "xxxxxxxxxx" ),
553 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value
);
554 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
555 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
557 /* overflow empty name */
561 strcpy( value
, "xxxxxxxxxx" );
562 strcpy( data
, "xxxxxxxxxx" );
563 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
564 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
565 ok( val_count
== 0, "val_count set to %d\n", val_count
);
566 ok( data_count
== 7 || broken( data_count
== 8 ), "data_count set to %d instead of 7\n", data_count
);
567 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
568 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
569 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
570 ok( !strcmp( data
, "foobar" ) || !strcmp( data
, "xxxxxxx" ) || broken( !strcmp( data
, "xxxxxxxx" ) && data_count
== 8 ),
571 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data
);
577 strcpy( value
, "xxxxxxxxxx" );
578 strcpy( data
, "xxxxxxxxxx" );
579 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
580 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
581 ok( val_count
== 20, "val_count set to %d\n", val_count
);
582 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
583 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
584 ok( !strcmp( value
, "xxxxxxxxxx" ), "value set to '%s'\n", value
);
585 ok( !strcmp( data
, "xxxxxxxxxx" ), "data set to '%s'\n", data
);
591 strcpy( value
, "xxxxxxxxxx" );
592 strcpy( data
, "xxxxxxxxxx" );
593 res
= RegEnumValueA( test_key
, 0, value
, &val_count
, NULL
, &type
, (LPBYTE
)data
, &data_count
);
594 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
595 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
596 ok( data_count
== 7, "data_count set to %d instead of 7\n", data_count
);
597 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
598 ok( !strcmp( value
, "Test" ), "value is '%s' instead of Test\n", value
);
599 ok( !strcmp( data
, "foobar" ), "data is '%s' instead of foobar\n", data
);
603 SetLastError(0xdeadbeef);
604 res
= RegSetValueExW( test_key
, testW
, 0, REG_SZ
, (const BYTE
*)foobarW
, 7*sizeof(WCHAR
) );
605 if (res
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
607 win_skip("RegSetValueExW is not implemented\n");
610 ok( res
== 0, "RegSetValueExW failed error %d\n", res
);
612 /* overflow both name and data */
616 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
617 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
618 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
619 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
620 ok( val_count
== 2, "val_count set to %d\n", val_count
);
621 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
622 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
623 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
624 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
630 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
631 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
632 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
633 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
634 ok( val_count
== 3, "val_count set to %d\n", val_count
);
635 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
636 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
637 ok( !memcmp( valueW
, xxxW
, sizeof(xxxW
) ), "value modified\n" );
638 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
644 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
645 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
646 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
647 ok( res
== ERROR_MORE_DATA
, "expected ERROR_MORE_DATA, got %d\n", res
);
648 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
649 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
650 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
651 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
652 ok( !memcmp( dataW
, xxxW
, sizeof(xxxW
) ), "data modified\n" );
658 memcpy( valueW
, xxxW
, sizeof(xxxW
) );
659 memcpy( dataW
, xxxW
, sizeof(xxxW
) );
660 res
= RegEnumValueW( test_key
, 0, valueW
, &val_count
, NULL
, &type
, (BYTE
*)dataW
, &data_count
);
661 ok( res
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", res
);
662 ok( val_count
== 4, "val_count set to %d instead of 4\n", val_count
);
663 ok( data_count
== 7*sizeof(WCHAR
), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count
);
664 ok( type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
665 ok( !memcmp( valueW
, testW
, sizeof(testW
) ), "value is not 'Test'\n" );
666 ok( !memcmp( dataW
, foobarW
, sizeof(foobarW
) ), "data is not 'foobar'\n" );
669 RegDeleteKeyA(test_key
, "");
670 RegCloseKey(test_key
);
673 static void test_query_value_ex(void)
680 ret
= RegQueryValueExA(hkey_main
, "TP1_SZ", NULL
, &type
, NULL
, &size
);
681 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
682 ok(size
== strlen(sTestpath1
) + 1, "(%d,%d)\n", (DWORD
)strlen(sTestpath1
) + 1, size
);
683 ok(type
== REG_SZ
, "type %d is not REG_SZ\n", type
);
687 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, NULL
, &size
);
688 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
689 ok(size
== 0, "size should have been set to 0 instead of %d\n", size
);
691 size
= sizeof(buffer
);
692 ret
= RegQueryValueExA(HKEY_CLASSES_ROOT
, "Nonexistent Value", NULL
, &type
, buffer
, &size
);
693 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
694 ok(size
== sizeof(buffer
), "size shouldn't have been changed to %d\n", size
);
697 ret
= RegQueryValueExA(hkey_main
, "BIN32", NULL
, &size
, buffer
, &size
);
698 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
701 static void test_get_value(void)
708 CHAR expanded
[] = "bar\\subdir1";
709 CHAR expanded2
[] = "ImARatherLongButIndeedNeededString\\subdir1";
713 win_skip("RegGetValue not available on this platform\n");
717 /* Invalid parameter */
718 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, NULL
);
719 ok(ret
== ERROR_INVALID_PARAMETER
, "ret=%d\n", ret
);
721 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
722 size
= type
= dw
= 0xdeadbeef;
723 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_DWORD
, &type
, &dw
, &size
);
724 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
725 ok(size
== 4, "size=%d\n", size
);
726 ok(type
== REG_DWORD
, "type=%d\n", type
);
727 ok(dw
== 0x12345678, "dw=%d\n", dw
);
729 /* Query by subkey-name */
730 ret
= pRegGetValueA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD
, NULL
, NULL
, NULL
);
731 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
733 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
734 size
= type
= dw
= 0xdeadbeef;
735 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
736 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
737 /* Although the function failed all values are retrieved */
738 ok(size
== 4, "size=%d\n", size
);
739 ok(type
== REG_DWORD
, "type=%d\n", type
);
740 ok(dw
== 0x12345678, "dw=%d\n", dw
);
742 /* Test RRF_ZEROONFAILURE */
743 type
= dw
= 0xdeadbeef; size
= 4;
744 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, &dw
, &size
);
745 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
746 /* Again all values are retrieved ... */
747 ok(size
== 4, "size=%d\n", size
);
748 ok(type
== REG_DWORD
, "type=%d\n", type
);
749 /* ... except the buffer, which is zeroed out */
750 ok(dw
== 0, "dw=%d\n", dw
);
752 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
753 type
= size
= 0xbadbeef;
754 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_REG_SZ
|RRF_ZEROONFAILURE
, &type
, NULL
, &size
);
755 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
756 ok(size
== 4, "size=%d\n", size
);
757 ok(type
== REG_DWORD
, "type=%d\n", type
);
759 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
760 size
= type
= dw
= 0xdeadbeef;
761 ret
= pRegGetValueA(hkey_main
, NULL
, "DWORD", RRF_RT_DWORD
, &type
, &dw
, &size
);
762 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
763 ok(size
== 4, "size=%d\n", size
);
764 ok(type
== REG_DWORD
, "type=%d\n", type
);
765 ok(dw
== 0x12345678, "dw=%d\n", dw
);
767 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
768 size
= type
= dw
= 0xdeadbeef;
769 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN32", RRF_RT_DWORD
, &type
, &dw
, &size
);
770 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
771 ok(size
== 4, "size=%d\n", size
);
772 ok(type
== REG_BINARY
, "type=%d\n", type
);
773 ok(dw
== 0x12345678, "dw=%d\n", dw
);
775 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
776 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
777 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_DWORD
, &type
, qw
, &size
);
778 ok(ret
== ERROR_DATATYPE_MISMATCH
, "ret=%d\n", ret
);
779 ok(size
== 8, "size=%d\n", size
);
780 ok(type
== REG_BINARY
, "type=%d\n", type
);
781 ok(qw
[0] == 0x12345678 &&
782 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
784 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
785 type
= dw
= 0xdeadbeef; size
= 4;
786 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_REG_BINARY
, &type
, &dw
, &size
);
787 ok(ret
== ERROR_MORE_DATA
, "ret=%d\n", ret
);
788 ok(dw
== 0xdeadbeef, "dw=%d\n", dw
);
789 ok(size
== 8, "size=%d\n", size
);
791 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
792 qw
[0] = qw
[1] = size
= type
= 0xdeadbeef;
793 ret
= pRegGetValueA(hkey_main
, NULL
, "BIN64", RRF_RT_QWORD
, &type
, qw
, &size
);
794 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
795 ok(size
== 8, "size=%d\n", size
);
796 ok(type
== REG_BINARY
, "type=%d\n", type
);
797 ok(qw
[0] == 0x12345678 &&
798 qw
[1] == 0x87654321, "qw={%d,%d}\n", qw
[0], qw
[1]);
800 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
801 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
802 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
803 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
804 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
805 ok(type
== REG_SZ
, "type=%d\n", type
);
806 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
808 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
809 type
= 0xdeadbeef; size
= 0;
810 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
, &type
, NULL
, &size
);
811 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
812 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
813 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
814 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
815 ok(type
== REG_SZ
, "type=%d\n", type
);
817 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
818 strcpy(buf
, sTestpath1
);
821 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_ZB_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
822 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
823 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
825 size
== 1, /* win2k3 */
827 ok(type
== REG_SZ
, "type=%d\n", type
);
828 ok(!strcmp(sTestpath1
, buf
) ||
830 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1
, buf
);
832 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
833 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
834 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
835 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
836 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
837 ok(type
== REG_SZ
, "type=%d\n", type
);
838 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
840 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
842 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, NULL
, NULL
, &size
);
843 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
844 ok((size
== strlen(expanded2
)+1) || /* win2k3 SP1 */
845 (size
== strlen(expanded2
)+2) || /* win2k3 SP2 */
846 (size
== strlen(sTestpath2
)+1),
847 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
849 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
850 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
851 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
852 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
853 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
854 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
855 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
856 ok(type
== REG_SZ
, "type=%d\n", type
);
857 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
859 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
860 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
861 ret
= pRegGetValueA(hkey_main
, NULL
, "TP2_EXP_SZ", RRF_RT_REG_SZ
, &type
, buf
, &size
);
862 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
863 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
864 ok(size
== strlen(expanded2
)+1 || broken(size
== strlen(sTestpath2
)+1),
865 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2
), lstrlenA(sTestpath2
), size
);
866 ok(type
== REG_SZ
, "type=%d\n", type
);
867 ok(!strcmp(expanded2
, buf
), "expanded2=\"%s\" buf=\"%s\"\n", expanded2
, buf
);
869 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
870 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
871 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, &type
, buf
, &size
);
872 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
873 ok(size
== strlen(sTestpath1
)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
874 ok(type
== REG_EXPAND_SZ
, "type=%d\n", type
);
875 ok(!strcmp(sTestpath1
, buf
), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1
, buf
);
877 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
879 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
|RRF_NOEXPAND
, NULL
, NULL
, &size
);
880 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
881 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
882 ok(size
== strlen(sTestpath1
)+1 || broken(size
== strlen(sTestpath1
)+2),
883 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1
), size
);
885 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
886 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_SZ
|RRF_NOEXPAND
, NULL
, NULL
, NULL
);
887 ok(ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
889 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
890 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ
, NULL
, NULL
, NULL
);
891 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
892 ok(ret
== ERROR_INVALID_PARAMETER
|| ret
== ERROR_UNSUPPORTED_TYPE
, "ret=%d\n", ret
);
894 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
895 buf
[0] = 0; type
= 0xdeadbeef; size
= sizeof(buf
);
896 ret
= pRegGetValueA(hkey_main
, NULL
, "TP1_EXP_SZ", RRF_RT_ANY
, &type
, buf
, &size
);
897 ok(ret
== ERROR_SUCCESS
, "ret=%d\n", ret
);
898 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
899 ok(size
== strlen(expanded
)+1 || broken(size
== strlen(sTestpath1
)+1),
900 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded
), lstrlenA(sTestpath1
), size
);
901 ok(type
== REG_SZ
, "type=%d\n", type
);
902 ok(!strcmp(expanded
, buf
), "expanded=\"%s\" buf=\"%s\"\n", expanded
, buf
);
905 static void test_reg_open_key(void)
908 HKEY hkResult
= NULL
;
909 HKEY hkPreserve
= NULL
;
910 HKEY hkRoot64
= NULL
;
911 HKEY hkRoot32
= NULL
;
913 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
915 EXPLICIT_ACCESSA access
;
917 SECURITY_DESCRIPTOR
*sd
;
919 /* successful open */
920 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
921 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
922 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
923 hkPreserve
= hkResult
;
925 /* open same key twice */
926 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkResult
);
927 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
928 ok(hkResult
!= hkPreserve
, "expected hkResult != hkPreserve\n");
929 ok(hkResult
!= NULL
, "hkResult != NULL\n");
930 RegCloseKey(hkResult
);
932 /* open nonexistent key
933 * check that hkResult is set to NULL
935 hkResult
= hkPreserve
;
936 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
937 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
938 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
940 /* open the same nonexistent key again to make sure the key wasn't created */
941 hkResult
= hkPreserve
;
942 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Nonexistent", &hkResult
);
943 ok(ret
== ERROR_FILE_NOT_FOUND
, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
944 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
946 /* send in NULL lpSubKey
947 * check that hkResult receives the value of hKey
949 hkResult
= hkPreserve
;
950 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, &hkResult
);
951 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
952 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
954 /* send empty-string in lpSubKey */
955 hkResult
= hkPreserve
;
956 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "", &hkResult
);
957 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
958 ok(hkResult
== HKEY_CURRENT_USER
, "expected hkResult == HKEY_CURRENT_USER\n");
960 /* send in NULL lpSubKey and NULL hKey
961 * hkResult is set to NULL
963 hkResult
= hkPreserve
;
964 ret
= RegOpenKeyA(NULL
, NULL
, &hkResult
);
965 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
966 ok(hkResult
== NULL
, "expected hkResult == NULL\n");
968 /* only send NULL hKey
969 * the value of hkResult remains unchanged
971 hkResult
= hkPreserve
;
972 ret
= RegOpenKeyA(NULL
, "Software\\Wine\\Test", &hkResult
);
973 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
974 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
975 ok(hkResult
== hkPreserve
, "expected hkResult == hkPreserve\n");
976 RegCloseKey(hkResult
);
978 /* send in NULL hkResult */
979 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", NULL
);
980 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
982 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, NULL
, NULL
);
983 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
985 ret
= RegOpenKeyA(NULL
, NULL
, NULL
);
986 ok(ret
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
988 /* beginning backslash character */
989 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "\\Software\\Wine\\Test", &hkResult
);
990 ok(ret
== ERROR_BAD_PATHNAME
|| /* NT/2k/XP */
991 broken(ret
== ERROR_SUCCESS
), /* wow64 */
992 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
993 if (!ret
) RegCloseKey(hkResult
);
996 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "\\clsid", 0, KEY_QUERY_VALUE
, &hkResult
);
997 ok(ret
== ERROR_SUCCESS
|| /* 2k/XP */
998 ret
== ERROR_BAD_PATHNAME
, /* NT */
999 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1000 RegCloseKey(hkResult
);
1004 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_32KEY
, &hkResult
);
1005 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1006 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1007 RegCloseKey(hkResult
);
1010 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, KEY_READ
|KEY_WOW64_64KEY
, &hkResult
);
1011 ok((ret
== ERROR_SUCCESS
&& hkResult
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1012 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1013 RegCloseKey(hkResult
);
1015 /* check special HKEYs on 64bit
1016 * only the lower 4 bytes of the supplied key are used
1020 /* HKEY_CURRENT_USER */
1021 ret
= RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER
)), "Software", &hkResult
);
1022 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1023 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1024 RegCloseKey(hkResult
);
1026 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)1 << 32), "Software", &hkResult
);
1027 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1028 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1029 RegCloseKey(hkResult
);
1031 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1032 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1033 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1034 RegCloseKey(hkResult
);
1036 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_CURRENT_USER
) | (ULONG64
)0xffffffff << 32), "Software", &hkResult
);
1037 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1038 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1039 RegCloseKey(hkResult
);
1041 /* HKEY_LOCAL_MACHINE */
1042 ret
= RegOpenKeyA((HKEY
)(HandleToUlong(HKEY_LOCAL_MACHINE
) | (ULONG64
)0xdeadbeef << 32), "Software", &hkResult
);
1043 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1044 ok(hkResult
!= NULL
, "expected hkResult != NULL\n");
1045 RegCloseKey(hkResult
);
1048 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1049 * the registry access check is performed correctly. Redirection isn't
1050 * being tested, so the tests don't care about whether the process is
1051 * running under WOW64. */
1052 if (!pIsWow64Process
)
1054 win_skip("WOW64 flags are not recognized\n");
1058 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1059 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1061 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1062 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1064 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1065 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1067 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1068 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1070 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1071 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1073 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1074 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1076 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1077 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1079 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1081 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1082 access
.grfAccessMode
= SET_ACCESS
;
1083 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1084 access
.Trustee
.pMultipleTrustee
= NULL
;
1085 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1086 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1087 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1088 access
.Trustee
.ptstrName
= (char *)world_sid
;
1090 ret
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1091 ok(ret
== ERROR_SUCCESS
,
1092 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret
, GetLastError());
1094 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1095 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1097 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1099 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1101 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1105 skip("not enough privileges to modify HKLM\n");
1111 error
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1112 ok(error
== ERROR_SUCCESS
,
1113 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1115 bRet
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1116 ok(error
== ERROR_SUCCESS
,
1117 "Expected RegSetKeySecurity to return success, got error %u\n", error
);
1120 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_64KEY
| KEY_READ
, &hkResult
);
1121 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1122 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1123 RegCloseKey(hkResult
);
1126 ret
= RegOpenKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, KEY_WOW64_32KEY
| KEY_READ
, &hkResult
);
1127 ok(ret
== ERROR_SUCCESS
&& hkResult
!= NULL
,
1128 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1129 RegCloseKey(hkResult
);
1132 HeapFree(GetProcessHeap(), 0, sd
);
1135 RegDeleteKeyA(hkRoot64
, "");
1136 RegCloseKey(hkRoot64
);
1137 RegDeleteKeyA(hkRoot32
, "");
1138 RegCloseKey(hkRoot32
);
1141 static void test_reg_create_key(void)
1145 HKEY hkRoot64
= NULL
;
1146 HKEY hkRoot32
= NULL
;
1149 SID_IDENTIFIER_AUTHORITY sid_authority
= {SECURITY_WORLD_SID_AUTHORITY
};
1151 EXPLICIT_ACCESSA access
;
1153 SECURITY_DESCRIPTOR
*sd
;
1155 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1156 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1157 /* should succeed: all versions of Windows ignore the access rights
1158 * to the parent handle */
1159 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &hkey2
, NULL
);
1160 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1163 RegDeleteKeyA(hkey2
, "");
1164 RegDeleteKeyA(hkey1
, "");
1168 /* test creation of volatile keys */
1169 ret
= RegCreateKeyExA(hkey_main
, "Volatile", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey1
, NULL
);
1170 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1171 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1172 ok(ret
== ERROR_CHILD_MUST_BE_VOLATILE
, "RegCreateKeyExA failed with error %d\n", ret
);
1173 if (!ret
) RegCloseKey( hkey2
);
1174 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, REG_OPTION_VOLATILE
, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1175 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1177 /* should succeed if the key already exists */
1178 ret
= RegCreateKeyExA(hkey1
, "Subkey2", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey2
, NULL
);
1179 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1182 RegDeleteKeyA(hkey2
, "");
1183 RegDeleteKeyA(hkey1
, "");
1187 /* beginning backslash character */
1188 ret
= RegCreateKeyExA(hkey_main
, "\\Subkey3", 0, NULL
, 0, KEY_NOTIFY
, NULL
, &hkey1
, NULL
);
1189 if (!(GetVersion() & 0x80000000))
1190 ok(ret
== ERROR_BAD_PATHNAME
, "expected ERROR_BAD_PATHNAME, got %d\n", ret
);
1192 ok(!ret
, "RegCreateKeyExA failed with error %d\n", ret
);
1193 RegDeleteKeyA(hkey1
, NULL
);
1197 /* WOW64 flags - open an existing key */
1199 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_32KEY
, NULL
, &hkey1
, NULL
);
1200 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1201 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1205 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0, KEY_READ
|KEY_WOW64_64KEY
, NULL
, &hkey1
, NULL
);
1206 ok((ret
== ERROR_SUCCESS
&& hkey1
!= NULL
) || broken(ret
== ERROR_ACCESS_DENIED
/* NT4, win2k */),
1207 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1210 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1211 * the registry access check is performed correctly. Redirection isn't
1212 * being tested, so the tests don't care about whether the process is
1213 * running under WOW64. */
1214 if (!pIsWow64Process
)
1216 win_skip("WOW64 flags are not recognized\n");
1220 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1221 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot32
, NULL
);
1223 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot32
== NULL
,
1224 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1226 ok(ret
== ERROR_SUCCESS
&& hkRoot32
!= NULL
,
1227 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret
);
1229 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1230 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &hkRoot64
, NULL
);
1232 ok(ret
== ERROR_ACCESS_DENIED
&& hkRoot64
== NULL
,
1233 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1235 ok(ret
== ERROR_SUCCESS
&& hkRoot64
!= NULL
,
1236 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret
);
1238 bRet
= AllocateAndInitializeSid(&sid_authority
, 1, SECURITY_WORLD_RID
,
1239 0, 0, 0, 0, 0, 0, 0, &world_sid
);
1241 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1243 access
.grfAccessPermissions
= GENERIC_ALL
| STANDARD_RIGHTS_ALL
;
1244 access
.grfAccessMode
= SET_ACCESS
;
1245 access
.grfInheritance
= SUB_CONTAINERS_AND_OBJECTS_INHERIT
;
1246 access
.Trustee
.pMultipleTrustee
= NULL
;
1247 access
.Trustee
.MultipleTrusteeOperation
= NO_MULTIPLE_TRUSTEE
;
1248 access
.Trustee
.TrusteeForm
= TRUSTEE_IS_SID
;
1249 access
.Trustee
.TrusteeType
= TRUSTEE_IS_WELL_KNOWN_GROUP
;
1250 access
.Trustee
.ptstrName
= (char *)world_sid
;
1252 dwRet
= SetEntriesInAclA(1, &access
, NULL
, &key_acl
);
1253 ok(dwRet
== ERROR_SUCCESS
,
1254 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet
, GetLastError());
1256 sd
= HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH
);
1257 bRet
= InitializeSecurityDescriptor(sd
, SECURITY_DESCRIPTOR_REVISION
);
1259 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1261 bRet
= SetSecurityDescriptorDacl(sd
, TRUE
, key_acl
, FALSE
);
1263 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet
, GetLastError());
1267 skip("not enough privileges to modify HKLM\n");
1271 ret
= RegSetKeySecurity(hkRoot64
, DACL_SECURITY_INFORMATION
, sd
);
1272 ok(ret
== ERROR_SUCCESS
,
1273 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1275 ret
= RegSetKeySecurity(hkRoot32
, DACL_SECURITY_INFORMATION
, sd
);
1276 ok(ret
== ERROR_SUCCESS
,
1277 "Expected RegSetKeySecurity to return success, got error %u\n", ret
);
1280 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1281 KEY_WOW64_64KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1282 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1283 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret
);
1287 ret
= RegCreateKeyExA(HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1288 KEY_WOW64_32KEY
| KEY_READ
, NULL
, &hkey1
, NULL
);
1289 ok(ret
== ERROR_SUCCESS
&& hkey1
!= NULL
,
1290 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret
);
1294 HeapFree(GetProcessHeap(), 0, sd
);
1297 RegDeleteKeyA(hkRoot64
, "");
1298 RegCloseKey(hkRoot64
);
1299 RegDeleteKeyA(hkRoot32
, "");
1300 RegCloseKey(hkRoot32
);
1303 static void test_reg_close_key(void)
1308 /* successfully close key
1309 * hkHandle remains changed after call to RegCloseKey
1311 ret
= RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkHandle
);
1312 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1313 ret
= RegCloseKey(hkHandle
);
1314 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1316 /* try to close the key twice */
1317 ret
= RegCloseKey(hkHandle
); /* Windows 95 doesn't mind. */
1318 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_SUCCESS
,
1319 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret
);
1321 /* try to close a NULL handle */
1322 ret
= RegCloseKey(NULL
);
1323 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 95 returns BADKEY */
1324 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1326 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1327 * win98 doesn't give a new handle when the same key is opened.
1328 * Not re-opening will make some next tests fail.
1330 if (hkey_main
== hkHandle
)
1332 trace("The main handle is most likely closed, so re-opening\n");
1333 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey_main
);
1337 static void test_reg_delete_key(void)
1341 ret
= RegDeleteKeyA(hkey_main
, NULL
);
1343 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1344 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1345 * Not re-creating will make some next tests fail.
1347 if (ret
== ERROR_SUCCESS
)
1349 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1350 " re-creating the main key\n");
1354 ok(ret
== ERROR_INVALID_PARAMETER
||
1355 ret
== ERROR_ACCESS_DENIED
||
1356 ret
== ERROR_BADKEY
, /* Win95 */
1360 static void test_reg_save_key(void)
1364 ret
= RegSaveKeyA(hkey_main
, "saved_key", NULL
);
1365 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1368 static void test_reg_load_key(void)
1373 ret
= RegLoadKeyA(HKEY_LOCAL_MACHINE
, "Test", "saved_key");
1374 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1376 ret
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, "Test", &hkHandle
);
1377 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1379 RegCloseKey(hkHandle
);
1382 static void test_reg_unload_key(void)
1386 ret
= RegUnLoadKeyA(HKEY_LOCAL_MACHINE
, "Test");
1387 ok(ret
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %d\n", ret
);
1389 DeleteFileA("saved_key");
1390 DeleteFileA("saved_key.LOG");
1393 static BOOL
set_privileges(LPCSTR privilege
, BOOL set
)
1395 TOKEN_PRIVILEGES tp
;
1399 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1402 if(!LookupPrivilegeValueA(NULL
, privilege
, &luid
))
1404 CloseHandle(hToken
);
1408 tp
.PrivilegeCount
= 1;
1409 tp
.Privileges
[0].Luid
= luid
;
1412 tp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1414 tp
.Privileges
[0].Attributes
= 0;
1416 AdjustTokenPrivileges(hToken
, FALSE
, &tp
, sizeof(TOKEN_PRIVILEGES
), NULL
, NULL
);
1417 if (GetLastError() != ERROR_SUCCESS
)
1419 CloseHandle(hToken
);
1423 CloseHandle(hToken
);
1427 /* tests that show that RegConnectRegistry and
1428 OpenSCManager accept computer names without the
1429 \\ prefix (what MSDN says). */
1430 static void test_regconnectregistry( void)
1432 CHAR compName
[MAX_COMPUTERNAME_LENGTH
+ 1];
1433 CHAR netwName
[MAX_COMPUTERNAME_LENGTH
+ 3]; /* 2 chars for double backslash */
1434 DWORD len
= sizeof(compName
) ;
1440 SetLastError(0xdeadbeef);
1441 ret
= GetComputerNameA(compName
, &len
);
1442 ok( ret
, "GetComputerName failed err = %d\n", GetLastError());
1445 lstrcpyA(netwName
, "\\\\");
1446 lstrcpynA(netwName
+2, compName
, MAX_COMPUTERNAME_LENGTH
+ 1);
1448 retl
= RegConnectRegistryA( compName
, HKEY_LOCAL_MACHINE
, &hkey
);
1450 retl
== ERROR_DLL_INIT_FAILED
||
1451 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1452 "RegConnectRegistryA failed err = %d\n", retl
);
1453 if( !retl
) RegCloseKey( hkey
);
1455 retl
= RegConnectRegistryA( netwName
, HKEY_LOCAL_MACHINE
, &hkey
);
1457 retl
== ERROR_DLL_INIT_FAILED
||
1458 retl
== ERROR_BAD_NETPATH
, /* some win2k */
1459 "RegConnectRegistryA failed err = %d\n", retl
);
1460 if( !retl
) RegCloseKey( hkey
);
1462 SetLastError(0xdeadbeef);
1463 schnd
= OpenSCManagerA( compName
, NULL
, GENERIC_READ
);
1464 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1466 win_skip("OpenSCManagerA is not implemented\n");
1470 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1471 CloseServiceHandle( schnd
);
1473 SetLastError(0xdeadbeef);
1474 schnd
= OpenSCManagerA( netwName
, NULL
, GENERIC_READ
);
1475 ok( schnd
!= NULL
, "OpenSCManagerA failed err = %d\n", GetLastError());
1476 CloseServiceHandle( schnd
);
1480 static void test_reg_query_value(void)
1487 static const WCHAR expected
[] = {'d','a','t','a',0};
1489 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1490 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1492 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1493 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1495 /* try an invalid hkey */
1496 SetLastError(0xdeadbeef);
1498 ret
= RegQueryValueA((HKEY
)0xcafebabe, "subkey", val
, &size
);
1499 ok(ret
== ERROR_INVALID_HANDLE
||
1500 ret
== ERROR_BADKEY
|| /* Windows 98 returns BADKEY */
1501 ret
== ERROR_ACCESS_DENIED
, /* non-admin winxp */
1502 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1503 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1505 /* try a NULL hkey */
1506 SetLastError(0xdeadbeef);
1508 ret
= RegQueryValueA(NULL
, "subkey", val
, &size
);
1509 ok(ret
== ERROR_INVALID_HANDLE
|| ret
== ERROR_BADKEY
, /* Windows 98 returns BADKEY */
1510 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret
);
1511 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1513 /* try a NULL value */
1515 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, &size
);
1516 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1517 ok(size
== 5, "Expected 5, got %d\n", size
);
1519 /* try a NULL size */
1520 SetLastError(0xdeadbeef);
1522 ret
= RegQueryValueA(hkey_main
, "subkey", val
, NULL
);
1523 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
1524 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1525 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1527 /* try a NULL value and size */
1528 ret
= RegQueryValueA(hkey_main
, "subkey", NULL
, NULL
);
1529 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1531 /* try a size too small */
1532 SetLastError(0xdeadbeef);
1535 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1536 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1537 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1538 ok(lstrlenA(val
) == 0, "Expected val to be untouched, got %s\n", val
);
1539 ok(size
== 5, "Expected 5, got %d\n", size
);
1541 /* successfully read the value using 'subkey' */
1543 ret
= RegQueryValueA(hkey_main
, "subkey", val
, &size
);
1544 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1545 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1546 ok(size
== 5, "Expected 5, got %d\n", size
);
1548 /* successfully read the value using the subkey key */
1550 ret
= RegQueryValueA(subkey
, NULL
, val
, &size
);
1551 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1552 ok(!lstrcmpA(val
, "data"), "Expected 'data', got '%s'\n", val
);
1553 ok(size
== 5, "Expected 5, got %d\n", size
);
1555 /* unicode - try size too small */
1556 SetLastError(0xdeadbeef);
1559 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1560 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1562 win_skip("RegQueryValueW is not implemented\n");
1565 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1566 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1567 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1568 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1570 /* unicode - try size in WCHARS */
1571 SetLastError(0xdeadbeef);
1572 size
= sizeof(valW
) / sizeof(WCHAR
);
1573 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1574 ok(ret
== ERROR_MORE_DATA
, "Expected ERROR_MORE_DATA, got %d\n", ret
);
1575 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1576 ok(lstrlenW(valW
) == 0, "Expected valW to be untouched\n");
1577 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1579 /* unicode - successfully read the value */
1580 size
= sizeof(valW
);
1581 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1582 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1583 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1584 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1586 /* unicode - set the value without a NULL terminator */
1587 ret
= RegSetValueW(subkey
, NULL
, REG_SZ
, expected
, sizeof(expected
)-sizeof(WCHAR
));
1588 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1590 /* unicode - read the unterminated value, value is terminated for us */
1591 memset(valW
, 'a', sizeof(valW
));
1592 size
= sizeof(valW
);
1593 ret
= RegQueryValueW(subkey
, NULL
, valW
, &size
);
1594 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1595 ok(!lstrcmpW(valW
, expected
), "Got wrong value\n");
1596 ok(size
== sizeof(expected
), "Got wrong size: %d\n", size
);
1599 RegDeleteKeyA(subkey
, "");
1600 RegCloseKey(subkey
);
1603 static void test_string_termination(void)
1607 static const char string
[] = "FullString";
1610 DWORD insize
, outsize
, nsize
;
1612 ret
= RegCreateKeyA(hkey_main
, "string_termination", &subkey
);
1613 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1615 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1616 insize
=sizeof(string
)-1;
1617 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1618 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1620 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1621 ok(ret
== ERROR_MORE_DATA
, "RegQueryValueExA returned: %d\n", ret
);
1623 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1624 insize
=sizeof(string
)-2;
1625 ret
= RegSetValueExA(subkey
, "stringtest", 0, REG_SZ
, (BYTE
*)string
, insize
);
1626 ok(ret
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", ret
);
1628 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, NULL
, &outsize
);
1629 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1630 ok(outsize
== insize
, "wrong size %u != %u\n", outsize
, insize
);
1632 /* RegQueryValueExA may return a string with no trailing '\0' */
1634 memset(buffer
, 0xbd, sizeof(buffer
));
1635 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1636 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1637 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1638 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1639 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1640 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1642 /* RegQueryValueExA adds a trailing '\0' if there is room */
1644 memset(buffer
, 0xbd, sizeof(buffer
));
1645 ret
= RegQueryValueExA(subkey
, "stringtest", NULL
, NULL
, buffer
, &outsize
);
1646 ok(ret
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", ret
);
1647 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1648 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1649 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1650 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1652 /* RegEnumValueA may return a string with no trailing '\0' */
1654 memset(buffer
, 0xbd, sizeof(buffer
));
1656 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1657 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1658 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1659 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1660 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1661 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1662 ok(buffer
[insize
] == 0xbd, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1664 /* RegEnumValueA adds a trailing '\0' if there is room */
1666 memset(buffer
, 0xbd, sizeof(buffer
));
1668 ret
= RegEnumValueA(subkey
, 0, name
, &nsize
, NULL
, NULL
, buffer
, &outsize
);
1669 ok(ret
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", ret
);
1670 ok(strcmp(name
, "stringtest") == 0, "wrong name: %s\n", name
);
1671 ok(outsize
== insize
, "wrong size: %u != %u\n", outsize
, insize
);
1672 ok(memcmp(buffer
, string
, outsize
) == 0, "bad string: %s/%u != %s\n",
1673 wine_debugstr_an((char*)buffer
, outsize
), outsize
, string
);
1674 ok(buffer
[insize
] == 0, "buffer overflow at %u %02x\n", insize
, buffer
[insize
]);
1676 RegDeleteKeyA(subkey
, "");
1677 RegCloseKey(subkey
);
1680 static void test_reg_delete_tree(void)
1682 CHAR buffer
[MAX_PATH
];
1683 HKEY subkey
, subkey2
;
1686 if(!pRegDeleteTreeA
) {
1687 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1691 ret
= RegCreateKeyA(hkey_main
, "subkey", &subkey
);
1692 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1693 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1694 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1695 ret
= RegSetValueA(subkey
, NULL
, REG_SZ
, "data", 4);
1696 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1697 ret
= RegSetValueA(subkey2
, NULL
, REG_SZ
, "data2", 5);
1698 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1699 ret
= RegCloseKey(subkey2
);
1700 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1702 ret
= pRegDeleteTreeA(subkey
, "subkey2");
1703 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1704 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1705 "subkey2 was not deleted\n");
1707 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1708 "Default value of subkey not longer present\n");
1710 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1711 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1712 ret
= RegCloseKey(subkey2
);
1713 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1714 ret
= pRegDeleteTreeA(hkey_main
, "subkey\\subkey2");
1715 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1716 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1717 "subkey2 was not deleted\n");
1718 ok(!RegQueryValueA(subkey
, NULL
, buffer
, &size
),
1719 "Default value of subkey not longer present\n");
1721 ret
= RegCreateKeyA(subkey
, "subkey2", &subkey2
);
1722 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1723 ret
= RegCloseKey(subkey2
);
1724 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1725 ret
= RegCreateKeyA(subkey
, "subkey3", &subkey2
);
1726 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1727 ret
= RegCloseKey(subkey2
);
1728 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1729 ret
= RegSetValueA(subkey
, "value", REG_SZ
, "data2", 5);
1730 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1731 ret
= pRegDeleteTreeA(subkey
, NULL
);
1732 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
1733 ok(!RegOpenKeyA(hkey_main
, "subkey", &subkey
),
1734 "subkey was deleted\n");
1735 ok(RegOpenKeyA(subkey
, "subkey2", &subkey2
),
1736 "subkey2 was not deleted\n");
1737 ok(RegOpenKeyA(subkey
, "subkey3", &subkey2
),
1738 "subkey3 was not deleted\n");
1740 ret
= RegQueryValueA(subkey
, NULL
, buffer
, &size
);
1741 ok(ret
== ERROR_SUCCESS
,
1742 "Default value of subkey is not present\n");
1743 ok(!lstrlenA(buffer
),
1744 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer
), buffer
);
1746 ok(RegQueryValueA(subkey
, "value", buffer
, &size
),
1747 "Value is still present\n");
1749 ret
= pRegDeleteTreeA(hkey_main
, "not-here");
1750 ok(ret
== ERROR_FILE_NOT_FOUND
,
1751 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret
);
1754 static void test_rw_order(void)
1758 static const char keyname
[] = "test_rw_order";
1760 DWORD values
, value_len
, value_name_max_len
;
1763 RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
);
1764 ret
= RegCreateKeyA(HKEY_CURRENT_USER
, keyname
, &hKey
);
1765 if(ret
!= ERROR_SUCCESS
) {
1766 skip("Couldn't create key. Skipping.\n");
1770 ok(!RegSetValueExA(hKey
, "A", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1771 "RegSetValueExA for value \"A\" failed\n");
1772 ok(!RegSetValueExA(hKey
, "C", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1773 "RegSetValueExA for value \"C\" failed\n");
1774 ok(!RegSetValueExA(hKey
, "D", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1775 "RegSetValueExA for value \"D\" failed\n");
1776 ok(!RegSetValueExA(hKey
, "B", 0, REG_DWORD
, (LPBYTE
)&dw
, sizeof(dw
)),
1777 "RegSetValueExA for value \"B\" failed\n");
1779 ok(!RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &values
,
1780 &value_name_max_len
, NULL
, NULL
, NULL
), "RegQueryInfoKeyA failed\n");
1781 ok(values
== 4, "Expected 4 values, got %u\n", values
);
1783 /* Value enumeration preserves RegSetValueEx call order */
1785 ok(!RegEnumValueA(hKey
, 0, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1786 ok(strcmp(value_buf
, "A") == 0, "Expected name \"A\", got %s\n", value_buf
);
1788 ok(!RegEnumValueA(hKey
, 1, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1789 todo_wine
ok(strcmp(value_buf
, "C") == 0, "Expected name \"C\", got %s\n", value_buf
);
1791 ok(!RegEnumValueA(hKey
, 2, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1792 todo_wine
ok(strcmp(value_buf
, "D") == 0, "Expected name \"D\", got %s\n", value_buf
);
1794 ok(!RegEnumValueA(hKey
, 3, value_buf
, &value_len
, NULL
, NULL
, NULL
, NULL
), "RegEnumValueA failed\n");
1795 todo_wine
ok(strcmp(value_buf
, "B") == 0, "Expected name \"B\", got %s\n", value_buf
);
1797 ok(!RegDeleteKeyA(HKEY_CURRENT_USER
, keyname
), "Failed to delete key\n");
1800 static void test_symlinks(void)
1802 static const WCHAR targetW
[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1803 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1805 UNICODE_STRING target_str
;
1809 DWORD target_len
, type
, len
, dw
, err
;
1811 if (!pRtlFormatCurrentUserKeyPath
|| !pNtDeleteKey
)
1813 win_skip( "Can't perform symlink tests\n" );
1817 pRtlFormatCurrentUserKeyPath( &target_str
);
1819 target_len
= target_str
.Length
+ sizeof(targetW
);
1820 target
= HeapAlloc( GetProcessHeap(), 0, target_len
);
1821 memcpy( target
, target_str
.Buffer
, target_str
.Length
);
1822 memcpy( target
+ target_str
.Length
/sizeof(WCHAR
), targetW
, sizeof(targetW
) );
1824 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1825 KEY_ALL_ACCESS
, NULL
, &link
, NULL
);
1826 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed: %u\n", err
);
1828 /* REG_SZ is not allowed */
1829 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_SZ
, (BYTE
*)"foobar", sizeof("foobar") );
1830 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1831 err
= RegSetValueExA( link
, "SymbolicLinkValue", 0, REG_LINK
,
1832 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1833 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1834 /* other values are not allowed */
1835 err
= RegSetValueExA( link
, "link", 0, REG_LINK
, (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1836 ok( err
== ERROR_ACCESS_DENIED
, "RegSetValueEx wrong error %u\n", err
);
1838 /* try opening the target through the link */
1840 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1841 ok( err
== ERROR_FILE_NOT_FOUND
, "RegOpenKey wrong error %u\n", err
);
1843 err
= RegCreateKeyExA( hkey_main
, "target", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1844 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1847 err
= RegSetValueExA( key
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1848 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1851 err
= RegOpenKeyA( hkey_main
, "link", &key
);
1852 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1854 len
= sizeof(buffer
);
1855 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1856 ok( err
== ERROR_SUCCESS
, "RegOpenKey failed error %u\n", err
);
1857 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1859 len
= sizeof(buffer
);
1860 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1861 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1863 /* REG_LINK can be created in non-link keys */
1864 err
= RegSetValueExA( key
, "SymbolicLinkValue", 0, REG_LINK
,
1865 (BYTE
*)target
, target_len
- sizeof(WCHAR
) );
1866 ok( err
== ERROR_SUCCESS
, "RegSetValueEx failed error %u\n", err
);
1867 len
= sizeof(buffer
);
1868 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1869 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1870 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1871 err
= RegDeleteValueA( key
, "SymbolicLinkValue" );
1872 ok( err
== ERROR_SUCCESS
, "RegDeleteValue failed error %u\n", err
);
1876 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1877 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1879 len
= sizeof(buffer
);
1880 err
= RegQueryValueExA( key
, "value", NULL
, &type
, buffer
, &len
);
1881 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1882 ok( len
== sizeof(DWORD
), "wrong len %u\n", len
);
1884 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1885 ok( err
== ERROR_FILE_NOT_FOUND
, "RegQueryValueEx wrong error %u\n", err
);
1888 /* now open the symlink itself */
1890 err
= RegOpenKeyExA( hkey_main
, "link", REG_OPTION_OPEN_LINK
, KEY_ALL_ACCESS
, &key
);
1891 ok( err
== ERROR_SUCCESS
, "RegOpenKeyEx failed error %u\n", err
);
1892 len
= sizeof(buffer
);
1893 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1894 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1895 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1898 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_OPEN_LINK
,
1899 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1900 ok( err
== ERROR_SUCCESS
, "RegCreateKeyEx failed error %u\n", err
);
1901 len
= sizeof(buffer
);
1902 err
= RegQueryValueExA( key
, "SymbolicLinkValue", NULL
, &type
, buffer
, &len
);
1903 ok( err
== ERROR_SUCCESS
, "RegQueryValueEx failed error %u\n", err
);
1904 ok( len
== target_len
- sizeof(WCHAR
), "wrong len %u\n", len
);
1907 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
,
1908 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1909 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1911 err
= RegCreateKeyExA( hkey_main
, "link", 0, NULL
, REG_OPTION_CREATE_LINK
| REG_OPTION_OPEN_LINK
,
1912 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1913 ok( err
== ERROR_ALREADY_EXISTS
, "RegCreateKeyEx wrong error %u\n", err
);
1915 err
= RegDeleteKeyA( hkey_main
, "target" );
1916 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed error %u\n", err
);
1918 err
= RegDeleteKeyA( hkey_main
, "link" );
1919 ok( err
== ERROR_FILE_NOT_FOUND
, "RegDeleteKey wrong error %u\n", err
);
1921 status
= pNtDeleteKey( link
);
1922 ok( !status
, "NtDeleteKey failed: 0x%08x\n", status
);
1923 RegCloseKey( link
);
1925 HeapFree( GetProcessHeap(), 0, target
);
1926 pRtlFreeUnicodeString( &target_str
);
1929 static DWORD
get_key_value( HKEY root
, const char *name
, DWORD flags
)
1932 DWORD err
, type
, dw
, len
= sizeof(dw
);
1934 err
= RegCreateKeyExA( root
, name
, 0, NULL
, 0, flags
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
1935 if (err
== ERROR_FILE_NOT_FOUND
) return 0;
1936 ok( err
== ERROR_SUCCESS
, "%08x: RegCreateKeyEx failed: %u\n", flags
, err
);
1938 err
= RegQueryValueExA( key
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1939 if (err
== ERROR_FILE_NOT_FOUND
)
1942 ok( err
== ERROR_SUCCESS
, "%08x: RegQueryValueEx failed: %u\n", flags
, err
);
1947 static void _check_key_value( int line
, HANDLE root
, const char *name
, DWORD flags
, DWORD expect
)
1949 DWORD dw
= get_key_value( root
, name
, flags
);
1950 ok_(__FILE__
,line
)( dw
== expect
, "%08x: wrong value %u/%u\n", flags
, dw
, expect
);
1952 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1954 static void test_redirection(void)
1956 DWORD err
, type
, dw
, len
;
1957 HKEY key
, root32
, root64
, key32
, key64
, native
, op_key
;
1958 BOOL is_vista
= FALSE
;
1959 REGSAM opposite
= (sizeof(void*) == 8 ? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
);
1964 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
) || !is_wow64
)
1966 skip( "Not on Wow64, no redirection\n" );
1971 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1972 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &root64
, NULL
);
1973 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1975 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
1976 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &root32
, NULL
);
1977 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1979 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1980 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key64
, NULL
);
1981 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1983 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, NULL
, 0,
1984 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key32
, NULL
);
1985 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
1988 err
= RegSetValueExA( key64
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1989 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1992 err
= RegSetValueExA( key32
, "value", 0, REG_DWORD
, (BYTE
*)&dw
, sizeof(dw
) );
1993 ok( err
== ERROR_SUCCESS
, "RegSetValueExA failed: %u\n", err
);
1997 err
= RegQueryValueExA( key32
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
1998 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
1999 ok( dw
== 32, "wrong value %u\n", dw
);
2003 err
= RegQueryValueExA( key64
, "value", NULL
, &type
, (BYTE
*)&dw
, &len
);
2004 ok( err
== ERROR_SUCCESS
, "RegQueryValueExA failed: %u\n", err
);
2005 ok( dw
== 64, "wrong value %u\n", dw
);
2007 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2008 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2009 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2013 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2014 /* the new (and simpler) Win7 mechanism doesn't */
2015 if (get_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2017 trace( "using Vista-style Wow6432Node handling\n" );
2020 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2021 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2022 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2023 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2024 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2025 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2029 if (get_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
) == 64)
2031 trace( "using Vista-style Wow6432Node handling\n" );
2034 check_key_value( key
, "Wine\\Winetest", 0, 64 );
2035 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2041 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2042 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2043 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2044 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2045 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2046 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2047 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2048 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2049 dw
= get_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
);
2050 ok( dw
== 32 || broken(dw
== 64) /* xp64 */, "wrong value %u\n", dw
);
2051 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2054 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software", 0, NULL
, 0,
2055 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2056 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2057 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2058 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2059 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2060 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", 0, is_vista
? 32 : 0 );
2061 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 0 );
2062 check_key_value( key
, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, is_vista
? 32 : 0 );
2066 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", 0, ptr_size
);
2067 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2070 /* KEY_WOW64 flags have no effect on 64-bit */
2071 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2072 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2073 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2074 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2078 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_64KEY
, 64 );
2079 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2080 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2081 check_key_value( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2084 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2085 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2086 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2087 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2088 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2089 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2094 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2095 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2096 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2097 dw
= get_key_value( key
, "Wine\\Winetest", 0 );
2098 ok( dw
== (is_vista
? 64 : 32) || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2099 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2100 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2103 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node", 0, NULL
, 0,
2104 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2105 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2106 check_key_value( key
, "Wine\\Winetest", 0, 32 );
2107 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2108 check_key_value( key
, "Wine\\Winetest", KEY_WOW64_32KEY
, 32 );
2112 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2113 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2114 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2115 check_key_value( key
, "Winetest", 0, 32 );
2116 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2117 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2122 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2123 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2124 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2125 dw
= get_key_value( key
, "Winetest", 0 );
2126 ok( dw
== 32 || (is_vista
&& dw
== 64), "wrong value %u\n", dw
);
2127 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2128 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2131 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wow6432Node\\Wine", 0, NULL
, 0,
2132 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2133 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2134 check_key_value( key
, "Winetest", 0, 32 );
2135 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2136 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2140 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2141 KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2142 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2143 check_key_value( key
, "Winetest", 0, ptr_size
);
2144 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : ptr_size
);
2145 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2146 if (ptr_size
== 32) ok( dw
== 32, "wrong value %u\n", dw
);
2147 else todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2152 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2153 KEY_WOW64_64KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2154 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2155 dw
= get_key_value( key
, "Winetest", 0 );
2156 ok( dw
== 64 || broken(dw
== 32) /* xp64 */, "wrong value %u\n", dw
);
2157 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, 64 );
2158 dw
= get_key_value( key
, "Winetest", KEY_WOW64_32KEY
);
2159 todo_wine
ok( dw
== 32, "wrong value %u\n", dw
);
2162 err
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Wine", 0, NULL
, 0,
2163 KEY_WOW64_32KEY
| KEY_ALL_ACCESS
, NULL
, &key
, NULL
);
2164 ok( err
== ERROR_SUCCESS
, "RegCreateKeyExA failed: %u\n", err
);
2165 check_key_value( key
, "Winetest", 0, 32 );
2166 check_key_value( key
, "Winetest", KEY_WOW64_64KEY
, is_vista
? 64 : 32 );
2167 check_key_value( key
, "Winetest", KEY_WOW64_32KEY
, 32 );
2171 if (pRegDeleteKeyExA
)
2173 err
= pRegDeleteKeyExA( key32
, "", KEY_WOW64_32KEY
, 0 );
2174 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2175 err
= pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2176 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2177 pRegDeleteKeyExA( key64
, "", KEY_WOW64_64KEY
, 0 );
2178 pRegDeleteKeyExA( root64
, "", KEY_WOW64_64KEY
, 0 );
2182 err
= RegDeleteKeyA( key32
, "" );
2183 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2184 err
= RegDeleteKeyA( key64
, "" );
2185 ok( err
== ERROR_SUCCESS
, "RegDeleteKey failed: %u\n", err
);
2186 RegDeleteKeyA( key64
, "" );
2187 RegDeleteKeyA( root64
, "" );
2189 RegCloseKey( key32
);
2190 RegCloseKey( key64
);
2191 RegCloseKey( root32
);
2192 RegCloseKey( root64
);
2194 /* open key in native bit mode */
2195 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
, &native
);
2196 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2198 pRegDeleteKeyExA(native
, "AWineTest", 0, 0);
2200 /* write subkey in opposite bit mode */
2201 err
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "Interface", 0, KEY_ALL_ACCESS
| opposite
, &op_key
);
2202 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2204 err
= RegCreateKeyExA(op_key
, "AWineTest", 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
,
2206 ok(err
== ERROR_SUCCESS
|| err
== ERROR_ACCESS_DENIED
, "got %i\n", err
);
2207 if(err
!= ERROR_SUCCESS
){
2208 win_skip("Can't write to registry\n");
2209 RegCloseKey(op_key
);
2210 RegCloseKey(native
);
2215 /* verify subkey is not present in native mode */
2216 err
= RegOpenKeyExA(native
, "AWineTest", 0, KEY_ALL_ACCESS
, &key
);
2217 ok(err
== ERROR_FILE_NOT_FOUND
||
2218 broken(err
== ERROR_SUCCESS
), /* before Win7, HKCR is reflected instead of redirected */
2221 err
= pRegDeleteKeyExA(op_key
, "AWineTest", opposite
, 0);
2222 ok(err
== ERROR_SUCCESS
, "got %i\n", err
);
2224 RegCloseKey(op_key
);
2225 RegCloseKey(native
);
2228 static void test_classesroot(void)
2230 HKEY hkey
, hklm
, hkcr
, hkeysub1
, hklmsub1
, hkcrsub1
, hklmsub2
, hkcrsub2
;
2232 DWORD type
= REG_SZ
;
2233 static CHAR buffer
[8];
2236 /* create a key in the user's classes */
2237 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkey
))
2240 RegCloseKey( hkey
);
2242 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2243 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
);
2244 if (res
== ERROR_ACCESS_DENIED
)
2246 skip("not enough privileges to add a user class\n");
2249 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2251 /* try to open that key in hkcr */
2252 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2253 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2254 todo_wine
ok(res
== ERROR_SUCCESS
||
2255 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2256 "test key not found in hkcr: %d\n", res
);
2259 skip("HKCR key merging not supported\n");
2261 RegCloseKey( hkey
);
2265 todo_wine
ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2267 /* set a value in user's classes */
2268 res
= RegSetValueExA(hkey
, "val1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2269 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2271 /* try to find the value in hkcr */
2272 res
= RegQueryValueExA(hkcr
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2273 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2274 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2276 /* modify the value in hkcr */
2277 res
= RegSetValueExA(hkcr
, "val1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2278 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2280 /* check if the value is also modified in user's classes */
2281 res
= RegQueryValueExA(hkey
, "val1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2282 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2283 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2285 /* set a value in hkcr */
2286 res
= RegSetValueExA(hkcr
, "val0", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2287 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2289 /* try to find the value in user's classes */
2290 res
= RegQueryValueExA(hkey
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2291 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2292 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2294 /* modify the value in user's classes */
2295 res
= RegSetValueExA(hkey
, "val0", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2296 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2298 /* check if the value is also modified in hkcr */
2299 res
= RegQueryValueExA(hkcr
, "val0", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2300 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2301 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2306 RegCloseKey( hkey
);
2307 RegCloseKey( hkcr
);
2309 /* create a key in the hklm classes */
2310 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2313 RegCloseKey( hklm
);
2315 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, REG_OPTION_NON_VOLATILE
,
2316 KEY_ALL_ACCESS
, NULL
, &hklm
, NULL
);
2317 if (res
== ERROR_ACCESS_DENIED
)
2319 skip("not enough privileges to add a system class\n");
2322 ok(!IS_HKCR(hklm
), "hkcr mask set in %p\n", hklm
);
2324 /* try to open that key in hkcr */
2325 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2326 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2327 ok(res
== ERROR_SUCCESS
,
2328 "test key not found in hkcr: %d\n", res
);
2329 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2333 RegCloseKey( hklm
);
2337 /* set a value in hklm classes */
2338 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2339 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2341 /* try to find the value in hkcr */
2342 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2343 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2344 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2346 /* modify the value in hkcr */
2347 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2348 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2350 /* check that the value is modified in hklm classes */
2351 res
= RegQueryValueExA(hklm
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2352 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2353 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2355 if (RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2356 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkey
, NULL
)) return;
2357 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2359 /* try to open that key in hkcr */
2360 res
= RegOpenKeyExA( HKEY_CLASSES_ROOT
, "WineTestCls", 0,
2361 KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcr
);
2362 ok(res
== ERROR_SUCCESS
,
2363 "test key not found in hkcr: %d\n", res
);
2364 ok(IS_HKCR(hkcr
), "hkcr mask not set in %p\n", hkcr
);
2366 /* set a value in user's classes */
2367 res
= RegSetValueExA(hkey
, "val2", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2368 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2370 /* try to find the value in hkcr */
2371 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2372 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2373 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2375 /* modify the value in hklm */
2376 res
= RegSetValueExA(hklm
, "val2", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2377 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2379 /* check that the value is not overwritten in hkcr or user's classes */
2380 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2381 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2382 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2383 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2384 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2385 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2387 /* modify the value in hkcr */
2388 res
= RegSetValueExA(hkcr
, "val2", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2389 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2391 /* check that the value is overwritten in hklm and user's classes */
2392 res
= RegQueryValueExA(hkcr
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2393 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2394 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2395 res
= RegQueryValueExA(hkey
, "val2", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2396 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2397 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2399 /* create a subkey in hklm */
2400 if (RegCreateKeyExA( hklm
, "subkey1", 0, NULL
, 0,
2401 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hklmsub1
, NULL
)) return;
2402 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2403 /* try to open that subkey in hkcr */
2404 res
= RegOpenKeyExA( hkcr
, "subkey1", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hkcrsub1
);
2405 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2406 ok(IS_HKCR(hkcrsub1
), "hkcr mask not set in %p\n", hkcrsub1
);
2408 /* set a value in hklm classes */
2409 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2410 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2412 /* try to find the value in hkcr */
2413 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2414 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2415 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2417 /* modify the value in hkcr */
2418 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2419 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2421 /* check that the value is modified in hklm classes */
2422 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2423 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2424 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2426 /* create a subkey in user's classes */
2427 if (RegCreateKeyExA( hkey
, "subkey1", 0, NULL
, 0,
2428 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkeysub1
, NULL
)) return;
2429 ok(!IS_HKCR(hkeysub1
), "hkcr mask set in %p\n", hkeysub1
);
2431 /* set a value in user's classes */
2432 res
= RegSetValueExA(hkeysub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"user", sizeof("user"));
2433 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2435 /* try to find the value in hkcr */
2436 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2437 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2438 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2440 /* modify the value in hklm */
2441 res
= RegSetValueExA(hklmsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hklm", sizeof("hklm"));
2442 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2444 /* check that the value is not overwritten in hkcr or user's classes */
2445 res
= RegQueryValueExA(hkcrsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2446 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2447 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2448 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2449 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2450 ok(!strcmp( buffer
, "user" ), "value set to '%s'\n", buffer
);
2452 /* modify the value in hkcr */
2453 res
= RegSetValueExA(hkcrsub1
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2454 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2456 /* check that the value is not overwritten in hklm, but in user's classes */
2457 res
= RegQueryValueExA(hklmsub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2458 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2459 ok(!strcmp( buffer
, "hklm" ), "value set to '%s'\n", buffer
);
2460 res
= RegQueryValueExA(hkeysub1
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2461 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2462 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2464 /* new subkey in hkcr */
2465 if (RegCreateKeyExA( hkcr
, "subkey2", 0, NULL
, 0,
2466 KEY_QUERY_VALUE
|KEY_SET_VALUE
, NULL
, &hkcrsub2
, NULL
)) return;
2467 ok(IS_HKCR(hkcrsub2
), "hkcr mask not set in %p\n", hkcrsub2
);
2468 res
= RegSetValueExA(hkcrsub2
, "subval1", 0, REG_SZ
, (const BYTE
*)"hkcr", sizeof("hkcr"));
2469 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d, GLE=%x\n", res
, GetLastError());
2471 /* try to open that new subkey in user's classes and hklm */
2472 res
= RegOpenKeyExA( hkey
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2473 ok(res
!= ERROR_SUCCESS
, "test key found in user's classes: %d\n", res
);
2475 res
= RegOpenKeyExA( hklm
, "subkey2", 0, KEY_QUERY_VALUE
|KEY_SET_VALUE
, &hklmsub2
);
2476 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2477 ok(!IS_HKCR(hklmsub2
), "hkcr mask set in %p\n", hklmsub2
);
2479 /* check that the value is present in hklm */
2480 res
= RegQueryValueExA(hklmsub2
, "subval1", NULL
, &type
, (LPBYTE
)buffer
, &size
);
2481 ok(res
== ERROR_SUCCESS
, "RegQueryValueExA failed: %d\n", res
);
2482 ok(!strcmp( buffer
, "hkcr" ), "value set to '%s'\n", buffer
);
2485 RegCloseKey( hkeysub1
);
2486 RegCloseKey( hklmsub1
);
2488 /* delete subkey1 from hkcr (should point at user's classes) */
2489 res
= RegDeleteKeyA(hkcr
, "subkey1");
2490 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2492 /* confirm key was removed in hkey but not hklm */
2493 res
= RegOpenKeyExA(hkey
, "subkey1", 0, KEY_READ
, &hkeysub1
);
2494 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in user's classes: %d\n", res
);
2495 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2496 ok(res
== ERROR_SUCCESS
, "test key not found in hklm: %d\n", res
);
2497 ok(!IS_HKCR(hklmsub1
), "hkcr mask set in %p\n", hklmsub1
);
2499 /* delete subkey1 from hkcr again (which should now point at hklm) */
2500 res
= RegDeleteKeyA(hkcr
, "subkey1");
2501 ok(res
== ERROR_SUCCESS
, "RegDeleteKey failed: %d\n", res
);
2503 /* confirm hkey was removed in hklm */
2504 RegCloseKey( hklmsub1
);
2505 res
= RegOpenKeyExA(hklm
, "subkey1", 0, KEY_READ
, &hklmsub1
);
2506 ok(res
== ERROR_FILE_NOT_FOUND
, "test key found in hklm: %d\n", res
);
2512 delete_key( hkeysub1
);
2513 delete_key( hklmsub1
);
2514 delete_key( hkcrsub1
);
2515 delete_key( hklmsub2
);
2516 delete_key( hkcrsub2
);
2517 RegCloseKey( hkey
);
2518 RegCloseKey( hklm
);
2519 RegCloseKey( hkcr
);
2520 RegCloseKey( hkeysub1
);
2521 RegCloseKey( hklmsub1
);
2522 RegCloseKey( hkcrsub1
);
2523 RegCloseKey( hklmsub2
);
2524 RegCloseKey( hkcrsub2
);
2527 static void test_classesroot_enum(void)
2529 HKEY hkcu
=0, hklm
=0, hkcr
=0, hkcusub
[2]={0}, hklmsub
[2]={0};
2531 static CHAR buffer
[2];
2534 /* prepare initial testing env in HKCU */
2535 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", &hkcu
))
2538 RegCloseKey( hkcu
);
2540 res
= RegCreateKeyExA( HKEY_CURRENT_USER
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2541 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hkcu
, NULL
);
2543 if (res
!= ERROR_SUCCESS
)
2545 skip("failed to add a user class\n");
2549 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2550 todo_wine
ok(res
== ERROR_SUCCESS
||
2551 broken(res
== ERROR_FILE_NOT_FOUND
/* WinNT */),
2552 "test key not found in hkcr: %d\n", res
);
2555 skip("HKCR key merging not supported\n");
2557 RegCloseKey( hkcu
);
2561 res
= RegSetValueExA( hkcu
, "X", 0, REG_SZ
, (const BYTE
*) "AA", 3 );
2562 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2563 res
= RegSetValueExA( hkcu
, "Y", 0, REG_SZ
, (const BYTE
*) "B", 2 );
2564 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2565 res
= RegCreateKeyA( hkcu
, "A", &hkcusub
[0] );
2566 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2567 res
= RegCreateKeyA( hkcu
, "B", &hkcusub
[1] );
2568 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2570 /* test on values in HKCU */
2571 size
= sizeof(buffer
);
2572 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2573 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2574 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2575 size
= sizeof(buffer
);
2576 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2577 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2578 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2579 size
= sizeof(buffer
);
2580 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2581 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2583 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2584 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2585 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2586 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2587 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2588 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2589 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2590 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2592 /* prepare test env in HKLM */
2593 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", &hklm
))
2596 RegCloseKey( hklm
);
2599 res
= RegCreateKeyExA( HKEY_LOCAL_MACHINE
, "Software\\Classes\\WineTestCls", 0, NULL
, 0,
2600 KEY_SET_VALUE
|KEY_ENUMERATE_SUB_KEYS
, NULL
, &hklm
, NULL
);
2602 if (res
== ERROR_ACCESS_DENIED
)
2604 RegCloseKey( hkcusub
[0] );
2605 RegCloseKey( hkcusub
[1] );
2607 RegCloseKey( hkcu
);
2608 RegCloseKey( hkcr
);
2609 skip("not enough privileges to add a system class\n");
2613 res
= RegSetValueExA( hklm
, "X", 0, REG_SZ
, (const BYTE
*) "AB", 3 );
2614 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2615 res
= RegSetValueExA( hklm
, "Z", 0, REG_SZ
, (const BYTE
*) "C", 2 );
2616 ok(res
== ERROR_SUCCESS
, "RegSetValueExA failed: %d\n", res
);
2617 res
= RegCreateKeyA( hklm
, "A", &hklmsub
[0] );
2618 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2619 res
= RegCreateKeyA( hklm
, "C", &hklmsub
[1] );
2620 ok(res
== ERROR_SUCCESS
, "RegCreateKeyA failed: %d\n", res
);
2622 /* test on values/keys in both HKCU and HKLM */
2623 size
= sizeof(buffer
);
2624 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2625 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2626 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2627 size
= sizeof(buffer
);
2628 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2629 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2630 ok(!strcmp( buffer
, "Y" ), "expected 'Y', got '%s'\n", buffer
);
2631 size
= sizeof(buffer
);
2632 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2633 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2634 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2635 size
= sizeof(buffer
);
2636 res
= RegEnumValueA( hkcr
, 3, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2637 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2639 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2640 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2641 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2642 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2643 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2644 ok(!strcmp( buffer
, "B" ), "expected 'B', got '%s'\n", buffer
);
2645 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2646 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2647 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2648 res
= RegEnumKeyA( hkcr
, 3, buffer
, size
);
2649 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2651 /* delete values/keys from HKCU to test only on HKLM */
2652 RegCloseKey( hkcusub
[0] );
2653 RegCloseKey( hkcusub
[1] );
2655 RegCloseKey( hkcu
);
2657 size
= sizeof(buffer
);
2658 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2659 ok(res
== ERROR_KEY_DELETED
||
2660 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2661 "expected ERROR_KEY_DELETED, got %d\n", res
);
2662 size
= sizeof(buffer
);
2663 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2664 ok(res
== ERROR_KEY_DELETED
||
2665 res
== ERROR_NO_SYSTEM_RESOURCES
, /* Windows XP */
2666 "expected ERROR_KEY_DELETED, got %d\n", res
);
2668 /* reopen HKCR handle */
2669 RegCloseKey( hkcr
);
2670 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "WineTestCls", &hkcr
);
2671 ok(res
== ERROR_SUCCESS
, "test key not found in hkcr: %d\n", res
);
2672 if (res
) goto cleanup
;
2674 /* test on values/keys in HKLM */
2675 size
= sizeof(buffer
);
2676 res
= RegEnumValueA( hkcr
, 0, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2677 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2678 ok(!strcmp( buffer
, "X" ), "expected 'X', got '%s'\n", buffer
);
2679 size
= sizeof(buffer
);
2680 res
= RegEnumValueA( hkcr
, 1, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2681 ok(res
== ERROR_SUCCESS
, "RegEnumValueA failed: %d\n", res
);
2682 ok(!strcmp( buffer
, "Z" ), "expected 'Z', got '%s'\n", buffer
);
2683 size
= sizeof(buffer
);
2684 res
= RegEnumValueA( hkcr
, 2, buffer
, &size
, NULL
, NULL
, NULL
, NULL
);
2685 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2687 res
= RegEnumKeyA( hkcr
, 0, buffer
, size
);
2688 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2689 ok(!strcmp( buffer
, "A" ), "expected 'A', got '%s'\n", buffer
);
2690 res
= RegEnumKeyA( hkcr
, 1, buffer
, size
);
2691 ok(res
== ERROR_SUCCESS
, "RegEnumKey failed: %d\n", res
);
2692 ok(!strcmp( buffer
, "C" ), "expected 'C', got '%s'\n", buffer
);
2693 res
= RegEnumKeyA( hkcr
, 2, buffer
, size
);
2694 ok(res
== ERROR_NO_MORE_ITEMS
, "expected ERROR_NO_MORE_ITEMS, got %d\n", res
);
2697 RegCloseKey( hklmsub
[0] );
2698 RegCloseKey( hklmsub
[1] );
2700 RegCloseKey( hklm
);
2701 RegCloseKey( hkcr
);
2704 static void test_classesroot_mask(void)
2709 res
= RegOpenKeyA( HKEY_CLASSES_ROOT
, "CLSID", &hkey
);
2710 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2711 todo_wine
ok(IS_HKCR(hkey
) || broken(!IS_HKCR(hkey
)) /* WinNT */,
2712 "hkcr mask not set in %p\n", hkey
);
2713 RegCloseKey( hkey
);
2715 res
= RegOpenKeyA( HKEY_CURRENT_USER
, "Software", &hkey
);
2716 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2717 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2718 RegCloseKey( hkey
);
2720 res
= RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software", &hkey
);
2721 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2722 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2723 RegCloseKey( hkey
);
2725 res
= RegOpenKeyA( HKEY_USERS
, ".Default", &hkey
);
2726 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2727 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2728 RegCloseKey( hkey
);
2730 res
= RegOpenKeyA( HKEY_CURRENT_CONFIG
, "Software", &hkey
);
2731 ok(res
== ERROR_SUCCESS
, "RegOpenKeyA failed: %d\n", res
);
2732 ok(!IS_HKCR(hkey
), "hkcr mask set in %p\n", hkey
);
2733 RegCloseKey( hkey
);
2736 static void test_deleted_key(void)
2740 DWORD val_count
, type
;
2743 /* Open the test key, then delete it while it's open */
2744 RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Test", &hkey
);
2746 delete_key( hkey_main
);
2748 val_count
= sizeof(value
);
2750 res
= RegEnumValueA( hkey
, 0, value
, &val_count
, NULL
, &type
, 0, 0 );
2751 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2753 res
= RegEnumKeyA( hkey
, 0, value
, sizeof(value
) );
2754 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2756 val_count
= sizeof(value
);
2758 res
= RegQueryValueExA( hkey
, "test", NULL
, &type
, (BYTE
*)value
, &val_count
);
2759 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2761 res
= RegSetValueExA( hkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2762 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2764 res
= RegOpenKeyA( hkey
, "test", &hkey2
);
2765 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2767 RegCloseKey( hkey2
);
2769 res
= RegCreateKeyA( hkey
, "test", &hkey2
);
2770 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2772 RegCloseKey( hkey2
);
2774 res
= RegFlushKey( hkey
);
2775 ok(res
== ERROR_KEY_DELETED
, "expect ERROR_KEY_DELETED, got %i\n", res
);
2777 RegCloseKey( hkey
);
2782 static void test_delete_value(void)
2787 res
= RegSetValueExA( hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6 );
2788 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2790 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2791 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2793 res
= RegDeleteValueA( hkey_main
, "test" );
2794 ok(res
== ERROR_SUCCESS
, "expect ERROR_SUCCESS, got %i\n", res
);
2796 res
= RegQueryValueExA( hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2797 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2799 res
= RegDeleteValueA( hkey_main
, "test" );
2800 ok(res
== ERROR_FILE_NOT_FOUND
, "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2802 memset(longname
, 'a', 400);
2804 res
= RegDeleteValueA( hkey_main
, longname
);
2805 ok(res
== ERROR_FILE_NOT_FOUND
|| broken(res
== ERROR_MORE_DATA
), /* nt4, win2k */
2806 "expect ERROR_FILE_NOT_FOUND, got %i\n", res
);
2809 static void test_delete_key_value(void)
2814 if (!pRegDeleteKeyValueA
)
2816 win_skip("RegDeleteKeyValue is not available.\n");
2820 ret
= pRegDeleteKeyValueA(NULL
, NULL
, NULL
);
2821 ok(ret
== ERROR_INVALID_HANDLE
, "got %d\n", ret
);
2823 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, NULL
);
2824 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2826 ret
= RegSetValueExA(hkey_main
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2827 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2829 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2830 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2832 /* NULL subkey name means delete from open key */
2833 ret
= pRegDeleteKeyValueA(hkey_main
, NULL
, "test");
2834 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2836 ret
= RegQueryValueExA(hkey_main
, "test", NULL
, NULL
, NULL
, NULL
);
2837 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2839 /* now with real subkey */
2840 ret
= RegCreateKeyExA(hkey_main
, "Subkey1", 0, NULL
, 0, KEY_WRITE
|KEY_READ
, NULL
, &subkey
, NULL
);
2841 ok(!ret
, "failed with error %d\n", ret
);
2843 ret
= RegSetValueExA(subkey
, "test", 0, REG_SZ
, (const BYTE
*)"value", 6);
2844 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2846 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
2847 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2849 ret
= pRegDeleteKeyValueA(hkey_main
, "Subkey1", "test");
2850 ok(ret
== ERROR_SUCCESS
, "got %d\n", ret
);
2852 ret
= RegQueryValueExA(subkey
, "test", NULL
, NULL
, NULL
, NULL
);
2853 ok(ret
== ERROR_FILE_NOT_FOUND
, "got %d\n", ret
);
2855 RegDeleteKeyA(subkey
, "");
2856 RegCloseKey(subkey
);
2859 START_TEST(registry
)
2861 /* Load pointers for functions that are not available in all Windows versions */
2867 create_test_entries();
2869 test_query_value_ex();
2871 test_reg_open_key();
2872 test_reg_create_key();
2873 test_reg_close_key();
2874 test_reg_delete_key();
2875 test_reg_query_value();
2876 test_string_termination();
2880 test_classesroot_enum();
2881 test_classesroot_mask();
2883 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2884 if (set_privileges(SE_BACKUP_NAME
, TRUE
) &&
2885 set_privileges(SE_RESTORE_NAME
, TRUE
))
2887 test_reg_save_key();
2888 test_reg_load_key();
2889 test_reg_unload_key();
2891 set_privileges(SE_BACKUP_NAME
, FALSE
);
2892 set_privileges(SE_RESTORE_NAME
, FALSE
);
2895 test_reg_delete_tree();
2898 test_delete_value();
2899 test_delete_key_value();
2902 delete_key( hkey_main
);
2904 test_regconnectregistry();