2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
34 static HKEY hkey_main;
37 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
38 static const char * sTestpath2 = "%FOO%\\subdir1";
40 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
41 static DWORD (WINAPI *pRegDeleteTreeA)(HKEY,LPCSTR);
42 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
43 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
44 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
45 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
46 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
49 /* Debugging functions from wine/libs/wine/debug.c */
51 /* allocate some tmp string space */
52 /* FIXME: this is not 100% thread-safe */
53 static char *get_temp_buffer( int size )
55 static char *list[32];
60 idx = ++pos % (sizeof(list)/sizeof(list[0]));
62 ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
64 ret = HeapAlloc( GetProcessHeap(), 0, size );
65 if (ret) list[idx] = ret;
69 static const char *wine_debugstr_an( const char *str, int n )
71 static const char hex[16] = "0123456789abcdef";
75 if (!((ULONG_PTR)str >> 16))
77 if (!str) return "(null)";
78 res = get_temp_buffer( 6 );
79 sprintf( res, "#%04x", LOWORD(str) );
82 if (n == -1) n = strlen(str);
84 size = 10 + min( 300, n * 4 );
85 dst = res = get_temp_buffer( size );
87 while (n-- > 0 && dst <= res + size - 9)
89 unsigned char c = *str++;
92 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
93 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
94 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
95 case '"': *dst++ = '\\'; *dst++ = '"'; break;
96 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
98 if (c >= ' ' && c <= 126)
104 *dst++ = hex[(c >> 4) & 0x0f];
105 *dst++ = hex[c & 0x0f];
120 #define ADVAPI32_GET_PROC(func) \
121 p ## func = (void*)GetProcAddress(hadvapi32, #func)
123 static void InitFunctionPtrs(void)
125 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
126 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
127 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
129 /* This function was introduced with Windows 2003 SP1 */
130 ADVAPI32_GET_PROC(RegGetValueA);
131 ADVAPI32_GET_PROC(RegDeleteTreeA);
132 ADVAPI32_GET_PROC(RegDeleteKeyExA);
134 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
135 pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
136 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
137 pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
140 /* delete key and all its subkeys */
141 static DWORD delete_key( HKEY hkey )
146 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
149 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
151 ret = delete_key( tmp );
156 if (ret != ERROR_NO_MORE_ITEMS) return ret;
157 RegDeleteKeyA( hkey, "" );
161 static void setup_main_key(void)
163 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
165 assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
168 #define lok ok_(__FILE__, line)
169 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
170 static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
173 DWORD ret, type, cbData;
179 /* When successful RegQueryValueExA() leaves GLE as is,
180 * so we must reset it to detect unimplemented functions.
182 SetLastError(0xdeadbeef);
183 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
184 GLE = GetLastError();
185 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret, GLE);
186 /* It is wrong for the Ansi version to not be implemented */
187 ok(GLE == 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE);
188 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
190 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
191 lok(type == REG_SZ, "RegQueryValueExA/1 returned type %d\n", type);
192 lok(cbData == full_byte_len || cbData == str_byte_len /* Win9x */,
193 "cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
195 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
196 memset(value, 0xbd, cbData+1);
198 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
199 GLE = GetLastError();
200 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
203 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
204 lok(*value == 0xbd || (cbData == 1 && *value == '\0') /* Win9x */,
205 "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
209 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
210 wine_debugstr_an((char*)value, cbData), cbData,
211 wine_debugstr_an(string, full_byte_len), full_byte_len);
212 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
214 HeapFree(GetProcessHeap(), 0, value);
217 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
218 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
221 DWORD ret, type, cbData;
226 /* When successful RegQueryValueExW() leaves GLE as is,
227 * so we must reset it to detect unimplemented functions.
229 SetLastError(0xdeadbeef);
230 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
231 GLE = GetLastError();
232 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
233 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
235 win_skip("RegQueryValueExW() is not implemented\n");
239 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
240 lok(cbData == full_byte_len,
241 "cbData=%d instead of %d\n", cbData, full_byte_len);
243 /* Give enough space to overflow by one WCHAR */
244 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
245 memset(value, 0xbd, cbData+2);
247 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
248 GLE = GetLastError();
249 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
252 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
253 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
254 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
256 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
257 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
258 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
259 HeapFree(GetProcessHeap(), 0, value);
262 static void test_set_value(void)
266 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
267 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};
268 static const WCHAR emptyW[] = {0};
269 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
270 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};
271 static const WCHAR substring2W[] = {'T','h','i','s',0};
273 static const char name1A[] = "CleanSingleString";
274 static const char name2A[] = "SomeIntraZeroedString";
275 static const char emptyA[] = "";
276 static const char string1A[] = "ThisNeverBreaks";
277 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
278 static const char substring2A[] = "This";
282 /* Crashes on NT4, Windows 2000 and XP SP1 */
283 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
284 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
287 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
288 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
289 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
290 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
292 /* RegSetValueA ignores the size passed in */
293 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
294 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
295 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
296 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
298 /* stops at first null */
299 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
300 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
301 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
302 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
304 /* only REG_SZ is supported on NT*/
305 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
306 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
307 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS),
308 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret);
310 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
311 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
312 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS),
313 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret);
315 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
316 /* NT: ERROR_INVALID_PARAMETER, 9x: ERROR_SUCCESS */
317 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS),
318 "got %d (expected ERROR_INVALID_PARAMETER or ERROR_SUCCESS)\n", ret);
320 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
321 * Surprisingly enough we're supposed to get zero bytes out of it.
323 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
324 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
325 test_hkey_main_Value_A(name1A, NULL, 0);
326 test_hkey_main_Value_W(name1W, NULL, 0);
328 /* test RegSetValueExA with an empty string */
329 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
330 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
331 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
332 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
334 /* test RegSetValueExA with off-by-one size */
335 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
336 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
337 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
338 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
340 /* test RegSetValueExA with normal string */
341 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
342 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
343 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
344 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
346 /* test RegSetValueExA with intrazeroed string */
347 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
348 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
349 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
350 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
352 /* 9x doesn't support W-calls, so don't test them then */
353 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
357 /* Crashes on NT4, Windows 2000 and XP SP1 */
358 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
359 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
362 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
363 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
364 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
365 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
367 /* RegSetValueA ignores the size passed in */
368 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
369 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
370 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
371 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
373 /* stops at first null */
374 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
375 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
376 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
377 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
379 /* only REG_SZ is supported */
380 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
381 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
382 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
383 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
384 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
385 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
387 /* test RegSetValueExW with off-by-one size */
388 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
389 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
390 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
391 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
393 /* test RegSetValueExW with normal string */
394 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
395 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
396 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
397 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
399 /* test RegSetValueExW with intrazeroed string */
400 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
401 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
402 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
403 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
406 static void create_test_entries(void)
408 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
410 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
411 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
413 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
414 "RegSetValueExA failed\n");
415 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
416 "RegSetValueExA failed\n");
417 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
418 "RegSetValueExA failed\n");
419 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
420 "RegSetValueExA failed\n");
421 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
422 "RegSetValueExA failed\n");
423 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
424 "RegSetValueExA failed\n");
425 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
426 "RegSetValueExA failed\n");
429 static void test_enum_value(void)
433 char value[20], data[20];
434 WCHAR valueW[20], dataW[20];
435 DWORD val_count, data_count, type;
436 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
437 static const WCHAR testW[] = {'T','e','s','t',0};
438 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
440 /* create the working key for new 'Test' value */
441 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
442 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
444 /* check NULL data with zero length */
445 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
446 if (GetVersion() & 0x80000000)
447 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
449 ok( !res, "RegSetValueExA returned %d\n", res );
450 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
451 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
452 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
453 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
455 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
456 ok( res == 0, "RegSetValueExA failed error %d\n", res );
458 /* overflow both name and data */
462 strcpy( value, "xxxxxxxxxx" );
463 strcpy( data, "xxxxxxxxxx" );
464 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
465 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
466 ok( val_count == 2, "val_count set to %d\n", val_count );
467 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
468 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
469 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
470 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
476 strcpy( value, "xxxxxxxxxx" );
477 strcpy( data, "xxxxxxxxxx" );
478 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
479 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
480 /* Win9x returns 2 as specified by MSDN but NT returns 3... */
481 ok( val_count == 2 || val_count == 3, "val_count set to %d\n", val_count );
482 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
483 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
484 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
485 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
486 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
487 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
488 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
490 /* overflow empty name */
494 strcpy( value, "xxxxxxxxxx" );
495 strcpy( data, "xxxxxxxxxx" );
496 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
497 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
498 ok( val_count == 0, "val_count set to %d\n", val_count );
499 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
500 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
501 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
502 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
503 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
504 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
510 strcpy( value, "xxxxxxxxxx" );
511 strcpy( data, "xxxxxxxxxx" );
512 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
513 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
514 ok( val_count == 20, "val_count set to %d\n", val_count );
515 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
516 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
517 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
518 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
524 strcpy( value, "xxxxxxxxxx" );
525 strcpy( data, "xxxxxxxxxx" );
526 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
527 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
528 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
529 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
530 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
531 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
532 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
536 SetLastError(0xdeadbeef);
537 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
538 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
540 win_skip("RegSetValueExW is not implemented\n");
543 ok( res == 0, "RegSetValueExW failed error %d\n", res );
545 /* overflow both name and data */
549 memcpy( valueW, xxxW, sizeof(xxxW) );
550 memcpy( dataW, xxxW, sizeof(xxxW) );
551 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
552 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
553 ok( val_count == 2, "val_count set to %d\n", val_count );
554 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
555 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
556 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
557 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
563 memcpy( valueW, xxxW, sizeof(xxxW) );
564 memcpy( dataW, xxxW, sizeof(xxxW) );
565 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
566 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
567 ok( val_count == 3, "val_count set to %d\n", val_count );
568 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
569 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
570 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
571 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
577 memcpy( valueW, xxxW, sizeof(xxxW) );
578 memcpy( dataW, xxxW, sizeof(xxxW) );
579 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
580 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
581 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
582 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
583 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
584 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
585 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
591 memcpy( valueW, xxxW, sizeof(xxxW) );
592 memcpy( dataW, xxxW, sizeof(xxxW) );
593 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &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*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
597 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
598 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
599 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
602 RegDeleteKeyA(test_key, "");
603 RegCloseKey(test_key);
606 static void test_query_value_ex(void)
613 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
614 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
615 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
616 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
620 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
621 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
622 /* the type parameter is cleared on Win9x, but is set to a random value on
623 * NT, so don't do that test there. The size parameter is left untouched on Win9x
624 * but cleared on NT+, this can be tested on all platforms.
626 if (GetVersion() & 0x80000000)
628 ok(type == 0, "type should have been set to 0 instead of 0x%x\n", type);
629 ok(size == 0xdeadbeef, "size should have been left untouched (0xdeadbeef)\n");
633 trace("test_query_value_ex: type set to: 0x%08x\n", type);
634 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
637 size = sizeof(buffer);
638 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
639 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
640 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
643 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
644 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
647 static void test_get_value(void)
654 CHAR expanded[] = "bar\\subdir1";
655 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
659 win_skip("RegGetValue not available on this platform\n");
663 /* Invalid parameter */
664 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
665 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
667 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
668 size = type = dw = 0xdeadbeef;
669 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
670 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
671 ok(size == 4, "size=%d\n", size);
672 ok(type == REG_DWORD, "type=%d\n", type);
673 ok(dw == 0x12345678, "dw=%d\n", dw);
675 /* Query by subkey-name */
676 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
677 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
679 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
680 size = type = dw = 0xdeadbeef;
681 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
682 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
683 /* Although the function failed all values are retrieved */
684 ok(size == 4, "size=%d\n", size);
685 ok(type == REG_DWORD, "type=%d\n", type);
686 ok(dw == 0x12345678, "dw=%d\n", dw);
688 /* Test RRF_ZEROONFAILURE */
689 type = dw = 0xdeadbeef; size = 4;
690 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
691 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
692 /* Again all values are retrieved ... */
693 ok(size == 4, "size=%d\n", size);
694 ok(type == REG_DWORD, "type=%d\n", type);
695 /* ... except the buffer, which is zeroed out */
696 ok(dw == 0, "dw=%d\n", dw);
698 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
699 type = size = 0xbadbeef;
700 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
701 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
702 ok(size == 4, "size=%d\n", size);
703 ok(type == REG_DWORD, "type=%d\n", type);
705 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
706 size = type = dw = 0xdeadbeef;
707 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
708 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
709 ok(size == 4, "size=%d\n", size);
710 ok(type == REG_DWORD, "type=%d\n", type);
711 ok(dw == 0x12345678, "dw=%d\n", dw);
713 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
714 size = type = dw = 0xdeadbeef;
715 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
716 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
717 ok(size == 4, "size=%d\n", size);
718 ok(type == REG_BINARY, "type=%d\n", type);
719 ok(dw == 0x12345678, "dw=%d\n", dw);
721 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
722 qw[0] = qw[1] = size = type = 0xdeadbeef;
723 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
724 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
725 ok(size == 8, "size=%d\n", size);
726 ok(type == REG_BINARY, "type=%d\n", type);
727 ok(qw[0] == 0x12345678 &&
728 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
730 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
731 type = dw = 0xdeadbeef; size = 4;
732 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
733 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
734 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
735 ok(size == 8, "size=%d\n", size);
737 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
738 qw[0] = qw[1] = size = type = 0xdeadbeef;
739 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
740 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
741 ok(size == 8, "size=%d\n", size);
742 ok(type == REG_BINARY, "type=%d\n", type);
743 ok(qw[0] == 0x12345678 &&
744 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
746 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
747 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
748 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
749 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
750 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
751 ok(type == REG_SZ, "type=%d\n", type);
752 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
754 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
755 type = 0xdeadbeef; size = 0;
756 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
757 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
758 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
759 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
760 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
761 ok(type == REG_SZ, "type=%d\n", type);
763 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
764 strcpy(buf, sTestpath1);
767 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
768 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
769 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
771 size == 1, /* win2k3 */
773 ok(type == REG_SZ, "type=%d\n", type);
774 ok(!strcmp(sTestpath1, buf) ||
776 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
778 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
779 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
780 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
781 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
782 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
783 ok(type == REG_SZ, "type=%d\n", type);
784 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
786 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
788 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
789 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
790 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
791 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
792 (size == strlen(sTestpath2)+1),
793 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
795 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
796 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
797 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
798 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
799 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
800 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
801 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
802 ok(type == REG_SZ, "type=%d\n", type);
803 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
805 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
806 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
807 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
808 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
809 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
810 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
811 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
812 ok(type == REG_SZ, "type=%d\n", type);
813 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
815 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
816 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
817 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
818 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
819 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
820 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
821 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
823 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
825 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
826 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
827 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
828 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
829 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
831 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
832 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
833 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
835 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
836 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
837 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
839 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
840 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
841 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
842 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
843 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
844 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
845 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
846 ok(type == REG_SZ, "type=%d\n", type);
847 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
850 static void test_reg_open_key(void)
853 HKEY hkResult = NULL;
854 HKEY hkPreserve = NULL;
855 HKEY hkRoot64 = NULL;
856 HKEY hkRoot32 = NULL;
858 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
860 EXPLICIT_ACCESSA access;
862 SECURITY_DESCRIPTOR *sd;
864 /* successful open */
865 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
866 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
867 ok(hkResult != NULL, "expected hkResult != NULL\n");
868 hkPreserve = hkResult;
870 /* these tests fail on Win9x, but we want to be compatible with NT, so
871 * run them if we can */
872 if (!(GetVersion() & 0x80000000))
874 /* open same key twice */
875 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
876 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
877 ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
878 ok(hkResult != NULL, "hkResult != NULL\n");
879 RegCloseKey(hkResult);
881 /* open nonexistent key
882 * check that hkResult is set to NULL
884 hkResult = hkPreserve;
885 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
886 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
887 ok(hkResult == NULL, "expected hkResult == NULL\n");
889 /* open the same nonexistent key again to make sure the key wasn't created */
890 hkResult = hkPreserve;
891 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
892 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
893 ok(hkResult == NULL, "expected hkResult == NULL\n");
895 /* send in NULL lpSubKey
896 * check that hkResult receives the value of hKey
898 hkResult = hkPreserve;
899 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
900 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
901 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
903 /* send empty-string in lpSubKey */
904 hkResult = hkPreserve;
905 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
906 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
907 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
909 /* send in NULL lpSubKey and NULL hKey
910 * hkResult is set to NULL
912 hkResult = hkPreserve;
913 ret = RegOpenKeyA(NULL, NULL, &hkResult);
914 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
915 ok(hkResult == NULL, "expected hkResult == NULL\n");
918 /* only send NULL hKey
919 * the value of hkResult remains unchanged
921 hkResult = hkPreserve;
922 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
923 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
924 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
925 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
926 RegCloseKey(hkResult);
928 /* send in NULL hkResult */
929 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
930 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
932 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
933 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
935 ret = RegOpenKeyA(NULL, NULL, NULL);
936 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
938 /* beginning backslash character */
939 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
940 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
941 ret == ERROR_FILE_NOT_FOUND || /* Win9x,ME */
942 broken(ret == ERROR_SUCCESS), /* wow64 */
943 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
944 if (!ret) RegCloseKey(hkResult);
947 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
948 ok(ret == ERROR_SUCCESS || /* 2k/XP */
949 ret == ERROR_BAD_PATHNAME || /* NT */
950 ret == ERROR_FILE_NOT_FOUND /* Win9x,ME */
951 , "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
952 RegCloseKey(hkResult);
956 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
957 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
958 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
959 RegCloseKey(hkResult);
962 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
963 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
964 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
965 RegCloseKey(hkResult);
967 /* Try using WOW64 flags when opening a key with a DACL set to verify that
968 * the registry access check is performed correctly. Redirection isn't
969 * being tested, so the tests don't care about whether the process is
970 * running under WOW64. */
971 if (!pIsWow64Process)
973 win_skip("WOW64 flags are not recognized\n");
977 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
978 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
979 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
980 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
982 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
983 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
984 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
985 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
987 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
988 0, 0, 0, 0, 0, 0, 0, &world_sid);
990 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
992 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
993 access.grfAccessMode = SET_ACCESS;
994 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
995 access.Trustee.pMultipleTrustee = NULL;
996 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
997 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
998 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
999 access.Trustee.ptstrName = (char *)world_sid;
1001 ret = SetEntriesInAclA(1, &access, NULL, &key_acl);
1002 ok(ret == ERROR_SUCCESS,
1003 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret, GetLastError());
1005 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1006 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1008 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1010 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1012 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1014 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1015 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1017 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1019 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1021 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1024 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
1025 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1026 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1027 RegCloseKey(hkResult);
1030 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
1031 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1032 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1033 RegCloseKey(hkResult);
1035 HeapFree(GetProcessHeap(), 0, sd);
1038 RegDeleteKeyA(hkRoot64, "");
1039 RegCloseKey(hkRoot64);
1040 RegDeleteKeyA(hkRoot32, "");
1041 RegCloseKey(hkRoot32);
1044 static void test_reg_create_key(void)
1048 HKEY hkRoot64 = NULL;
1049 HKEY hkRoot32 = NULL;
1052 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1054 EXPLICIT_ACCESSA access;
1056 SECURITY_DESCRIPTOR *sd;
1058 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1059 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1060 /* should succeed: all versions of Windows ignore the access rights
1061 * to the parent handle */
1062 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
1063 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1066 RegDeleteKey(hkey2, "");
1067 RegDeleteKey(hkey1, "");
1071 /* test creation of volatile keys */
1072 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
1073 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1074 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1075 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE || broken(!ret), /* win9x */
1076 "RegCreateKeyExA failed with error %d\n", ret);
1077 if (!ret) RegCloseKey( hkey2 );
1078 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1079 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1081 /* should succeed if the key already exists */
1082 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1083 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1086 RegDeleteKey(hkey2, "");
1087 RegDeleteKey(hkey1, "");
1091 /* beginning backslash character */
1092 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1093 if (!(GetVersion() & 0x80000000))
1094 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1096 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1097 RegDeleteKey(hkey1, NULL);
1101 /* WOW64 flags - open an existing key */
1103 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1104 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1105 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1109 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1110 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1111 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1114 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1115 * the registry access check is performed correctly. Redirection isn't
1116 * being tested, so the tests don't care about whether the process is
1117 * running under WOW64. */
1118 if (!pIsWow64Process)
1120 win_skip("WOW64 flags are not recognized\n");
1124 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1125 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1126 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1127 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1129 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1130 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1131 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1132 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1134 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1135 0, 0, 0, 0, 0, 0, 0, &world_sid);
1137 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1139 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1140 access.grfAccessMode = SET_ACCESS;
1141 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1142 access.Trustee.pMultipleTrustee = NULL;
1143 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1144 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1145 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1146 access.Trustee.ptstrName = (char *)world_sid;
1148 dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
1149 ok(ret == ERROR_SUCCESS,
1150 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
1152 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1153 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1155 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1157 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1159 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1161 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1162 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1164 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1166 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1168 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1171 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1172 KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
1173 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1174 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1178 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1179 KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
1180 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1181 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1184 HeapFree(GetProcessHeap(), 0, sd);
1187 RegDeleteKeyA(hkRoot64, "");
1188 RegCloseKey(hkRoot64);
1189 RegDeleteKeyA(hkRoot32, "");
1190 RegCloseKey(hkRoot32);
1193 static void test_reg_close_key(void)
1198 /* successfully close key
1199 * hkHandle remains changed after call to RegCloseKey
1201 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1202 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1203 ret = RegCloseKey(hkHandle);
1204 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1206 /* try to close the key twice */
1207 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1208 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1209 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1211 /* try to close a NULL handle */
1212 ret = RegCloseKey(NULL);
1213 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1214 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1216 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1217 * win98 doesn't give a new handle when the same key is opened.
1218 * Not re-opening will make some next tests fail.
1220 if (hkey_main == hkHandle)
1222 trace("The main handle is most likely closed, so re-opening\n");
1223 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1227 static void test_reg_delete_key(void)
1231 ret = RegDeleteKey(hkey_main, NULL);
1233 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1234 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1235 * Not re-creating will make some next tests fail.
1237 if (ret == ERROR_SUCCESS)
1239 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1240 " re-creating the main key\n");
1244 ok(ret == ERROR_INVALID_PARAMETER ||
1245 ret == ERROR_ACCESS_DENIED ||
1246 ret == ERROR_BADKEY, /* Win95 */
1250 static void test_reg_save_key(void)
1254 ret = RegSaveKey(hkey_main, "saved_key", NULL);
1255 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1258 static void test_reg_load_key(void)
1263 ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1264 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1266 ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1267 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1269 RegCloseKey(hkHandle);
1272 static void test_reg_unload_key(void)
1276 ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
1277 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1279 DeleteFile("saved_key");
1280 DeleteFile("saved_key.LOG");
1283 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1285 TOKEN_PRIVILEGES tp;
1289 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1292 if(!LookupPrivilegeValue(NULL, privilege, &luid))
1294 CloseHandle(hToken);
1298 tp.PrivilegeCount = 1;
1299 tp.Privileges[0].Luid = luid;
1302 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1304 tp.Privileges[0].Attributes = 0;
1306 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1307 if (GetLastError() != ERROR_SUCCESS)
1309 CloseHandle(hToken);
1313 CloseHandle(hToken);
1317 /* tests that show that RegConnectRegistry and
1318 OpenSCManager accept computer names without the
1319 \\ prefix (what MSDN says). */
1320 static void test_regconnectregistry( void)
1322 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1323 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1324 DWORD len = sizeof(compName) ;
1330 SetLastError(0xdeadbeef);
1331 ret = GetComputerNameA(compName, &len);
1332 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1335 lstrcpyA(netwName, "\\\\");
1336 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1338 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1340 retl == ERROR_DLL_INIT_FAILED ||
1341 retl == ERROR_BAD_NETPATH, /* some win2k */
1342 "RegConnectRegistryA failed err = %d\n", retl);
1343 if( !retl) RegCloseKey( hkey);
1345 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1347 retl == ERROR_DLL_INIT_FAILED ||
1348 retl == ERROR_BAD_NETPATH, /* some win2k */
1349 "RegConnectRegistryA failed err = %d\n", retl);
1350 if( !retl) RegCloseKey( hkey);
1352 SetLastError(0xdeadbeef);
1353 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1354 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1356 win_skip("OpenSCManagerA is not implemented\n");
1360 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1361 CloseServiceHandle( schnd);
1363 SetLastError(0xdeadbeef);
1364 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1365 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1366 CloseServiceHandle( schnd);
1370 static void test_reg_query_value(void)
1377 static const WCHAR expected[] = {'d','a','t','a',0};
1379 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1380 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1382 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1383 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1385 /* try an invalid hkey */
1386 SetLastError(0xdeadbeef);
1388 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1389 ok(ret == ERROR_INVALID_HANDLE ||
1390 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1391 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1392 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1393 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1395 /* try a NULL hkey */
1396 SetLastError(0xdeadbeef);
1398 ret = RegQueryValueA(NULL, "subkey", val, &size);
1399 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1400 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1401 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1403 /* try a NULL value */
1405 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1406 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1407 ok(size == 5, "Expected 5, got %d\n", size);
1409 /* try a NULL size */
1410 SetLastError(0xdeadbeef);
1412 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1413 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1414 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1415 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1417 /* try a NULL value and size */
1418 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1419 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1421 /* try a size too small */
1422 SetLastError(0xdeadbeef);
1425 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1426 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1427 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1428 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1429 ok(size == 5, "Expected 5, got %d\n", size);
1431 /* successfully read the value using 'subkey' */
1433 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1434 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1435 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1436 ok(size == 5, "Expected 5, got %d\n", size);
1438 /* successfully read the value using the subkey key */
1440 ret = RegQueryValueA(subkey, NULL, val, &size);
1441 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1442 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1443 ok(size == 5, "Expected 5, got %d\n", size);
1445 /* unicode - try size too small */
1446 SetLastError(0xdeadbeef);
1449 ret = RegQueryValueW(subkey, NULL, valW, &size);
1450 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1452 win_skip("RegQueryValueW is not implemented\n");
1455 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1456 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1457 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1458 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1460 /* unicode - try size in WCHARS */
1461 SetLastError(0xdeadbeef);
1462 size = sizeof(valW) / sizeof(WCHAR);
1463 ret = RegQueryValueW(subkey, NULL, valW, &size);
1464 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1465 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1466 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1467 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1469 /* unicode - successfully read the value */
1470 size = sizeof(valW);
1471 ret = RegQueryValueW(subkey, NULL, valW, &size);
1472 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1473 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1474 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1476 /* unicode - set the value without a NULL terminator */
1477 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1478 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1480 /* unicode - read the unterminated value, value is terminated for us */
1481 memset(valW, 'a', sizeof(valW));
1482 size = sizeof(valW);
1483 ret = RegQueryValueW(subkey, NULL, valW, &size);
1484 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1485 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1486 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1489 RegDeleteKeyA(subkey, "");
1490 RegCloseKey(subkey);
1493 static void test_string_termination(void)
1497 static const char string[] = "FullString";
1500 DWORD insize, outsize, nsize;
1502 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
1503 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1505 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1506 insize=sizeof(string)-1;
1507 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1508 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1510 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1511 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
1513 /* Off-by-two RegSetValueExA -> no trailing '\0', except on Win9x */
1514 insize=sizeof(string)-2;
1515 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1516 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1518 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
1519 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1520 ok(outsize == insize || broken(outsize == sizeof(string)) /* Win9x */,
1521 "wrong size %u != %u\n", outsize, insize);
1523 if (outsize == insize)
1525 /* RegQueryValueExA may return a string with no trailing '\0' */
1527 memset(buffer, 0xbd, sizeof(buffer));
1528 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1529 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1530 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1531 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1532 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1533 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1535 /* RegQueryValueExA adds a trailing '\0' if there is room */
1537 memset(buffer, 0xbd, sizeof(buffer));
1538 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1539 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1540 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1541 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1542 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1543 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1545 /* RegEnumValueA may return a string with no trailing '\0' */
1547 memset(buffer, 0xbd, sizeof(buffer));
1549 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1550 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1551 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1552 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1553 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1554 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1555 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1557 /* RegEnumValueA adds a trailing '\0' if there is room */
1559 memset(buffer, 0xbd, sizeof(buffer));
1561 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1562 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1563 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1564 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1565 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1566 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1567 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1570 RegDeleteKeyA(subkey, "");
1571 RegCloseKey(subkey);
1574 static void test_reg_delete_tree(void)
1576 CHAR buffer[MAX_PATH];
1577 HKEY subkey, subkey2;
1580 if(!pRegDeleteTreeA) {
1581 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1585 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1586 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1587 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1588 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1589 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1590 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1591 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
1592 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1593 ret = RegCloseKey(subkey2);
1594 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1596 ret = pRegDeleteTreeA(subkey, "subkey2");
1597 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1598 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1599 "subkey2 was not deleted\n");
1601 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1602 "Default value of subkey not longer present\n");
1604 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1605 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1606 ret = RegCloseKey(subkey2);
1607 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1608 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
1609 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1610 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1611 "subkey2 was not deleted\n");
1612 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1613 "Default value of subkey not longer present\n");
1615 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1616 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1617 ret = RegCloseKey(subkey2);
1618 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1619 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
1620 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1621 ret = RegCloseKey(subkey2);
1622 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1623 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
1624 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1625 ret = pRegDeleteTreeA(subkey, NULL);
1626 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1627 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
1628 "subkey was deleted\n");
1629 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1630 "subkey2 was not deleted\n");
1631 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
1632 "subkey3 was not deleted\n");
1634 ret = RegQueryValueA(subkey, NULL, buffer, &size);
1635 ok(ret == ERROR_SUCCESS,
1636 "Default value of subkey is not present\n");
1637 ok(!lstrlenA(buffer),
1638 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
1640 ok(RegQueryValueA(subkey, "value", buffer, &size),
1641 "Value is still present\n");
1643 ret = pRegDeleteTreeA(hkey_main, "not-here");
1644 ok(ret == ERROR_FILE_NOT_FOUND,
1645 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1648 static void test_rw_order(void)
1652 static char keyname[] = "test_rw_order";
1654 DWORD values, value_len, value_name_max_len;
1657 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
1658 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
1659 if(ret != ERROR_SUCCESS) {
1660 skip("Couldn't create key. Skipping.\n");
1664 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1665 "RegSetValueExA for value \"A\" failed\n");
1666 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1667 "RegSetValueExA for value \"C\" failed\n");
1668 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1669 "RegSetValueExA for value \"D\" failed\n");
1670 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1671 "RegSetValueExA for value \"B\" failed\n");
1673 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
1674 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
1675 ok(values == 4, "Expected 4 values, got %u\n", values);
1677 /* Value enumeration preserves RegSetValueEx call order */
1679 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1680 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
1682 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1683 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
1685 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1686 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
1688 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1689 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
1691 ok(!RegDeleteKey(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
1694 static void test_symlinks(void)
1696 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1697 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1699 UNICODE_STRING target_str;
1703 DWORD target_len, type, len, dw, err;
1705 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
1707 win_skip( "Can't perform symlink tests\n" );
1711 pRtlFormatCurrentUserKeyPath( &target_str );
1713 target_len = target_str.Length + sizeof(targetW);
1714 target = HeapAlloc( GetProcessHeap(), 0, target_len );
1715 memcpy( target, target_str.Buffer, target_str.Length );
1716 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
1718 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1719 KEY_ALL_ACCESS, NULL, &link, NULL );
1720 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
1722 /* REG_SZ is not allowed */
1723 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
1724 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1725 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
1726 (BYTE *)target, target_len - sizeof(WCHAR) );
1727 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1728 /* other values are not allowed */
1729 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
1730 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1732 /* try opening the target through the link */
1734 err = RegOpenKeyA( hkey_main, "link", &key );
1735 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
1737 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1738 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1741 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1742 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1745 err = RegOpenKeyA( hkey_main, "link", &key );
1746 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1748 len = sizeof(buffer);
1749 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1750 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1751 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1753 len = sizeof(buffer);
1754 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1755 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1757 /* REG_LINK can be created in non-link keys */
1758 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
1759 (BYTE *)target, target_len - sizeof(WCHAR) );
1760 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1761 len = sizeof(buffer);
1762 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1763 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1764 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1765 err = RegDeleteValueA( key, "SymbolicLinkValue" );
1766 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
1770 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1771 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1773 len = sizeof(buffer);
1774 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1775 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1776 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1778 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1779 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1782 /* now open the symlink itself */
1784 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
1785 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
1786 len = sizeof(buffer);
1787 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1788 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1789 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1792 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
1793 KEY_ALL_ACCESS, NULL, &key, NULL );
1794 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1795 len = sizeof(buffer);
1796 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1797 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1798 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1801 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1802 KEY_ALL_ACCESS, NULL, &key, NULL );
1803 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1805 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
1806 KEY_ALL_ACCESS, NULL, &key, NULL );
1807 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1809 err = RegDeleteKey( hkey_main, "target" );
1810 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
1812 err = RegDeleteKey( hkey_main, "link" );
1813 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
1815 status = pNtDeleteKey( link );
1816 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
1817 RegCloseKey( link );
1819 HeapFree( GetProcessHeap(), 0, target );
1820 pRtlFreeUnicodeString( &target_str );
1823 static const DWORD ptr_size = 8 * sizeof(void*);
1825 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
1828 DWORD err, type, dw, len = sizeof(dw);
1830 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
1831 if (err == ERROR_FILE_NOT_FOUND) return 0;
1832 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
1834 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
1835 if (err == ERROR_FILE_NOT_FOUND)
1838 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
1843 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
1845 DWORD dw = get_key_value( root, name, flags );
1846 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
1848 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1850 static void test_redirection(void)
1852 DWORD err, type, dw, len;
1853 HKEY key, root32, root64, key32, key64;
1854 BOOL is_vista = FALSE;
1859 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
1861 skip( "Not on Wow64, no redirection\n" );
1866 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1867 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
1868 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1870 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1871 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
1872 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1874 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1875 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
1876 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1878 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1879 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
1880 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1883 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1884 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1887 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1888 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1892 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
1893 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1894 ok( dw == 32, "wrong value %u\n", dw );
1898 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
1899 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1900 ok( dw == 64, "wrong value %u\n", dw );
1902 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1903 KEY_ALL_ACCESS, NULL, &key, NULL );
1904 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1908 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1909 /* the new (and simpler) Win7 mechanism doesn't */
1910 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1912 trace( "using Vista-style Wow6432Node handling\n" );
1915 check_key_value( key, "Wine\\Winetest", 0, 32 );
1916 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1917 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1918 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1919 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1920 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1924 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
1926 trace( "using Vista-style Wow6432Node handling\n" );
1929 check_key_value( key, "Wine\\Winetest", 0, 64 );
1930 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1936 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1937 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1938 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1939 dw = get_key_value( key, "Wine\\Winetest", 0 );
1940 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1941 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1942 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1943 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1944 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
1945 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
1946 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1949 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1950 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1951 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1952 check_key_value( key, "Wine\\Winetest", 0, 32 );
1953 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1954 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1955 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1956 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1957 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1961 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
1962 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1965 /* KEY_WOW64 flags have no effect on 64-bit */
1966 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1967 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1968 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1969 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1973 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1974 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1975 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1976 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1979 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1980 KEY_ALL_ACCESS, NULL, &key, NULL );
1981 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1982 check_key_value( key, "Wine\\Winetest", 0, 32 );
1983 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1984 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1989 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1990 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1991 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1992 dw = get_key_value( key, "Wine\\Winetest", 0 );
1993 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1994 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1995 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1998 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1999 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2000 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2001 check_key_value( key, "Wine\\Winetest", 0, 32 );
2002 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2003 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2007 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2008 KEY_ALL_ACCESS, NULL, &key, NULL );
2009 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2010 check_key_value( key, "Winetest", 0, 32 );
2011 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2012 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2017 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2018 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2019 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2020 dw = get_key_value( key, "Winetest", 0 );
2021 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
2022 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2023 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2026 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2027 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2028 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2029 check_key_value( key, "Winetest", 0, 32 );
2030 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2031 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2035 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2036 KEY_ALL_ACCESS, NULL, &key, NULL );
2037 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2038 check_key_value( key, "Winetest", 0, ptr_size );
2039 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
2040 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2041 if (ptr_size == 32) ok( dw == 32, "wrong value %u\n", dw );
2042 else todo_wine ok( dw == 32, "wrong value %u\n", dw );
2047 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2048 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2049 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2050 dw = get_key_value( key, "Winetest", 0 );
2051 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2052 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
2053 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2054 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2057 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2058 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2059 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2060 check_key_value( key, "Winetest", 0, 32 );
2061 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2062 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2066 if (pRegDeleteKeyExA)
2068 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
2069 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2070 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2071 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2072 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2073 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
2077 err = RegDeleteKeyA( key32, "" );
2078 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2079 err = RegDeleteKeyA( key64, "" );
2080 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2081 RegDeleteKeyA( key64, "" );
2082 RegDeleteKeyA( root64, "" );
2084 RegCloseKey( key32 );
2085 RegCloseKey( key64 );
2086 RegCloseKey( root32 );
2087 RegCloseKey( root64 );
2090 static void test_classesroot(void)
2092 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
2094 DWORD type = REG_SZ;
2095 static CHAR buffer[8];
2098 /* create a key in the user's classes */
2099 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
2102 RegCloseKey( hkey );
2104 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2105 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2107 /* try to open that key in hkcr */
2108 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2109 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2110 todo_wine ok(res == ERROR_SUCCESS ||
2111 broken(res == ERROR_FILE_NOT_FOUND /* Win9x */),
2112 "test key not found in hkcr: %d\n", res);
2115 trace( "HKCR key merging not supported\n" );
2117 RegCloseKey( hkey );
2121 /* set a value in user's classes */
2122 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2123 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2125 /* try to find the value in hkcr */
2126 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
2127 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2128 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2130 /* modify the value in hkcr */
2131 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2132 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2134 /* check if the value is also modified in user's classes */
2135 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
2136 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2137 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2139 /* set a value in hkcr */
2140 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2141 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2143 /* try to find the value in user's classes */
2144 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
2145 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2146 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2148 /* modify the value in user's classes */
2149 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2150 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2152 /* check if the value is also modified in hkcr */
2153 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
2154 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2155 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2160 RegCloseKey( hkey );
2161 RegCloseKey( hkcr );
2163 /* create a key in the hklm classes */
2164 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2167 RegCloseKey( hklm );
2169 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
2170 KEY_ALL_ACCESS, NULL, &hklm, NULL );
2171 if (res == ERROR_ACCESS_DENIED)
2173 skip("not enough privileges to add a system class\n");
2177 /* try to open that key in hkcr */
2178 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2179 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2180 ok(res == ERROR_SUCCESS,
2181 "test key not found in hkcr: %d\n", res);
2185 RegCloseKey( hklm );
2189 /* set a value in hklm classes */
2190 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2191 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2193 /* try to find the value in hkcr */
2194 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2195 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2196 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2198 /* modify the value in hkcr */
2199 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2200 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2202 /* check that the value is not modified in hklm classes */
2203 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2204 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2205 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2207 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2208 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2210 /* try to open that key in hkcr */
2211 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2212 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2213 ok(res == ERROR_SUCCESS,
2214 "test key not found in hkcr: %d\n", res);
2216 /* set a value in user's classes */
2217 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2218 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2220 /* try to find the value in hkcr */
2221 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2222 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2223 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2225 /* modify the value in hklm */
2226 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2227 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2229 /* check that the value is not overwritten in hkcr or user's classes */
2230 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2231 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2232 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2233 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2234 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2235 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2237 /* modify the value in hkcr */
2238 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2239 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2241 /* check that the value is overwritten in hklm and user's classes */
2242 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2243 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2244 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2245 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2246 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2247 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2249 /* create a subkey in hklm */
2250 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2251 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2252 /* try to open that subkey in hkcr */
2253 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2254 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2256 /* set a value in hklm classes */
2257 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2258 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2260 /* try to find the value in hkcr */
2261 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2262 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2263 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2265 /* modify the value in hkcr */
2266 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2267 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2269 /* check that the value is modified in hklm classes */
2270 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2271 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2272 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2274 /* create a subkey in user's classes */
2275 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2276 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2278 /* set a value in user's classes */
2279 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2280 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2282 /* try to find the value in hkcr */
2283 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2284 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2285 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2287 /* modify the value in hklm */
2288 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2289 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2291 /* check that the value is not overwritten in hkcr or user's classes */
2292 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2293 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2294 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2295 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2296 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2297 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2299 /* modify the value in hkcr */
2300 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2301 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2303 /* check that the value is not overwritten in hklm, but in user's classes */
2304 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2305 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2306 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2307 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2308 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2309 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2311 /* new subkey in hkcr */
2312 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
2313 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
2314 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2315 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2317 /* try to open that new subkey in user's classes and hklm */
2318 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2319 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
2321 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2322 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2324 /* check that the value is present in hklm */
2325 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2326 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2327 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2333 delete_key( hkeysub1 );
2334 delete_key( hklmsub1 );
2335 delete_key( hkcrsub1 );
2336 delete_key( hklmsub2 );
2337 delete_key( hkcrsub2 );
2338 RegCloseKey( hkey );
2339 RegCloseKey( hklm );
2340 RegCloseKey( hkcr );
2341 RegCloseKey( hkeysub1 );
2342 RegCloseKey( hklmsub1 );
2343 RegCloseKey( hkcrsub1 );
2344 RegCloseKey( hklmsub2 );
2345 RegCloseKey( hkcrsub2 );
2348 static void test_deleted_key(void)
2352 DWORD val_count, type;
2355 /* Open the test key, then delete it while it's open */
2356 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
2358 delete_key( hkey_main );
2360 val_count = sizeof(value);
2362 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
2363 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2365 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
2366 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2368 val_count = sizeof(value);
2370 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
2371 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2373 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
2374 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2376 res = RegOpenKeyA( hkey, "test", &hkey2 );
2377 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2379 RegCloseKey( hkey2 );
2381 res = RegCreateKeyA( hkey, "test", &hkey2 );
2382 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2384 RegCloseKey( hkey2 );
2386 res = RegFlushKey( hkey );
2387 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2389 RegCloseKey( hkey );
2394 static void test_delete_value(void)
2399 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
2400 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2402 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2403 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2405 res = RegDeleteValueA( hkey_main, "test" );
2406 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2408 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2409 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2411 res = RegDeleteValueA( hkey_main, "test" );
2412 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2414 memset(longname, 'a', 400);
2416 res = RegDeleteValueA( hkey_main, longname );
2417 ok(res == ERROR_FILE_NOT_FOUND || broken(res == ERROR_MORE_DATA), /* nt4, win2k */
2418 "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2421 START_TEST(registry)
2423 /* Load pointers for functions that are not available in all Windows versions */
2428 create_test_entries();
2430 test_query_value_ex();
2432 test_reg_open_key();
2433 test_reg_create_key();
2434 test_reg_close_key();
2435 test_reg_delete_key();
2436 test_reg_query_value();
2437 test_string_termination();
2442 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2443 if (set_privileges(SE_BACKUP_NAME, TRUE) &&
2444 set_privileges(SE_RESTORE_NAME, TRUE))
2446 test_reg_save_key();
2447 test_reg_load_key();
2448 test_reg_unload_key();
2450 set_privileges(SE_BACKUP_NAME, FALSE);
2451 set_privileges(SE_RESTORE_NAME, FALSE);
2454 test_reg_delete_tree();
2457 test_delete_value();
2460 delete_key( hkey_main );
2462 test_regconnectregistry();