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=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
194 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
195 memset(value, 0xbd, cbData+1);
197 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
198 GLE = GetLastError();
199 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
202 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
203 lok(*value == 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
207 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
208 wine_debugstr_an((char*)value, cbData), cbData,
209 wine_debugstr_an(string, full_byte_len), full_byte_len);
210 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
212 HeapFree(GetProcessHeap(), 0, value);
215 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
216 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
219 DWORD ret, type, cbData;
224 /* When successful RegQueryValueExW() leaves GLE as is,
225 * so we must reset it to detect unimplemented functions.
227 SetLastError(0xdeadbeef);
228 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
229 GLE = GetLastError();
230 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
231 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
233 win_skip("RegQueryValueExW() is not implemented\n");
237 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
238 lok(cbData == full_byte_len,
239 "cbData=%d instead of %d\n", cbData, full_byte_len);
241 /* Give enough space to overflow by one WCHAR */
242 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
243 memset(value, 0xbd, cbData+2);
245 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
246 GLE = GetLastError();
247 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
250 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
251 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
252 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
254 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
255 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
256 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
257 HeapFree(GetProcessHeap(), 0, value);
260 static void test_set_value(void)
264 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
265 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};
266 static const WCHAR emptyW[] = {0};
267 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
268 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};
269 static const WCHAR substring2W[] = {'T','h','i','s',0};
271 static const char name1A[] = "CleanSingleString";
272 static const char name2A[] = "SomeIntraZeroedString";
273 static const char emptyA[] = "";
274 static const char string1A[] = "ThisNeverBreaks";
275 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
276 static const char substring2A[] = "This";
280 /* Crashes on NT4, Windows 2000 and XP SP1 */
281 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
282 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
285 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
286 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
287 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
288 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
290 /* RegSetValueA ignores the size passed in */
291 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
292 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
293 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
294 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
296 /* stops at first null */
297 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
298 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
299 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
300 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
302 /* only REG_SZ is supported on NT*/
303 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
304 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
306 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
307 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
309 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
310 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
312 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
313 * Surprisingly enough we're supposed to get zero bytes out of it.
315 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
316 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
317 test_hkey_main_Value_A(name1A, NULL, 0);
318 test_hkey_main_Value_W(name1W, NULL, 0);
320 /* test RegSetValueExA with an empty string */
321 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
322 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
323 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
324 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
326 /* test RegSetValueExA with off-by-one size */
327 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
328 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
329 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
330 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
332 /* test RegSetValueExA with normal string */
333 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
334 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
335 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
336 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
338 /* test RegSetValueExA with intrazeroed string */
339 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
340 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
341 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
342 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
346 /* Crashes on NT4, Windows 2000 and XP SP1 */
347 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
348 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
350 RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)1, 1);
351 RegSetValueExA(hkey_main, name2A, 0, REG_DWORD, (const BYTE *)1, 1);
354 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
355 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
356 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
357 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
359 ret = RegSetValueW(hkey_main, name1W, REG_SZ, string1W, sizeof(string1W));
360 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
361 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
362 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
364 /* RegSetValueW ignores the size passed in */
365 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
366 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
367 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
368 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
370 /* stops at first null */
371 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
372 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
373 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
374 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
376 /* only REG_SZ is supported */
377 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
378 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
379 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
380 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
381 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
382 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
384 /* test RegSetValueExW with off-by-one size */
385 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
386 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
387 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
388 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
390 /* test RegSetValueExW with normal string */
391 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
392 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
393 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
394 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
396 /* test RegSetValueExW with intrazeroed string */
397 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
398 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
399 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
400 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
402 /* test RegSetValueExW with data = 1 */
403 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)1, 1);
404 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
405 ret = RegSetValueExW(hkey_main, name2W, 0, REG_DWORD, (const BYTE *)1, 1);
406 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
409 static void create_test_entries(void)
411 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
413 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
414 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
416 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
417 "RegSetValueExA failed\n");
418 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
419 "RegSetValueExA failed\n");
420 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
421 "RegSetValueExA failed\n");
422 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
423 "RegSetValueExA failed\n");
424 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
425 "RegSetValueExA failed\n");
426 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
427 "RegSetValueExA failed\n");
428 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
429 "RegSetValueExA failed\n");
432 static void test_enum_value(void)
436 char value[20], data[20];
437 WCHAR valueW[20], dataW[20];
438 DWORD val_count, data_count, type;
439 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
440 static const WCHAR testW[] = {'T','e','s','t',0};
441 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
443 /* create the working key for new 'Test' value */
444 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
445 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
447 /* check NULL data with zero length */
448 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
449 if (GetVersion() & 0x80000000)
450 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
452 ok( !res, "RegSetValueExA returned %d\n", res );
453 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
454 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
455 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
456 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
458 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
459 ok( res == 0, "RegSetValueExA failed error %d\n", res );
461 /* overflow both name and data */
465 strcpy( value, "xxxxxxxxxx" );
466 strcpy( data, "xxxxxxxxxx" );
467 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
468 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
469 ok( val_count == 2, "val_count set to %d\n", val_count );
470 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
471 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
472 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
473 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
479 strcpy( value, "xxxxxxxxxx" );
480 strcpy( data, "xxxxxxxxxx" );
481 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
482 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
483 ok( val_count == 3, "val_count set to %d\n", val_count );
484 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
485 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
486 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
487 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
488 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
489 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
490 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
492 /* overflow empty name */
496 strcpy( value, "xxxxxxxxxx" );
497 strcpy( data, "xxxxxxxxxx" );
498 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
499 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
500 ok( val_count == 0, "val_count set to %d\n", val_count );
501 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
502 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
503 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
504 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
505 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
506 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
512 strcpy( value, "xxxxxxxxxx" );
513 strcpy( data, "xxxxxxxxxx" );
514 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
515 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
516 ok( val_count == 20, "val_count set to %d\n", val_count );
517 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
518 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
519 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
520 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
526 strcpy( value, "xxxxxxxxxx" );
527 strcpy( data, "xxxxxxxxxx" );
528 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
529 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
530 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
531 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
532 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
533 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
534 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
538 SetLastError(0xdeadbeef);
539 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
540 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
542 win_skip("RegSetValueExW is not implemented\n");
545 ok( res == 0, "RegSetValueExW failed error %d\n", res );
547 /* overflow both name and data */
551 memcpy( valueW, xxxW, sizeof(xxxW) );
552 memcpy( dataW, xxxW, sizeof(xxxW) );
553 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
554 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
555 ok( val_count == 2, "val_count set to %d\n", val_count );
556 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
557 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
558 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
559 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
565 memcpy( valueW, xxxW, sizeof(xxxW) );
566 memcpy( dataW, xxxW, sizeof(xxxW) );
567 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
568 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
569 ok( val_count == 3, "val_count set to %d\n", val_count );
570 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
571 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
572 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
573 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
579 memcpy( valueW, xxxW, sizeof(xxxW) );
580 memcpy( dataW, xxxW, sizeof(xxxW) );
581 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
582 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
583 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
584 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
585 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
586 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
587 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
593 memcpy( valueW, xxxW, sizeof(xxxW) );
594 memcpy( dataW, xxxW, sizeof(xxxW) );
595 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
596 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
597 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
598 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
599 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
600 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
601 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
604 RegDeleteKeyA(test_key, "");
605 RegCloseKey(test_key);
608 static void test_query_value_ex(void)
615 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
616 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
617 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
618 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
622 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
623 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
624 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
626 size = sizeof(buffer);
627 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
628 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
629 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
632 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
633 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
636 static void test_get_value(void)
643 CHAR expanded[] = "bar\\subdir1";
644 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
648 win_skip("RegGetValue not available on this platform\n");
652 /* Invalid parameter */
653 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
654 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
656 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
657 size = type = dw = 0xdeadbeef;
658 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
659 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
660 ok(size == 4, "size=%d\n", size);
661 ok(type == REG_DWORD, "type=%d\n", type);
662 ok(dw == 0x12345678, "dw=%d\n", dw);
664 /* Query by subkey-name */
665 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
666 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
668 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
669 size = type = dw = 0xdeadbeef;
670 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
671 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
672 /* Although the function failed all values are retrieved */
673 ok(size == 4, "size=%d\n", size);
674 ok(type == REG_DWORD, "type=%d\n", type);
675 ok(dw == 0x12345678, "dw=%d\n", dw);
677 /* Test RRF_ZEROONFAILURE */
678 type = dw = 0xdeadbeef; size = 4;
679 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
680 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
681 /* Again all values are retrieved ... */
682 ok(size == 4, "size=%d\n", size);
683 ok(type == REG_DWORD, "type=%d\n", type);
684 /* ... except the buffer, which is zeroed out */
685 ok(dw == 0, "dw=%d\n", dw);
687 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
688 type = size = 0xbadbeef;
689 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
690 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
691 ok(size == 4, "size=%d\n", size);
692 ok(type == REG_DWORD, "type=%d\n", type);
694 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
695 size = type = dw = 0xdeadbeef;
696 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
697 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
698 ok(size == 4, "size=%d\n", size);
699 ok(type == REG_DWORD, "type=%d\n", type);
700 ok(dw == 0x12345678, "dw=%d\n", dw);
702 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
703 size = type = dw = 0xdeadbeef;
704 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
705 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
706 ok(size == 4, "size=%d\n", size);
707 ok(type == REG_BINARY, "type=%d\n", type);
708 ok(dw == 0x12345678, "dw=%d\n", dw);
710 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
711 qw[0] = qw[1] = size = type = 0xdeadbeef;
712 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
713 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
714 ok(size == 8, "size=%d\n", size);
715 ok(type == REG_BINARY, "type=%d\n", type);
716 ok(qw[0] == 0x12345678 &&
717 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
719 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
720 type = dw = 0xdeadbeef; size = 4;
721 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
722 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
723 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
724 ok(size == 8, "size=%d\n", size);
726 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
727 qw[0] = qw[1] = size = type = 0xdeadbeef;
728 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
729 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
730 ok(size == 8, "size=%d\n", size);
731 ok(type == REG_BINARY, "type=%d\n", type);
732 ok(qw[0] == 0x12345678 &&
733 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
735 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
736 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
737 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
738 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
739 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
740 ok(type == REG_SZ, "type=%d\n", type);
741 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
743 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
744 type = 0xdeadbeef; size = 0;
745 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
746 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
747 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
748 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
749 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
750 ok(type == REG_SZ, "type=%d\n", type);
752 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
753 strcpy(buf, sTestpath1);
756 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
757 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
758 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
760 size == 1, /* win2k3 */
762 ok(type == REG_SZ, "type=%d\n", type);
763 ok(!strcmp(sTestpath1, buf) ||
765 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
767 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
768 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
769 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
770 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
771 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
772 ok(type == REG_SZ, "type=%d\n", type);
773 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
775 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
777 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
778 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
779 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
780 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
781 (size == strlen(sTestpath2)+1),
782 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
784 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
785 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
786 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
787 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
788 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
789 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
790 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
791 ok(type == REG_SZ, "type=%d\n", type);
792 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
794 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
795 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
796 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
797 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
798 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
799 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
800 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
801 ok(type == REG_SZ, "type=%d\n", type);
802 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
804 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
805 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
806 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
807 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
808 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
809 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
810 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
812 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
814 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
815 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
816 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
817 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
818 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
820 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
821 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
822 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
824 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
825 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
826 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
827 ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
829 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
830 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
831 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
832 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
833 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
834 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
835 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
836 ok(type == REG_SZ, "type=%d\n", type);
837 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
840 static void test_reg_open_key(void)
843 HKEY hkResult = NULL;
844 HKEY hkPreserve = NULL;
845 HKEY hkRoot64 = NULL;
846 HKEY hkRoot32 = NULL;
848 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
850 EXPLICIT_ACCESSA access;
852 SECURITY_DESCRIPTOR *sd;
854 /* successful open */
855 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
856 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
857 ok(hkResult != NULL, "expected hkResult != NULL\n");
858 hkPreserve = hkResult;
860 /* open same key twice */
861 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
862 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
863 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
864 ok(hkResult != NULL, "hkResult != NULL\n");
865 RegCloseKey(hkResult);
867 /* open nonexistent key
868 * check that hkResult is set to NULL
870 hkResult = hkPreserve;
871 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
872 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
873 ok(hkResult == NULL, "expected hkResult == NULL\n");
875 /* open the same nonexistent key again to make sure the key wasn't created */
876 hkResult = hkPreserve;
877 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
878 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
879 ok(hkResult == NULL, "expected hkResult == NULL\n");
881 /* send in NULL lpSubKey
882 * check that hkResult receives the value of hKey
884 hkResult = hkPreserve;
885 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
886 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
887 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
889 /* send empty-string in lpSubKey */
890 hkResult = hkPreserve;
891 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
892 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
893 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
895 /* send in NULL lpSubKey and NULL hKey
896 * hkResult is set to NULL
898 hkResult = hkPreserve;
899 ret = RegOpenKeyA(NULL, NULL, &hkResult);
900 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
901 ok(hkResult == NULL, "expected hkResult == NULL\n");
903 /* only send NULL hKey
904 * the value of hkResult remains unchanged
906 hkResult = hkPreserve;
907 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
908 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
909 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
910 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
911 RegCloseKey(hkResult);
913 /* send in NULL hkResult */
914 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
915 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
917 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
918 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
920 ret = RegOpenKeyA(NULL, NULL, NULL);
921 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
923 /* beginning backslash character */
924 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
925 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
926 broken(ret == ERROR_SUCCESS), /* wow64 */
927 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
928 if (!ret) RegCloseKey(hkResult);
931 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
932 ok(ret == ERROR_SUCCESS || /* 2k/XP */
933 ret == ERROR_BAD_PATHNAME, /* NT */
934 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
935 RegCloseKey(hkResult);
939 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
940 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
941 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
942 RegCloseKey(hkResult);
945 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
946 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
947 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
948 RegCloseKey(hkResult);
950 /* Try using WOW64 flags when opening a key with a DACL set to verify that
951 * the registry access check is performed correctly. Redirection isn't
952 * being tested, so the tests don't care about whether the process is
953 * running under WOW64. */
954 if (!pIsWow64Process)
956 win_skip("WOW64 flags are not recognized\n");
960 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
961 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
962 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
963 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
965 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
966 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
967 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
968 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
970 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
971 0, 0, 0, 0, 0, 0, 0, &world_sid);
973 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
975 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
976 access.grfAccessMode = SET_ACCESS;
977 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
978 access.Trustee.pMultipleTrustee = NULL;
979 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
980 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
981 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
982 access.Trustee.ptstrName = (char *)world_sid;
984 ret = SetEntriesInAclA(1, &access, NULL, &key_acl);
985 ok(ret == ERROR_SUCCESS,
986 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret, GetLastError());
988 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
989 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
991 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
993 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
995 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
997 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
998 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1000 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1002 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1004 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1007 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
1008 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1009 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1010 RegCloseKey(hkResult);
1013 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
1014 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1015 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1016 RegCloseKey(hkResult);
1018 HeapFree(GetProcessHeap(), 0, sd);
1021 RegDeleteKeyA(hkRoot64, "");
1022 RegCloseKey(hkRoot64);
1023 RegDeleteKeyA(hkRoot32, "");
1024 RegCloseKey(hkRoot32);
1027 static void test_reg_create_key(void)
1031 HKEY hkRoot64 = NULL;
1032 HKEY hkRoot32 = NULL;
1035 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1037 EXPLICIT_ACCESSA access;
1039 SECURITY_DESCRIPTOR *sd;
1041 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1042 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1043 /* should succeed: all versions of Windows ignore the access rights
1044 * to the parent handle */
1045 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
1046 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1049 RegDeleteKey(hkey2, "");
1050 RegDeleteKey(hkey1, "");
1054 /* test creation of volatile keys */
1055 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
1056 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1057 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1058 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE, "RegCreateKeyExA failed with error %d\n", ret);
1059 if (!ret) RegCloseKey( hkey2 );
1060 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1061 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1063 /* should succeed if the key already exists */
1064 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1065 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1068 RegDeleteKey(hkey2, "");
1069 RegDeleteKey(hkey1, "");
1073 /* beginning backslash character */
1074 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1075 if (!(GetVersion() & 0x80000000))
1076 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1078 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1079 RegDeleteKey(hkey1, NULL);
1083 /* WOW64 flags - open an existing key */
1085 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1086 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1087 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1091 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1092 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1093 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1096 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1097 * the registry access check is performed correctly. Redirection isn't
1098 * being tested, so the tests don't care about whether the process is
1099 * running under WOW64. */
1100 if (!pIsWow64Process)
1102 win_skip("WOW64 flags are not recognized\n");
1106 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1107 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1108 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1109 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1111 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1112 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1113 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1114 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1116 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1117 0, 0, 0, 0, 0, 0, 0, &world_sid);
1119 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1121 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1122 access.grfAccessMode = SET_ACCESS;
1123 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1124 access.Trustee.pMultipleTrustee = NULL;
1125 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1126 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1127 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1128 access.Trustee.ptstrName = (char *)world_sid;
1130 dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
1131 ok(ret == ERROR_SUCCESS,
1132 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
1134 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1135 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1137 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1139 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1141 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1143 /* The "sanctioned" methods of setting a registry ACL aren't implemented in Wine. */
1144 bRet = SetKernelObjectSecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1146 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1148 bRet = SetKernelObjectSecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1150 "Expected SetKernelObjectSecurity to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1153 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1154 KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
1155 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1156 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1160 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1161 KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
1162 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1163 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1166 HeapFree(GetProcessHeap(), 0, sd);
1169 RegDeleteKeyA(hkRoot64, "");
1170 RegCloseKey(hkRoot64);
1171 RegDeleteKeyA(hkRoot32, "");
1172 RegCloseKey(hkRoot32);
1175 static void test_reg_close_key(void)
1180 /* successfully close key
1181 * hkHandle remains changed after call to RegCloseKey
1183 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1184 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1185 ret = RegCloseKey(hkHandle);
1186 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1188 /* try to close the key twice */
1189 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1190 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1191 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1193 /* try to close a NULL handle */
1194 ret = RegCloseKey(NULL);
1195 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1196 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1198 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1199 * win98 doesn't give a new handle when the same key is opened.
1200 * Not re-opening will make some next tests fail.
1202 if (hkey_main == hkHandle)
1204 trace("The main handle is most likely closed, so re-opening\n");
1205 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1209 static void test_reg_delete_key(void)
1213 ret = RegDeleteKey(hkey_main, NULL);
1215 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1216 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1217 * Not re-creating will make some next tests fail.
1219 if (ret == ERROR_SUCCESS)
1221 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1222 " re-creating the main key\n");
1226 ok(ret == ERROR_INVALID_PARAMETER ||
1227 ret == ERROR_ACCESS_DENIED ||
1228 ret == ERROR_BADKEY, /* Win95 */
1232 static void test_reg_save_key(void)
1236 ret = RegSaveKey(hkey_main, "saved_key", NULL);
1237 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1240 static void test_reg_load_key(void)
1245 ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1246 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1248 ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1249 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1251 RegCloseKey(hkHandle);
1254 static void test_reg_unload_key(void)
1258 ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
1259 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1261 DeleteFile("saved_key");
1262 DeleteFile("saved_key.LOG");
1265 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1267 TOKEN_PRIVILEGES tp;
1271 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1274 if(!LookupPrivilegeValue(NULL, privilege, &luid))
1276 CloseHandle(hToken);
1280 tp.PrivilegeCount = 1;
1281 tp.Privileges[0].Luid = luid;
1284 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1286 tp.Privileges[0].Attributes = 0;
1288 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1289 if (GetLastError() != ERROR_SUCCESS)
1291 CloseHandle(hToken);
1295 CloseHandle(hToken);
1299 /* tests that show that RegConnectRegistry and
1300 OpenSCManager accept computer names without the
1301 \\ prefix (what MSDN says). */
1302 static void test_regconnectregistry( void)
1304 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1305 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1306 DWORD len = sizeof(compName) ;
1312 SetLastError(0xdeadbeef);
1313 ret = GetComputerNameA(compName, &len);
1314 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1317 lstrcpyA(netwName, "\\\\");
1318 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1320 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1322 retl == ERROR_DLL_INIT_FAILED ||
1323 retl == ERROR_BAD_NETPATH, /* some win2k */
1324 "RegConnectRegistryA failed err = %d\n", retl);
1325 if( !retl) RegCloseKey( hkey);
1327 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1329 retl == ERROR_DLL_INIT_FAILED ||
1330 retl == ERROR_BAD_NETPATH, /* some win2k */
1331 "RegConnectRegistryA failed err = %d\n", retl);
1332 if( !retl) RegCloseKey( hkey);
1334 SetLastError(0xdeadbeef);
1335 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1336 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1338 win_skip("OpenSCManagerA is not implemented\n");
1342 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1343 CloseServiceHandle( schnd);
1345 SetLastError(0xdeadbeef);
1346 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1347 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1348 CloseServiceHandle( schnd);
1352 static void test_reg_query_value(void)
1359 static const WCHAR expected[] = {'d','a','t','a',0};
1361 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1362 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1364 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1365 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1367 /* try an invalid hkey */
1368 SetLastError(0xdeadbeef);
1370 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1371 ok(ret == ERROR_INVALID_HANDLE ||
1372 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1373 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1374 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1375 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1377 /* try a NULL hkey */
1378 SetLastError(0xdeadbeef);
1380 ret = RegQueryValueA(NULL, "subkey", val, &size);
1381 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1382 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1383 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1385 /* try a NULL value */
1387 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1388 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1389 ok(size == 5, "Expected 5, got %d\n", size);
1391 /* try a NULL size */
1392 SetLastError(0xdeadbeef);
1394 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1395 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1396 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1397 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1399 /* try a NULL value and size */
1400 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1401 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1403 /* try a size too small */
1404 SetLastError(0xdeadbeef);
1407 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1408 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1409 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1410 ok(lstrlenA(val) == 0, "Expected val to be untouched, got %s\n", val);
1411 ok(size == 5, "Expected 5, got %d\n", size);
1413 /* successfully read the value using 'subkey' */
1415 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1416 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1417 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1418 ok(size == 5, "Expected 5, got %d\n", size);
1420 /* successfully read the value using the subkey key */
1422 ret = RegQueryValueA(subkey, NULL, val, &size);
1423 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1424 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1425 ok(size == 5, "Expected 5, got %d\n", size);
1427 /* unicode - try size too small */
1428 SetLastError(0xdeadbeef);
1431 ret = RegQueryValueW(subkey, NULL, valW, &size);
1432 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1434 win_skip("RegQueryValueW is not implemented\n");
1437 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1438 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1439 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1440 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1442 /* unicode - try size in WCHARS */
1443 SetLastError(0xdeadbeef);
1444 size = sizeof(valW) / sizeof(WCHAR);
1445 ret = RegQueryValueW(subkey, NULL, valW, &size);
1446 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1447 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1448 ok(lstrlenW(valW) == 0, "Expected valW to be untouched\n");
1449 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1451 /* unicode - successfully read the value */
1452 size = sizeof(valW);
1453 ret = RegQueryValueW(subkey, NULL, valW, &size);
1454 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1455 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1456 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1458 /* unicode - set the value without a NULL terminator */
1459 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1460 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1462 /* unicode - read the unterminated value, value is terminated for us */
1463 memset(valW, 'a', sizeof(valW));
1464 size = sizeof(valW);
1465 ret = RegQueryValueW(subkey, NULL, valW, &size);
1466 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1467 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1468 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1471 RegDeleteKeyA(subkey, "");
1472 RegCloseKey(subkey);
1475 static void test_string_termination(void)
1479 static const char string[] = "FullString";
1482 DWORD insize, outsize, nsize;
1484 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
1485 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1487 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
1488 insize=sizeof(string)-1;
1489 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1490 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1492 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1493 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
1495 /* Off-by-two RegSetValueExA -> no trailing '\0' */
1496 insize=sizeof(string)-2;
1497 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
1498 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
1500 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
1501 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1502 ok(outsize == insize, "wrong size %u != %u\n", outsize, insize);
1504 /* RegQueryValueExA may return a string with no trailing '\0' */
1506 memset(buffer, 0xbd, sizeof(buffer));
1507 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1508 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1509 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1510 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1511 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1512 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1514 /* RegQueryValueExA adds a trailing '\0' if there is room */
1516 memset(buffer, 0xbd, sizeof(buffer));
1517 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
1518 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
1519 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1520 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1521 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1522 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1524 /* RegEnumValueA may return a string with no trailing '\0' */
1526 memset(buffer, 0xbd, sizeof(buffer));
1528 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1529 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1530 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1531 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1532 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1533 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1534 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1536 /* RegEnumValueA adds a trailing '\0' if there is room */
1538 memset(buffer, 0xbd, sizeof(buffer));
1540 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
1541 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
1542 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
1543 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
1544 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
1545 wine_debugstr_an((char*)buffer, outsize), outsize, string);
1546 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
1548 RegDeleteKeyA(subkey, "");
1549 RegCloseKey(subkey);
1552 static void test_reg_delete_tree(void)
1554 CHAR buffer[MAX_PATH];
1555 HKEY subkey, subkey2;
1558 if(!pRegDeleteTreeA) {
1559 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
1563 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1564 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1565 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1566 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1567 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1568 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1569 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
1570 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1571 ret = RegCloseKey(subkey2);
1572 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1574 ret = pRegDeleteTreeA(subkey, "subkey2");
1575 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1576 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1577 "subkey2 was not deleted\n");
1579 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1580 "Default value of subkey not longer present\n");
1582 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1583 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1584 ret = RegCloseKey(subkey2);
1585 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1586 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
1587 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1588 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1589 "subkey2 was not deleted\n");
1590 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
1591 "Default value of subkey not longer present\n");
1593 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
1594 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1595 ret = RegCloseKey(subkey2);
1596 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1597 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
1598 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1599 ret = RegCloseKey(subkey2);
1600 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1601 ret = RegSetValueA(subkey, "value", REG_SZ, "data2", 5);
1602 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1603 ret = pRegDeleteTreeA(subkey, NULL);
1604 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1605 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
1606 "subkey was deleted\n");
1607 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
1608 "subkey2 was not deleted\n");
1609 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
1610 "subkey3 was not deleted\n");
1612 ret = RegQueryValueA(subkey, NULL, buffer, &size);
1613 ok(ret == ERROR_SUCCESS,
1614 "Default value of subkey is not present\n");
1615 ok(!lstrlenA(buffer),
1616 "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
1618 ok(RegQueryValueA(subkey, "value", buffer, &size),
1619 "Value is still present\n");
1621 ret = pRegDeleteTreeA(hkey_main, "not-here");
1622 ok(ret == ERROR_FILE_NOT_FOUND,
1623 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1626 static void test_rw_order(void)
1630 static char keyname[] = "test_rw_order";
1632 DWORD values, value_len, value_name_max_len;
1635 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
1636 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
1637 if(ret != ERROR_SUCCESS) {
1638 skip("Couldn't create key. Skipping.\n");
1642 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1643 "RegSetValueExA for value \"A\" failed\n");
1644 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1645 "RegSetValueExA for value \"C\" failed\n");
1646 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1647 "RegSetValueExA for value \"D\" failed\n");
1648 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
1649 "RegSetValueExA for value \"B\" failed\n");
1651 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
1652 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
1653 ok(values == 4, "Expected 4 values, got %u\n", values);
1655 /* Value enumeration preserves RegSetValueEx call order */
1657 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1658 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
1660 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1661 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
1663 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1664 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
1666 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
1667 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
1669 ok(!RegDeleteKey(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
1672 static void test_symlinks(void)
1674 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
1675 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
1677 UNICODE_STRING target_str;
1681 DWORD target_len, type, len, dw, err;
1683 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
1685 win_skip( "Can't perform symlink tests\n" );
1689 pRtlFormatCurrentUserKeyPath( &target_str );
1691 target_len = target_str.Length + sizeof(targetW);
1692 target = HeapAlloc( GetProcessHeap(), 0, target_len );
1693 memcpy( target, target_str.Buffer, target_str.Length );
1694 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
1696 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1697 KEY_ALL_ACCESS, NULL, &link, NULL );
1698 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
1700 /* REG_SZ is not allowed */
1701 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
1702 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1703 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
1704 (BYTE *)target, target_len - sizeof(WCHAR) );
1705 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1706 /* other values are not allowed */
1707 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
1708 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
1710 /* try opening the target through the link */
1712 err = RegOpenKeyA( hkey_main, "link", &key );
1713 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
1715 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1716 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1719 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1720 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1723 err = RegOpenKeyA( hkey_main, "link", &key );
1724 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1726 len = sizeof(buffer);
1727 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1728 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
1729 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1731 len = sizeof(buffer);
1732 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1733 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1735 /* REG_LINK can be created in non-link keys */
1736 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
1737 (BYTE *)target, target_len - sizeof(WCHAR) );
1738 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
1739 len = sizeof(buffer);
1740 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1741 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1742 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1743 err = RegDeleteValueA( key, "SymbolicLinkValue" );
1744 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
1748 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
1749 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1751 len = sizeof(buffer);
1752 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
1753 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1754 ok( len == sizeof(DWORD), "wrong len %u\n", len );
1756 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1757 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
1760 /* now open the symlink itself */
1762 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
1763 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
1764 len = sizeof(buffer);
1765 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1766 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1767 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1770 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
1771 KEY_ALL_ACCESS, NULL, &key, NULL );
1772 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
1773 len = sizeof(buffer);
1774 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
1775 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
1776 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
1779 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
1780 KEY_ALL_ACCESS, NULL, &key, NULL );
1781 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1783 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
1784 KEY_ALL_ACCESS, NULL, &key, NULL );
1785 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
1787 err = RegDeleteKey( hkey_main, "target" );
1788 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
1790 err = RegDeleteKey( hkey_main, "link" );
1791 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
1793 status = pNtDeleteKey( link );
1794 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
1795 RegCloseKey( link );
1797 HeapFree( GetProcessHeap(), 0, target );
1798 pRtlFreeUnicodeString( &target_str );
1801 static const DWORD ptr_size = 8 * sizeof(void*);
1803 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
1806 DWORD err, type, dw, len = sizeof(dw);
1808 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
1809 if (err == ERROR_FILE_NOT_FOUND) return 0;
1810 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
1812 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
1813 if (err == ERROR_FILE_NOT_FOUND)
1816 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
1821 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
1823 DWORD dw = get_key_value( root, name, flags );
1824 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
1826 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
1828 static void test_redirection(void)
1830 DWORD err, type, dw, len;
1831 HKEY key, root32, root64, key32, key64;
1832 BOOL is_vista = FALSE;
1837 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
1839 skip( "Not on Wow64, no redirection\n" );
1844 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1845 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
1846 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1848 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1849 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
1850 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1852 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1853 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
1854 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1856 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
1857 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
1858 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1861 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1862 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1865 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
1866 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
1870 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
1871 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1872 ok( dw == 32, "wrong value %u\n", dw );
1876 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
1877 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
1878 ok( dw == 64, "wrong value %u\n", dw );
1880 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1881 KEY_ALL_ACCESS, NULL, &key, NULL );
1882 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1886 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
1887 /* the new (and simpler) Win7 mechanism doesn't */
1888 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
1890 trace( "using Vista-style Wow6432Node handling\n" );
1893 check_key_value( key, "Wine\\Winetest", 0, 32 );
1894 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1895 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1896 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1897 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1898 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1902 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
1904 trace( "using Vista-style Wow6432Node handling\n" );
1907 check_key_value( key, "Wine\\Winetest", 0, 64 );
1908 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1914 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1915 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1916 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1917 dw = get_key_value( key, "Wine\\Winetest", 0 );
1918 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1919 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1920 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1921 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
1922 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
1923 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
1924 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1927 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
1928 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1929 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1930 check_key_value( key, "Wine\\Winetest", 0, 32 );
1931 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1932 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1933 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
1934 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
1935 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
1939 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
1940 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
1943 /* KEY_WOW64 flags have no effect on 64-bit */
1944 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1945 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1946 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1947 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1951 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
1952 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1953 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1954 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1957 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1958 KEY_ALL_ACCESS, NULL, &key, NULL );
1959 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1960 check_key_value( key, "Wine\\Winetest", 0, 32 );
1961 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1962 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1967 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1968 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1969 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1970 dw = get_key_value( key, "Wine\\Winetest", 0 );
1971 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
1972 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1973 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1976 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
1977 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1978 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1979 check_key_value( key, "Wine\\Winetest", 0, 32 );
1980 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1981 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
1985 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1986 KEY_ALL_ACCESS, NULL, &key, NULL );
1987 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1988 check_key_value( key, "Winetest", 0, 32 );
1989 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
1990 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
1995 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
1996 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
1997 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
1998 dw = get_key_value( key, "Winetest", 0 );
1999 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
2000 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2001 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2004 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2005 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2006 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2007 check_key_value( key, "Winetest", 0, 32 );
2008 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2009 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2013 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2014 KEY_ALL_ACCESS, NULL, &key, NULL );
2015 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2016 check_key_value( key, "Winetest", 0, ptr_size );
2017 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
2018 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2019 if (ptr_size == 32) ok( dw == 32, "wrong value %u\n", dw );
2020 else todo_wine ok( dw == 32, "wrong value %u\n", dw );
2025 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2026 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2027 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2028 dw = get_key_value( key, "Winetest", 0 );
2029 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2030 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
2031 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2032 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2035 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2036 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2037 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2038 check_key_value( key, "Winetest", 0, 32 );
2039 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2040 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2044 if (pRegDeleteKeyExA)
2046 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
2047 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2048 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2049 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2050 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2051 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
2055 err = RegDeleteKeyA( key32, "" );
2056 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2057 err = RegDeleteKeyA( key64, "" );
2058 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2059 RegDeleteKeyA( key64, "" );
2060 RegDeleteKeyA( root64, "" );
2062 RegCloseKey( key32 );
2063 RegCloseKey( key64 );
2064 RegCloseKey( root32 );
2065 RegCloseKey( root64 );
2068 static void test_classesroot(void)
2070 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
2072 DWORD type = REG_SZ;
2073 static CHAR buffer[8];
2076 /* create a key in the user's classes */
2077 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
2080 RegCloseKey( hkey );
2082 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2083 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL );
2084 if (res == ERROR_ACCESS_DENIED)
2086 skip("not enough privileges to add a user class\n");
2090 /* try to open that key in hkcr */
2091 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2092 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2093 todo_wine ok(res == ERROR_SUCCESS ||
2094 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2095 "test key not found in hkcr: %d\n", res);
2098 skip("HKCR key merging not supported\n");
2100 RegCloseKey( hkey );
2104 /* set a value in user's classes */
2105 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2106 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2108 /* try to find the value in hkcr */
2109 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
2110 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2111 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2113 /* modify the value in hkcr */
2114 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2115 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2117 /* check if the value is also modified in user's classes */
2118 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
2119 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2120 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2122 /* set a value in hkcr */
2123 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2124 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2126 /* try to find the value in user's classes */
2127 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
2128 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2129 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2131 /* modify the value in user's classes */
2132 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2133 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2135 /* check if the value is also modified in hkcr */
2136 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
2137 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2138 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2143 RegCloseKey( hkey );
2144 RegCloseKey( hkcr );
2146 /* create a key in the hklm classes */
2147 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2150 RegCloseKey( hklm );
2152 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
2153 KEY_ALL_ACCESS, NULL, &hklm, NULL );
2154 if (res == ERROR_ACCESS_DENIED)
2156 skip("not enough privileges to add a system class\n");
2160 /* try to open that key in hkcr */
2161 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2162 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2163 ok(res == ERROR_SUCCESS,
2164 "test key not found in hkcr: %d\n", res);
2168 RegCloseKey( hklm );
2172 /* set a value in hklm classes */
2173 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2174 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2176 /* try to find the value in hkcr */
2177 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2178 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2179 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2181 /* modify the value in hkcr */
2182 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2183 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2185 /* check that the value is not modified in hklm classes */
2186 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2187 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2188 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2190 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2191 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2193 /* try to open that key in hkcr */
2194 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2195 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2196 ok(res == ERROR_SUCCESS,
2197 "test key not found in hkcr: %d\n", res);
2199 /* set a value in user's classes */
2200 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2201 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2203 /* try to find the value in hkcr */
2204 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2205 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2206 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2208 /* modify the value in hklm */
2209 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2210 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2212 /* check that the value is not overwritten in hkcr or user's classes */
2213 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2214 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2215 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2216 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2217 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2218 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2220 /* modify the value in hkcr */
2221 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2222 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2224 /* check that the value is overwritten in hklm and user's classes */
2225 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2226 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2227 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2228 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2229 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2230 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2232 /* create a subkey in hklm */
2233 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2234 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2235 /* try to open that subkey in hkcr */
2236 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2237 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2239 /* set a value in hklm classes */
2240 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2241 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2243 /* try to find the value in hkcr */
2244 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2245 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2246 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2248 /* modify the value in hkcr */
2249 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2250 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2252 /* check that the value is modified in hklm classes */
2253 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2254 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2255 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2257 /* create a subkey in user's classes */
2258 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2259 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2261 /* set a value in user's classes */
2262 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2263 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2265 /* try to find the value in hkcr */
2266 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2267 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2268 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2270 /* modify the value in hklm */
2271 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2272 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2274 /* check that the value is not overwritten in hkcr or user's classes */
2275 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2276 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2277 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2278 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2279 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2280 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2282 /* modify the value in hkcr */
2283 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2284 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2286 /* check that the value is not overwritten in hklm, but in user's classes */
2287 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2288 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2289 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2290 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2291 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2292 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2294 /* new subkey in hkcr */
2295 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
2296 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
2297 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2298 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2300 /* try to open that new subkey in user's classes and hklm */
2301 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2302 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
2304 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
2305 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
2307 /* check that the value is present in hklm */
2308 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2309 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2310 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2316 delete_key( hkeysub1 );
2317 delete_key( hklmsub1 );
2318 delete_key( hkcrsub1 );
2319 delete_key( hklmsub2 );
2320 delete_key( hkcrsub2 );
2321 RegCloseKey( hkey );
2322 RegCloseKey( hklm );
2323 RegCloseKey( hkcr );
2324 RegCloseKey( hkeysub1 );
2325 RegCloseKey( hklmsub1 );
2326 RegCloseKey( hkcrsub1 );
2327 RegCloseKey( hklmsub2 );
2328 RegCloseKey( hkcrsub2 );
2331 static void test_deleted_key(void)
2335 DWORD val_count, type;
2338 /* Open the test key, then delete it while it's open */
2339 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
2341 delete_key( hkey_main );
2343 val_count = sizeof(value);
2345 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
2346 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2348 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
2349 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2351 val_count = sizeof(value);
2353 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
2354 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2356 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
2357 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2359 res = RegOpenKeyA( hkey, "test", &hkey2 );
2360 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2362 RegCloseKey( hkey2 );
2364 res = RegCreateKeyA( hkey, "test", &hkey2 );
2365 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2367 RegCloseKey( hkey2 );
2369 res = RegFlushKey( hkey );
2370 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
2372 RegCloseKey( hkey );
2377 static void test_delete_value(void)
2382 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
2383 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2385 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2386 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2388 res = RegDeleteValueA( hkey_main, "test" );
2389 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
2391 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
2392 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2394 res = RegDeleteValueA( hkey_main, "test" );
2395 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2397 memset(longname, 'a', 400);
2399 res = RegDeleteValueA( hkey_main, longname );
2400 ok(res == ERROR_FILE_NOT_FOUND || broken(res == ERROR_MORE_DATA), /* nt4, win2k */
2401 "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
2404 START_TEST(registry)
2406 /* Load pointers for functions that are not available in all Windows versions */
2411 create_test_entries();
2413 test_query_value_ex();
2415 test_reg_open_key();
2416 test_reg_create_key();
2417 test_reg_close_key();
2418 test_reg_delete_key();
2419 test_reg_query_value();
2420 test_string_termination();
2425 /* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
2426 if (set_privileges(SE_BACKUP_NAME, TRUE) &&
2427 set_privileges(SE_RESTORE_NAME, TRUE))
2429 test_reg_save_key();
2430 test_reg_load_key();
2431 test_reg_unload_key();
2433 set_privileges(SE_BACKUP_NAME, FALSE);
2434 set_privileges(SE_RESTORE_NAME, FALSE);
2437 test_reg_delete_tree();
2440 test_delete_value();
2443 delete_key( hkey_main );
2445 test_regconnectregistry();