winex11.drv: Map coordinates before calling send_mouse_input.
[wine/zf.git] / dlls / advapi32 / tests / registry.c
blobdfadd13ea8c8d95ed938e6d8c6bd944825346c46
1 /*
2 * Unit tests for registry functions
4 * Copyright (c) 2002 Alexandre Julliard
5 * Copyright (c) 2010 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include "ntstatus.h"
26 #define WIN32_NO_STATUS
27 #include "wine/test.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winternl.h"
31 #include "winreg.h"
32 #include "winperf.h"
33 #include "winsvc.h"
34 #include "winerror.h"
35 #include "aclapi.h"
37 #define IS_HKCR(hk) ((UINT_PTR)hk > 0 && ((UINT_PTR)hk & 3) == 2)
39 static HKEY hkey_main;
40 static DWORD GLE;
42 static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
43 static const char * sTestpath2 = "%FOO%\\subdir1";
44 static const DWORD ptr_size = 8 * sizeof(void*);
46 static DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
47 static DWORD (WINAPI *pRegGetValueW)(HKEY,LPCWSTR,LPCWSTR,DWORD,LPDWORD,PVOID,LPDWORD);
48 static LONG (WINAPI *pRegCopyTreeA)(HKEY,const char *,HKEY);
49 static LONG (WINAPI *pRegDeleteTreeA)(HKEY,const char *);
50 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
51 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
52 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
53 static NTSTATUS (WINAPI * pNtUnloadKey)(POBJECT_ATTRIBUTES);
54 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
55 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
56 static NTSTATUS (WINAPI * pRtlInitUnicodeString)(PUNICODE_STRING,PCWSTR);
57 static LONG (WINAPI *pRegDeleteKeyValueA)(HKEY,LPCSTR,LPCSTR);
58 static LONG (WINAPI *pRegSetKeyValueW)(HKEY,LPCWSTR,LPCWSTR,DWORD,const void*,DWORD);
59 static LONG (WINAPI *pRegLoadMUIStringA)(HKEY,LPCSTR,LPSTR,DWORD,LPDWORD,DWORD,LPCSTR);
60 static LONG (WINAPI *pRegLoadMUIStringW)(HKEY,LPCWSTR,LPWSTR,DWORD,LPDWORD,DWORD,LPCWSTR);
61 static DWORD (WINAPI *pEnumDynamicTimeZoneInformation)(const DWORD,
62 DYNAMIC_TIME_ZONE_INFORMATION*);
64 static BOOL limited_user;
66 static const char *dbgstr_SYSTEMTIME(const SYSTEMTIME *st)
68 return wine_dbg_sprintf("%02d-%02d-%04d %02d:%02d:%02d.%03d",
69 st->wMonth, st->wDay, st->wYear,
70 st->wHour, st->wMinute, st->wSecond, st->wMilliseconds);
73 #define ADVAPI32_GET_PROC(func) \
74 p ## func = (void*)GetProcAddress(hadvapi32, #func)
76 static void InitFunctionPtrs(void)
78 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
79 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
80 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
82 /* This function was introduced with Windows 2003 SP1 */
83 ADVAPI32_GET_PROC(RegGetValueA);
84 ADVAPI32_GET_PROC(RegGetValueW);
85 ADVAPI32_GET_PROC(RegCopyTreeA);
86 ADVAPI32_GET_PROC(RegDeleteTreeA);
87 ADVAPI32_GET_PROC(RegDeleteKeyExA);
88 ADVAPI32_GET_PROC(RegDeleteKeyValueA);
89 ADVAPI32_GET_PROC(RegSetKeyValueW);
90 ADVAPI32_GET_PROC(RegLoadMUIStringA);
91 ADVAPI32_GET_PROC(RegLoadMUIStringW);
92 ADVAPI32_GET_PROC(EnumDynamicTimeZoneInformation);
94 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
95 pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
96 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
97 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
98 pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
99 pNtUnloadKey = (void *)GetProcAddress( hntdll, "NtUnloadKey" );
102 /* delete key and all its subkeys */
103 static DWORD delete_key( HKEY hkey )
105 char name[MAX_PATH];
106 DWORD ret;
108 if ((ret = RegOpenKeyExA( hkey, "", 0, KEY_ENUMERATE_SUB_KEYS, &hkey ))) return ret;
109 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
111 HKEY tmp;
112 if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
114 ret = delete_key( tmp );
115 RegCloseKey( tmp );
117 if (ret) break;
119 if (ret != ERROR_NO_MORE_ITEMS) return ret;
120 RegDeleteKeyA( hkey, "" );
121 RegCloseKey(hkey);
122 return 0;
125 static void setup_main_key(void)
127 DWORD ret;
129 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
131 ret = RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
132 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
135 static void check_user_privs(void)
137 DWORD ret;
138 HKEY hkey = (HKEY)0xdeadbeef;
140 ret = RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WRITE, &hkey);
141 ok(ret == ERROR_SUCCESS || ret == ERROR_ACCESS_DENIED, "expected success or access denied, got %i\n", ret);
142 if (ret == ERROR_SUCCESS)
144 ok(hkey != NULL, "RegOpenKeyExA succeeded but returned NULL hkey\n");
145 RegCloseKey(hkey);
147 else
149 ok(hkey == NULL, "RegOpenKeyExA failed but returned hkey %p\n", hkey);
150 limited_user = TRUE;
151 trace("running as limited user\n");
155 #define lok ok_(__FILE__, line)
156 #define test_hkey_main_Value_A(name, string, full_byte_len) _test_hkey_main_Value_A(__LINE__, name, string, full_byte_len)
157 static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
158 DWORD full_byte_len)
160 DWORD ret, type, cbData;
161 DWORD str_byte_len;
162 BYTE* value;
164 type=0xdeadbeef;
165 cbData=0xdeadbeef;
166 /* When successful RegQueryValueExA() leaves GLE as is,
167 * so we must reset it to detect unimplemented functions.
169 SetLastError(0xdeadbeef);
170 ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
171 GLE = GetLastError();
172 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/1 failed: %d, GLE=%d\n", ret, GLE);
173 /* It is wrong for the Ansi version to not be implemented */
174 ok(GLE == 0xdeadbeef, "RegQueryValueExA set GLE = %u\n", GLE);
175 if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
177 str_byte_len = (string ? lstrlenA(string) : 0) + 1;
178 lok(type == REG_SZ, "RegQueryValueExA/1 returned type %d\n", type);
179 lok(cbData == full_byte_len, "cbData=%d instead of %d or %d\n", cbData, full_byte_len, str_byte_len);
181 value = HeapAlloc(GetProcessHeap(), 0, cbData+1);
182 memset(value, 0xbd, cbData+1);
183 type=0xdeadbeef;
184 ret = RegQueryValueExA(hkey_main, name, NULL, &type, value, &cbData);
185 GLE = GetLastError();
186 lok(ret == ERROR_SUCCESS, "RegQueryValueExA/2 failed: %d, GLE=%d\n", ret, GLE);
187 if (!string)
189 /* When cbData == 0, RegQueryValueExA() should not modify the buffer */
190 lok(*value == 0xbd, "RegQueryValueExA overflowed: cbData=%u *value=%02x\n", cbData, *value);
192 else
194 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
195 debugstr_an((char*)value, cbData), cbData,
196 debugstr_an(string, full_byte_len), full_byte_len);
197 lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
199 HeapFree(GetProcessHeap(), 0, value);
202 #define test_hkey_main_Value_W(name, string, full_byte_len) _test_hkey_main_Value_W(__LINE__, name, string, full_byte_len)
203 static void _test_hkey_main_Value_W(int line, LPCWSTR name, LPCWSTR string,
204 DWORD full_byte_len)
206 DWORD ret, type, cbData;
207 BYTE* value;
209 type=0xdeadbeef;
210 cbData=0xdeadbeef;
211 /* When successful RegQueryValueExW() leaves GLE as is,
212 * so we must reset it to detect unimplemented functions.
214 SetLastError(0xdeadbeef);
215 ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
216 GLE = GetLastError();
217 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/1 failed: %d, GLE=%d\n", ret, GLE);
218 if(GLE == ERROR_CALL_NOT_IMPLEMENTED)
220 win_skip("RegQueryValueExW() is not implemented\n");
221 return;
224 lok(type == REG_SZ, "RegQueryValueExW/1 returned type %d\n", type);
225 lok(cbData == full_byte_len,
226 "cbData=%d instead of %d\n", cbData, full_byte_len);
228 /* Give enough space to overflow by one WCHAR */
229 value = HeapAlloc(GetProcessHeap(), 0, cbData+2);
230 memset(value, 0xbd, cbData+2);
231 type=0xdeadbeef;
232 ret = RegQueryValueExW(hkey_main, name, NULL, &type, value, &cbData);
233 GLE = GetLastError();
234 lok(ret == ERROR_SUCCESS, "RegQueryValueExW/2 failed: %d, GLE=%d\n", ret, GLE);
235 if (string)
237 lok(memcmp(value, string, cbData) == 0, "RegQueryValueExW failed: %s/%d != %s/%d\n",
238 wine_dbgstr_wn((WCHAR*)value, cbData / sizeof(WCHAR)), cbData,
239 wine_dbgstr_wn(string, full_byte_len / sizeof(WCHAR)), full_byte_len);
241 /* This implies that when cbData == 0, RegQueryValueExW() should not modify the buffer */
242 lok(*(value+cbData) == 0xbd, "RegQueryValueExW/2 overflowed at %u: %02x != bd\n", cbData, *(value+cbData));
243 lok(*(value+cbData+1) == 0xbd, "RegQueryValueExW/2 overflowed at %u+1: %02x != bd\n", cbData, *(value+cbData+1));
244 HeapFree(GetProcessHeap(), 0, value);
247 static void test_set_value(void)
249 DWORD ret;
251 static const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
252 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};
253 static const WCHAR emptyW[] = {0};
254 static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
255 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};
256 static const WCHAR substring2W[] = {'T','h','i','s',0};
258 static const char name1A[] = "CleanSingleString";
259 static const char name2A[] = "SomeIntraZeroedString";
260 static const char emptyA[] = "";
261 static const char string1A[] = "ThisNeverBreaks";
262 static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
263 static const char substring2A[] = "This";
265 if (0)
267 /* Crashes on NT4, Windows 2000 and XP SP1 */
268 ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
269 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
272 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
273 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
274 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
275 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
277 /* RegSetValueA ignores the size passed in */
278 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
279 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
280 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
281 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
283 /* stops at first null */
284 ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
285 ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
286 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
287 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
289 /* only REG_SZ is supported on NT*/
290 ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
291 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
293 ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
294 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
296 ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
297 ok(ret == ERROR_INVALID_PARAMETER, "got %d (expected ERROR_INVALID_PARAMETER)\n", ret);
299 /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
300 * Surprisingly enough we're supposed to get zero bytes out of it.
302 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, 0);
303 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
304 test_hkey_main_Value_A(name1A, NULL, 0);
305 test_hkey_main_Value_W(name1W, NULL, 0);
307 /* test RegSetValueExA with an empty string */
308 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)emptyA, sizeof(emptyA));
309 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
310 test_hkey_main_Value_A(name1A, emptyA, sizeof(emptyA));
311 test_hkey_main_Value_W(name1W, emptyW, sizeof(emptyW));
313 /* test RegSetValueExA with off-by-one size */
314 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A)-sizeof(string1A[0]));
315 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
316 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
317 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
319 /* test RegSetValueExA with normal string */
320 ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (const BYTE *)string1A, sizeof(string1A));
321 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
322 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
323 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
325 /* test RegSetValueExA with intrazeroed string */
326 ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)string2A, sizeof(string2A));
327 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%d\n", ret, GetLastError());
328 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
329 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
331 if (0)
333 /* Crashes on NT4, Windows 2000 and XP SP1 */
334 ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
335 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
337 RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (const BYTE *)1, 1);
338 RegSetValueExA(hkey_main, name2A, 0, REG_DWORD, (const BYTE *)1, 1);
341 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
342 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
343 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
344 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
346 ret = RegSetValueW(hkey_main, name1W, REG_SZ, string1W, sizeof(string1W));
347 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
348 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
349 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
351 /* RegSetValueW ignores the size passed in */
352 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
353 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
354 test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
355 test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
357 /* stops at first null */
358 ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
359 ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
360 test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
361 test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
363 /* only REG_SZ is supported */
364 ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
365 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
366 ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
367 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
368 ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
369 ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
371 /* test RegSetValueExW with off-by-one size */
372 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W)-sizeof(string1W[0]));
373 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
374 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
375 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
377 /* test RegSetValueExW with normal string */
378 ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
379 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
380 test_hkey_main_Value_A(name1A, string1A, sizeof(string1A));
381 test_hkey_main_Value_W(name1W, string1W, sizeof(string1W));
383 /* test RegSetValueExW with intrazeroed string */
384 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)string2W, sizeof(string2W));
385 ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());
386 test_hkey_main_Value_A(name2A, string2A, sizeof(string2A));
387 test_hkey_main_Value_W(name2W, string2W, sizeof(string2W));
389 /* test RegSetValueExW with data = 1 */
390 ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (const BYTE *)1, 1);
391 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
392 ret = RegSetValueExW(hkey_main, name2W, 0, REG_DWORD, (const BYTE *)1, 1);
393 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
395 if (pRegGetValueA) /* avoid a crash on Windows 2000 */
397 ret = RegSetValueExW(hkey_main, NULL, 0, REG_SZ, NULL, 4);
398 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
400 ret = RegSetValueExW(hkey_main, NULL, 0, REG_SZ, NULL, 0);
401 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
403 ret = RegSetValueExW(hkey_main, NULL, 0, REG_DWORD, NULL, 4);
404 ok(ret == ERROR_NOACCESS, "RegSetValueExW should have failed with ERROR_NOACCESS: %d, GLE=%d\n", ret, GetLastError());
406 ret = RegSetValueExW(hkey_main, NULL, 0, REG_DWORD, NULL, 0);
407 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
410 /* RegSetKeyValue */
411 if (!pRegSetKeyValueW)
412 win_skip("RegSetKeyValue() is not supported.\n");
413 else
415 static const WCHAR subkeyW[] = {'s','u','b','k','e','y',0};
416 DWORD len, type;
417 HKEY subkey;
419 ret = pRegSetKeyValueW(hkey_main, NULL, name1W, REG_SZ, (const BYTE*)string2W, sizeof(string2W));
420 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
421 test_hkey_main_Value_A(name1A, string2A, sizeof(string2A));
422 test_hkey_main_Value_W(name1W, string2W, sizeof(string2W));
424 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_SZ, string1W, sizeof(string1W));
425 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
427 ret = RegOpenKeyExW(hkey_main, subkeyW, 0, KEY_QUERY_VALUE, &subkey);
428 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
429 type = len = 0;
430 ret = RegQueryValueExW(subkey, name1W, 0, &type, NULL, &len);
431 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
432 ok(len == sizeof(string1W), "got %d\n", len);
433 ok(type == REG_SZ, "got type %d\n", type);
435 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_SZ, NULL, 0);
436 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
438 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_SZ, NULL, 4);
439 ok(ret == ERROR_NOACCESS, "got %d\n", ret);
441 ret = pRegSetKeyValueW(hkey_main, subkeyW, name1W, REG_DWORD, NULL, 4);
442 ok(ret == ERROR_NOACCESS, "got %d\n", ret);
444 RegCloseKey(subkey);
448 static void create_test_entries(void)
450 static const DWORD qw[2] = { 0x12345678, 0x87654321 };
452 SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
453 SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
455 ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
456 "RegSetValueExA failed\n");
457 ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (const BYTE *)sTestpath1, strlen(sTestpath1)+1),
458 "RegSetValueExA failed\n");
459 ok(!RegSetValueExA(hkey_main,"TP1_ZB_SZ",0,REG_SZ, (const BYTE *)"", 0),
460 "RegSetValueExA failed\n");
461 ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (const BYTE *)sTestpath2, strlen(sTestpath2)+1),
462 "RegSetValueExA failed\n");
463 ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (const BYTE *)qw, 4),
464 "RegSetValueExA failed\n");
465 ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (const BYTE *)qw, 4),
466 "RegSetValueExA failed\n");
467 ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (const BYTE *)qw, 8),
468 "RegSetValueExA failed\n");
471 static void test_enum_value(void)
473 DWORD res;
474 HKEY test_key;
475 char value[20], data[20];
476 WCHAR valueW[20], dataW[20];
477 DWORD val_count, data_count, type;
478 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
479 static const WCHAR testW[] = {'T','e','s','t',0};
480 static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
482 /* create the working key for new 'Test' value */
483 res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
484 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
486 /* check NULL data with zero length */
487 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
488 if (GetVersion() & 0x80000000)
489 ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
490 else
491 ok( !res, "RegSetValueExA returned %d\n", res );
492 res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
493 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
494 res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
495 ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %d\n", res );
497 /* test reading the value and data without setting them */
498 val_count = 20;
499 data_count = 20;
500 type = 1234;
501 strcpy( value, "xxxxxxxxxx" );
502 strcpy( data, "xxxxxxxxxx" );
503 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
504 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
505 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
506 ok( data_count == 0, "data_count set to %d instead of 0\n", data_count );
507 ok( type == REG_BINARY, "type %d is not REG_BINARY\n", type );
508 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
509 ok( !strcmp( data, "xxxxxxxxxx" ), "data is '%s' instead of xxxxxxxxxx\n", data );
511 val_count = 20;
512 data_count = 20;
513 type = 1234;
514 memcpy( valueW, xxxW, sizeof(xxxW) );
515 memcpy( dataW, xxxW, sizeof(xxxW) );
516 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
517 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
518 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
519 ok( data_count == 0, "data_count set to %d instead of 0\n", data_count );
520 ok( type == REG_BINARY, "type %d is not REG_BINARY\n", type );
521 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
522 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data is not 'xxxxxxxxxx'\n" );
524 res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (const BYTE *)"foobar", 7 );
525 ok( res == 0, "RegSetValueExA failed error %d\n", res );
527 /* overflow both name and data */
528 val_count = 2;
529 data_count = 2;
530 type = 1234;
531 strcpy( value, "xxxxxxxxxx" );
532 strcpy( data, "xxxxxxxxxx" );
533 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
534 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
535 ok( val_count == 2, "val_count set to %d\n", val_count );
536 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
537 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
538 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
539 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
541 /* overflow name */
542 val_count = 3;
543 data_count = 20;
544 type = 1234;
545 strcpy( value, "xxxxxxxxxx" );
546 strcpy( data, "xxxxxxxxxx" );
547 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
548 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
549 ok( val_count == 3, "val_count set to %d\n", val_count );
550 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
551 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
552 /* v5.1.2600.0 (XP Home and Professional) does not touch value or data in this case */
553 ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
554 "value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
555 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
556 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
558 /* overflow empty name */
559 val_count = 0;
560 data_count = 20;
561 type = 1234;
562 strcpy( value, "xxxxxxxxxx" );
563 strcpy( data, "xxxxxxxxxx" );
564 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
565 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
566 ok( val_count == 0, "val_count set to %d\n", val_count );
567 ok( data_count == 7 || broken( data_count == 8 ), "data_count set to %d instead of 7\n", data_count );
568 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
569 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
570 /* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
571 ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ) || broken( !strcmp( data, "xxxxxxxx" ) && data_count == 8 ),
572 "data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
574 /* overflow data */
575 val_count = 20;
576 data_count = 2;
577 type = 1234;
578 strcpy( value, "xxxxxxxxxx" );
579 strcpy( data, "xxxxxxxxxx" );
580 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
581 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
582 ok( val_count == 20, "val_count set to %d\n", val_count );
583 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
584 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
585 ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
586 ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
588 /* no overflow */
589 val_count = 20;
590 data_count = 20;
591 type = 1234;
592 strcpy( value, "xxxxxxxxxx" );
593 strcpy( data, "xxxxxxxxxx" );
594 res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
595 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
596 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
597 ok( data_count == 7, "data_count set to %d instead of 7\n", data_count );
598 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
599 ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
600 ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
602 if (pRegGetValueA) /* avoid a crash on Windows 2000 */
604 /* no value and no val_count parameter */
605 data_count = 20;
606 type = 1234;
607 strcpy( data, "xxxxxxxxxx" );
608 res = RegEnumValueA( test_key, 0, NULL, NULL, NULL, &type, (BYTE*)data, &data_count );
609 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
611 /* no value parameter */
612 val_count = 20;
613 data_count = 20;
614 type = 1234;
615 strcpy( data, "xxxxxxxxxx" );
616 res = RegEnumValueA( test_key, 0, NULL, &val_count, NULL, &type, (BYTE*)data, &data_count );
617 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
619 /* no val_count parameter */
620 data_count = 20;
621 type = 1234;
622 strcpy( value, "xxxxxxxxxx" );
623 strcpy( data, "xxxxxxxxxx" );
624 res = RegEnumValueA( test_key, 0, value, NULL, NULL, &type, (BYTE*)data, &data_count );
625 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
628 /* Unicode tests */
630 SetLastError(0xdeadbeef);
631 res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
632 if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
634 win_skip("RegSetValueExW is not implemented\n");
635 goto cleanup;
637 ok( res == 0, "RegSetValueExW failed error %d\n", res );
639 /* overflow both name and data */
640 val_count = 2;
641 data_count = 2;
642 type = 1234;
643 memcpy( valueW, xxxW, sizeof(xxxW) );
644 memcpy( dataW, xxxW, sizeof(xxxW) );
645 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
646 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
647 ok( val_count == 2, "val_count set to %d\n", val_count );
648 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
649 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
650 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
651 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
653 /* overflow name */
654 val_count = 3;
655 data_count = 20;
656 type = 1234;
657 memcpy( valueW, xxxW, sizeof(xxxW) );
658 memcpy( dataW, xxxW, sizeof(xxxW) );
659 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
660 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
661 ok( val_count == 3, "val_count set to %d\n", val_count );
662 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
663 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
664 ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
665 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
667 /* overflow data */
668 val_count = 20;
669 data_count = 2;
670 type = 1234;
671 memcpy( valueW, xxxW, sizeof(xxxW) );
672 memcpy( dataW, xxxW, sizeof(xxxW) );
673 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
674 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", res );
675 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
676 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
677 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
678 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
679 ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
681 /* no overflow */
682 val_count = 20;
683 data_count = 20;
684 type = 1234;
685 memcpy( valueW, xxxW, sizeof(xxxW) );
686 memcpy( dataW, xxxW, sizeof(xxxW) );
687 res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
688 ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res );
689 ok( val_count == 4, "val_count set to %d instead of 4\n", val_count );
690 ok( data_count == 7*sizeof(WCHAR), "data_count set to %d instead of 7*sizeof(WCHAR)\n", data_count );
691 ok( type == REG_SZ, "type %d is not REG_SZ\n", type );
692 ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
693 ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
695 if (pRegGetValueA) /* avoid a crash on Windows 2000 */
697 /* no valueW and no val_count parameter */
698 data_count = 20;
699 type = 1234;
700 memcpy( dataW, xxxW, sizeof(xxxW) );
701 res = RegEnumValueW( test_key, 0, NULL, NULL, NULL, &type, (BYTE*)dataW, &data_count );
702 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
704 /* no valueW parameter */
705 val_count = 20;
706 data_count = 20;
707 type = 1234;
708 memcpy( dataW, xxxW, sizeof(xxxW) );
709 res = RegEnumValueW( test_key, 0, NULL, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
710 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
712 /* no val_count parameter */
713 data_count = 20;
714 type = 1234;
715 memcpy( valueW, xxxW, sizeof(xxxW) );
716 memcpy( dataW, xxxW, sizeof(xxxW) );
717 res = RegEnumValueW( test_key, 0, valueW, NULL, NULL, &type, (BYTE*)dataW, &data_count );
718 ok( res == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", res );
721 cleanup:
722 RegDeleteKeyA(test_key, "");
723 RegCloseKey(test_key);
726 static void test_query_value_ex(void)
728 DWORD ret, size, type;
729 BYTE buffer[10];
731 size = sizeof(buffer);
732 ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
733 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
734 ok(size == strlen(sTestpath1) + 1, "(%d,%d)\n", (DWORD)strlen(sTestpath1) + 1, size);
735 ok(type == REG_SZ, "type %d is not REG_SZ\n", type);
737 type = 0xdeadbeef;
738 size = 0xdeadbeef;
739 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, NULL, &size);
740 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
741 ok(size == 0, "size should have been set to 0 instead of %d\n", size);
743 size = sizeof(buffer);
744 ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Nonexistent Value", NULL, &type, buffer, &size);
745 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
746 ok(size == sizeof(buffer), "size shouldn't have been changed to %d\n", size);
748 size = 4;
749 ret = RegQueryValueExA(hkey_main, "BIN32", NULL, &size, buffer, &size);
750 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
753 static void test_get_value(void)
755 DWORD ret;
756 DWORD size;
757 DWORD type;
758 DWORD dw, qw[2];
759 CHAR buf[80];
760 CHAR expanded[] = "bar\\subdir1";
761 CHAR expanded2[] = "ImARatherLongButIndeedNeededString\\subdir1";
763 if(!pRegGetValueA)
765 win_skip("RegGetValue not available on this platform\n");
766 return;
769 /* Invalid parameter */
770 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, NULL);
771 ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
773 /* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
774 size = type = dw = 0xdeadbeef;
775 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
776 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
777 ok(size == 4, "size=%d\n", size);
778 ok(type == REG_DWORD, "type=%d\n", type);
779 ok(dw == 0x12345678, "dw=%d\n", dw);
781 /* Check RRF_SUBKEY_WOW64*KEY validation on a case without a subkey */
782 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6464KEY | RRF_SUBKEY_WOW6432KEY, NULL, NULL, NULL);
783 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS), /* Before Win10 */
784 "ret=%d\n", ret);
785 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6464KEY, NULL, NULL, NULL);
786 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
787 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6432KEY, NULL, NULL, NULL);
788 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
790 /* Query by subkey-name */
791 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
792 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
794 /* Check RRF_SUBKEY_WOW64*KEY validation on a case with a subkey */
795 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6464KEY | RRF_SUBKEY_WOW6432KEY, NULL, NULL, NULL);
796 ok(ret == ERROR_INVALID_PARAMETER || broken(ret == ERROR_SUCCESS), /* Before Win10 */
797 "ret=%d\n", ret);
798 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6464KEY, NULL, NULL, NULL);
799 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
800 ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6432KEY, NULL, NULL, NULL);
801 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
803 /* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
804 size = type = dw = 0xdeadbeef;
805 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
806 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
807 /* Although the function failed all values are retrieved */
808 ok(size == 4, "size=%d\n", size);
809 ok(type == REG_DWORD, "type=%d\n", type);
810 ok(dw == 0x12345678, "dw=%d\n", dw);
812 /* Test RRF_ZEROONFAILURE */
813 type = dw = 0xdeadbeef; size = 4;
814 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
815 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
816 /* Again all values are retrieved ... */
817 ok(size == 4, "size=%d\n", size);
818 ok(type == REG_DWORD, "type=%d\n", type);
819 /* ... except the buffer, which is zeroed out */
820 ok(dw == 0, "dw=%d\n", dw);
822 /* Test RRF_ZEROONFAILURE with a NULL buffer... */
823 type = size = 0xbadbeef;
824 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, NULL, &size);
825 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
826 ok(size == 4, "size=%d\n", size);
827 ok(type == REG_DWORD, "type=%d\n", type);
829 /* Query REG_DWORD using RRF_RT_DWORD (ok) */
830 size = type = dw = 0xdeadbeef;
831 ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
832 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
833 ok(size == 4, "size=%d\n", size);
834 ok(type == REG_DWORD, "type=%d\n", type);
835 ok(dw == 0x12345678, "dw=%d\n", dw);
837 /* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
838 size = type = dw = 0xdeadbeef;
839 ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
840 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
841 ok(size == 4, "size=%d\n", size);
842 ok(type == REG_BINARY, "type=%d\n", type);
843 ok(dw == 0x12345678, "dw=%d\n", dw);
845 /* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
846 qw[0] = qw[1] = size = type = 0xdeadbeef;
847 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
848 ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%d\n", ret);
849 ok(size == 8, "size=%d\n", size);
850 ok(type == REG_BINARY, "type=%d\n", type);
851 ok(qw[0] == 0x12345678 &&
852 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
854 /* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
855 type = dw = 0xdeadbeef; size = 4;
856 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
857 ok(ret == ERROR_MORE_DATA, "ret=%d\n", ret);
858 ok(dw == 0xdeadbeef, "dw=%d\n", dw);
859 ok(size == 8, "size=%d\n", size);
861 /* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
862 qw[0] = qw[1] = size = type = 0xdeadbeef;
863 ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
864 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
865 ok(size == 8, "size=%d\n", size);
866 ok(type == REG_BINARY, "type=%d\n", type);
867 ok(qw[0] == 0x12345678 &&
868 qw[1] == 0x87654321, "qw={%d,%d}\n", qw[0], qw[1]);
870 /* Query REG_SZ using RRF_RT_REG_SZ (ok) */
871 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
872 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
873 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
874 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
875 ok(type == REG_SZ, "type=%d\n", type);
876 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
878 /* Query REG_SZ using RRF_RT_REG_SZ and no buffer (ok) */
879 type = 0xdeadbeef; size = 0;
880 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, NULL, &size);
881 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
882 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
883 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
884 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
885 ok(type == REG_SZ, "type=%d\n", type);
887 /* Query REG_SZ using RRF_RT_REG_SZ on a zero-byte value (ok) */
888 strcpy(buf, sTestpath1);
889 type = 0xdeadbeef;
890 size = sizeof(buf);
891 ret = pRegGetValueA(hkey_main, NULL, "TP1_ZB_SZ", RRF_RT_REG_SZ, &type, buf, &size);
892 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
893 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
894 ok(size == 0 ||
895 size == 1, /* win2k3 */
896 "size=%d\n", size);
897 ok(type == REG_SZ, "type=%d\n", type);
898 ok(!strcmp(sTestpath1, buf) ||
899 !strcmp(buf, ""),
900 "Expected \"%s\" or \"\", got \"%s\"\n", sTestpath1, buf);
902 /* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
903 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
904 ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
905 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
906 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
907 ok(type == REG_SZ, "type=%d\n", type);
908 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
910 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ and no buffer (ok, expands) */
911 size = 0;
912 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, NULL, NULL, &size);
913 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
914 ok((size == strlen(expanded2)+1) || /* win2k3 SP1 */
915 (size == strlen(expanded2)+2) || /* win2k3 SP2 */
916 (size == strlen(sTestpath2)+1),
917 "strlen(expanded2)=%d, strlen(sTestpath2)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
919 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
920 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
921 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
922 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
923 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
924 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
925 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
926 ok(type == REG_SZ, "type=%d\n", type);
927 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
929 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands a lot) */
930 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
931 ret = pRegGetValueA(hkey_main, NULL, "TP2_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
932 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
933 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath2 length + 1 here. */
934 ok(size == strlen(expanded2)+1 || broken(size == strlen(sTestpath2)+1),
935 "strlen(expanded2)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded2), lstrlenA(sTestpath2), size);
936 ok(type == REG_SZ, "type=%d\n", type);
937 ok(!strcmp(expanded2, buf), "expanded2=\"%s\" buf=\"%s\"\n", expanded2, buf);
939 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
940 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
941 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
942 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
943 ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
944 ok(type == REG_EXPAND_SZ, "type=%d\n", type);
945 ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
947 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND and no buffer (ok, doesn't expand) */
948 size = 0xbadbeef;
949 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, NULL, NULL, &size);
950 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
951 /* v5.2.3790.1830 (2003 SP1) returns sTestpath1 length + 2 here. */
952 ok(size == strlen(sTestpath1)+1 || broken(size == strlen(sTestpath1)+2),
953 "strlen(sTestpath1)=%d size=%d\n", lstrlenA(sTestpath1), size);
955 /* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
956 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
957 ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
959 /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
960 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
961 /* before win8: ERROR_INVALID_PARAMETER, win8: ERROR_UNSUPPORTED_TYPE */
962 ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_UNSUPPORTED_TYPE, "ret=%d\n", ret);
964 /* Query REG_EXPAND_SZ using RRF_RT_ANY */
965 buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
966 ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_ANY, &type, buf, &size);
967 ok(ret == ERROR_SUCCESS, "ret=%d\n", ret);
968 /* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
969 ok(size == strlen(expanded)+1 || broken(size == strlen(sTestpath1)+1),
970 "strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%d\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
971 ok(type == REG_SZ, "type=%d\n", type);
972 ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
975 static void test_reg_open_key(void)
977 DWORD ret = 0;
978 HKEY hkResult = NULL;
979 HKEY hkPreserve = NULL;
980 HKEY hkRoot64 = NULL;
981 HKEY hkRoot32 = NULL;
982 BOOL bRet;
983 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
984 PSID world_sid;
985 EXPLICIT_ACCESSA access;
986 PACL key_acl;
987 SECURITY_DESCRIPTOR *sd;
989 /* successful open */
990 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
991 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
992 ok(hkResult != NULL, "expected hkResult != NULL\n");
993 hkPreserve = hkResult;
995 /* open same key twice */
996 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
997 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
998 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
999 ok(hkResult != NULL, "hkResult != NULL\n");
1000 RegCloseKey(hkResult);
1002 /* trailing slashes */
1003 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test\\\\", &hkResult);
1004 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1005 RegCloseKey(hkResult);
1007 /* open nonexistent key
1008 * check that hkResult is set to NULL
1010 hkResult = hkPreserve;
1011 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
1012 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1013 ok(hkResult == NULL, "expected hkResult == NULL\n");
1015 /* open the same nonexistent key again to make sure the key wasn't created */
1016 hkResult = hkPreserve;
1017 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
1018 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
1019 ok(hkResult == NULL, "expected hkResult == NULL\n");
1021 /* send in NULL lpSubKey
1022 * check that hkResult receives the value of hKey
1024 hkResult = hkPreserve;
1025 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
1026 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1027 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
1029 /* send empty-string in lpSubKey */
1030 hkResult = hkPreserve;
1031 ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
1032 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1033 ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
1035 /* send in NULL lpSubKey and NULL hKey
1036 * hkResult is set to NULL
1038 hkResult = hkPreserve;
1039 ret = RegOpenKeyA(NULL, NULL, &hkResult);
1040 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1041 ok(hkResult == NULL, "expected hkResult == NULL\n");
1043 /* only send NULL hKey
1044 * the value of hkResult remains unchanged
1046 hkResult = hkPreserve;
1047 ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
1048 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1049 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1050 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
1052 /* send in NULL hkResult */
1053 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
1054 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1056 ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, NULL);
1057 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1059 ret = RegOpenKeyA(NULL, NULL, NULL);
1060 ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1062 /* beginning backslash character */
1063 ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
1064 ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
1065 broken(ret == ERROR_SUCCESS), /* wow64 */
1066 "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
1067 if (!ret) RegCloseKey(hkResult);
1069 hkResult = NULL;
1070 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\clsid", 0, KEY_QUERY_VALUE, &hkResult);
1071 ok(ret == ERROR_SUCCESS || /* 2k/XP */
1072 ret == ERROR_BAD_PATHNAME, /* NT */
1073 "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
1074 RegCloseKey(hkResult);
1076 /* NULL or empty subkey of special root */
1077 hkResult = NULL;
1078 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, NULL, 0, KEY_QUERY_VALUE, &hkResult);
1079 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1080 ok(hkResult == HKEY_CLASSES_ROOT, "expected hkResult == HKEY_CLASSES_ROOT\n");
1082 hkResult = NULL;
1083 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "", 0, KEY_QUERY_VALUE, &hkResult);
1084 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1085 ok(hkResult == HKEY_CLASSES_ROOT, "expected hkResult == HKEY_CLASSES_ROOT\n");
1087 hkResult = NULL;
1088 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\", 0, KEY_QUERY_VALUE, &hkResult);
1089 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1090 ok(hkResult != HKEY_CLASSES_ROOT, "expected hkResult to be a new key\n");
1091 ok(!RegCloseKey(hkResult), "got invalid hkey\n");
1093 /* empty subkey of existing handle */
1094 hkResult = hkPreserve;
1095 ret = RegOpenKeyExA(hkPreserve, "", 0, KEY_QUERY_VALUE, &hkResult);
1096 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1097 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
1098 ok(!RegCloseKey(hkResult), "got invalid hkey\n");
1100 /* NULL subkey of existing handle */
1101 hkResult = hkPreserve;
1102 ret = RegOpenKeyExA(hkPreserve, NULL, 0, KEY_QUERY_VALUE, &hkResult);
1103 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1104 ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
1105 ok(!RegCloseKey(hkResult), "got invalid hkey\n");
1107 /* empty subkey of NULL */
1108 hkResult = hkPreserve;
1109 ret = RegOpenKeyExW(NULL, L"", 0, KEY_QUERY_VALUE, &hkResult);
1110 ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret);
1111 ok(hkResult == NULL || broken(hkResult == hkPreserve /* Windows XP */), "expected hkResult == NULL\n");
1113 hkResult = hkPreserve;
1114 ret = RegOpenKeyExA(NULL, "", 0, KEY_QUERY_VALUE, &hkResult);
1115 ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret);
1116 ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
1118 RegCloseKey(hkPreserve);
1120 /* WOW64 flags */
1121 hkResult = NULL;
1122 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
1123 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1124 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1125 RegCloseKey(hkResult);
1127 hkResult = NULL;
1128 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_64KEY, &hkResult);
1129 ok((ret == ERROR_SUCCESS && hkResult != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1130 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1131 RegCloseKey(hkResult);
1133 /* check special HKEYs on 64bit
1134 * only the lower 4 bytes of the supplied key are used
1136 if (ptr_size == 64)
1138 /* HKEY_CURRENT_USER */
1139 ret = RegOpenKeyA(UlongToHandle(HandleToUlong(HKEY_CURRENT_USER)), "Software", &hkResult);
1140 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1141 ok(hkResult != NULL, "expected hkResult != NULL\n");
1142 RegCloseKey(hkResult);
1144 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)1 << 32), "Software", &hkResult);
1145 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1146 ok(hkResult != NULL, "expected hkResult != NULL\n");
1147 RegCloseKey(hkResult);
1149 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)0xdeadbeef << 32), "Software", &hkResult);
1150 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1151 ok(hkResult != NULL, "expected hkResult != NULL\n");
1152 RegCloseKey(hkResult);
1154 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_CURRENT_USER) | (ULONG64)0xffffffff << 32), "Software", &hkResult);
1155 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1156 ok(hkResult != NULL, "expected hkResult != NULL\n");
1157 RegCloseKey(hkResult);
1159 /* HKEY_LOCAL_MACHINE */
1160 ret = RegOpenKeyA((HKEY)(HandleToUlong(HKEY_LOCAL_MACHINE) | (ULONG64)0xdeadbeef << 32), "Software", &hkResult);
1161 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1162 ok(hkResult != NULL, "expected hkResult != NULL\n");
1163 RegCloseKey(hkResult);
1166 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1167 * the registry access check is performed correctly. Redirection isn't
1168 * being tested, so the tests don't care about whether the process is
1169 * running under WOW64. */
1170 if (!pIsWow64Process)
1172 win_skip("WOW64 flags are not recognized\n");
1173 return;
1176 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1177 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1178 if (limited_user)
1179 ok(ret == ERROR_ACCESS_DENIED && hkRoot32 == NULL,
1180 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1181 else
1182 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1183 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1185 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1186 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1187 if (limited_user)
1188 ok(ret == ERROR_ACCESS_DENIED && hkRoot64 == NULL,
1189 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1190 else
1191 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1192 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1194 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1195 0, 0, 0, 0, 0, 0, 0, &world_sid);
1196 ok(bRet == TRUE,
1197 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1199 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1200 access.grfAccessMode = SET_ACCESS;
1201 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1202 access.Trustee.pMultipleTrustee = NULL;
1203 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1204 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1205 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1206 access.Trustee.ptstrName = (char *)world_sid;
1208 ret = SetEntriesInAclA(1, &access, NULL, &key_acl);
1209 ok(ret == ERROR_SUCCESS,
1210 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", ret, GetLastError());
1212 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1213 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1214 ok(bRet == TRUE,
1215 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1217 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1218 ok(bRet == TRUE,
1219 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1221 if (limited_user)
1223 skip("not enough privileges to modify HKLM\n");
1225 else
1227 LONG error;
1229 error = RegSetKeySecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1230 ok(error == ERROR_SUCCESS,
1231 "Expected RegSetKeySecurity to return success, got error %u\n", error);
1233 error = RegSetKeySecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1234 ok(error == ERROR_SUCCESS,
1235 "Expected RegSetKeySecurity to return success, got error %u\n", error);
1237 hkResult = NULL;
1238 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_64KEY | KEY_READ, &hkResult);
1239 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1240 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1241 RegCloseKey(hkResult);
1243 hkResult = NULL;
1244 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, KEY_WOW64_32KEY | KEY_READ, &hkResult);
1245 ok(ret == ERROR_SUCCESS && hkResult != NULL,
1246 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1247 RegCloseKey(hkResult);
1250 HeapFree(GetProcessHeap(), 0, sd);
1251 LocalFree(key_acl);
1252 FreeSid(world_sid);
1253 RegDeleteKeyA(hkRoot64, "");
1254 RegCloseKey(hkRoot64);
1255 RegDeleteKeyA(hkRoot32, "");
1256 RegCloseKey(hkRoot32);
1259 static void test_reg_create_key(void)
1261 LONG ret;
1262 HKEY hkey1, hkey2;
1263 HKEY hkRoot64 = NULL;
1264 HKEY hkRoot32 = NULL;
1265 DWORD dwRet;
1266 BOOL bRet;
1267 SID_IDENTIFIER_AUTHORITY sid_authority = {SECURITY_WORLD_SID_AUTHORITY};
1268 PSID world_sid;
1269 EXPLICIT_ACCESSA access;
1270 PACL key_acl;
1271 SECURITY_DESCRIPTOR *sd;
1273 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1274 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1275 /* should succeed: all versions of Windows ignore the access rights
1276 * to the parent handle */
1277 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
1278 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1280 /* clean up */
1281 RegDeleteKeyA(hkey2, "");
1282 RegDeleteKeyA(hkey1, "");
1283 RegCloseKey(hkey2);
1284 RegCloseKey(hkey1);
1286 /* test creation of volatile keys */
1287 ret = RegCreateKeyExA(hkey_main, "Volatile", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey1, NULL);
1288 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1289 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1290 ok(ret == ERROR_CHILD_MUST_BE_VOLATILE, "RegCreateKeyExA failed with error %d\n", ret);
1291 if (!ret) RegCloseKey( hkey2 );
1292 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1293 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1294 RegCloseKey(hkey2);
1295 /* should succeed if the key already exists */
1296 ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey2, NULL);
1297 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1299 /* clean up */
1300 RegDeleteKeyA(hkey2, "");
1301 RegDeleteKeyA(hkey1, "");
1302 RegCloseKey(hkey2);
1303 RegCloseKey(hkey1);
1305 /* beginning backslash character */
1306 ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1307 if (!(GetVersion() & 0x80000000))
1308 ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %d\n", ret);
1309 else {
1310 ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
1311 RegDeleteKeyA(hkey1, "");
1312 RegCloseKey(hkey1);
1315 /* trailing backslash characters */
1316 ret = RegCreateKeyExA(hkey_main, "Subkey4\\\\", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
1317 ok(ret == ERROR_SUCCESS, "RegCreateKeyExA failed with error %d\n", ret);
1318 RegDeleteKeyA(hkey1, "");
1319 RegCloseKey(hkey1);
1321 /* WOW64 flags - open an existing key */
1322 hkey1 = NULL;
1323 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &hkey1, NULL);
1324 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1325 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1326 RegCloseKey(hkey1);
1328 hkey1 = NULL;
1329 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0, KEY_READ|KEY_WOW64_64KEY, NULL, &hkey1, NULL);
1330 ok((ret == ERROR_SUCCESS && hkey1 != NULL) || broken(ret == ERROR_ACCESS_DENIED /* NT4, win2k */),
1331 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1332 RegCloseKey(hkey1);
1334 /* Try using WOW64 flags when opening a key with a DACL set to verify that
1335 * the registry access check is performed correctly. Redirection isn't
1336 * being tested, so the tests don't care about whether the process is
1337 * running under WOW64. */
1338 if (!pIsWow64Process)
1340 win_skip("WOW64 flags are not recognized\n");
1341 return;
1344 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1345 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &hkRoot32, NULL);
1346 if (limited_user)
1347 ok(ret == ERROR_ACCESS_DENIED && hkRoot32 == NULL,
1348 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1349 else
1350 ok(ret == ERROR_SUCCESS && hkRoot32 != NULL,
1351 "RegCreateKeyEx with KEY_WOW64_32KEY failed (err=%d)\n", ret);
1353 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1354 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &hkRoot64, NULL);
1355 if (limited_user)
1356 ok(ret == ERROR_ACCESS_DENIED && hkRoot64 == NULL,
1357 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1358 else
1359 ok(ret == ERROR_SUCCESS && hkRoot64 != NULL,
1360 "RegCreateKeyEx with KEY_WOW64_64KEY failed (err=%d)\n", ret);
1362 bRet = AllocateAndInitializeSid(&sid_authority, 1, SECURITY_WORLD_RID,
1363 0, 0, 0, 0, 0, 0, 0, &world_sid);
1364 ok(bRet == TRUE,
1365 "Expected AllocateAndInitializeSid to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1367 access.grfAccessPermissions = GENERIC_ALL | STANDARD_RIGHTS_ALL;
1368 access.grfAccessMode = SET_ACCESS;
1369 access.grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
1370 access.Trustee.pMultipleTrustee = NULL;
1371 access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1372 access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
1373 access.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
1374 access.Trustee.ptstrName = (char *)world_sid;
1376 dwRet = SetEntriesInAclA(1, &access, NULL, &key_acl);
1377 ok(dwRet == ERROR_SUCCESS,
1378 "Expected SetEntriesInAclA to return ERROR_SUCCESS, got %u, last error %u\n", dwRet, GetLastError());
1380 sd = HeapAlloc(GetProcessHeap(), 0, SECURITY_DESCRIPTOR_MIN_LENGTH);
1381 bRet = InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
1382 ok(bRet == TRUE,
1383 "Expected InitializeSecurityDescriptor to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1385 bRet = SetSecurityDescriptorDacl(sd, TRUE, key_acl, FALSE);
1386 ok(bRet == TRUE,
1387 "Expected SetSecurityDescriptorDacl to return TRUE, got %d, last error %u\n", bRet, GetLastError());
1389 if (limited_user)
1391 skip("not enough privileges to modify HKLM\n");
1393 else
1395 ret = RegSetKeySecurity(hkRoot64, DACL_SECURITY_INFORMATION, sd);
1396 ok(ret == ERROR_SUCCESS,
1397 "Expected RegSetKeySecurity to return success, got error %u\n", ret);
1399 ret = RegSetKeySecurity(hkRoot32, DACL_SECURITY_INFORMATION, sd);
1400 ok(ret == ERROR_SUCCESS,
1401 "Expected RegSetKeySecurity to return success, got error %u\n", ret);
1403 hkey1 = NULL;
1404 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1405 KEY_WOW64_64KEY | KEY_READ, NULL, &hkey1, NULL);
1406 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1407 "RegOpenKeyEx with KEY_WOW64_64KEY failed (err=%u)\n", ret);
1408 RegCloseKey(hkey1);
1410 hkey1 = NULL;
1411 ret = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
1412 KEY_WOW64_32KEY | KEY_READ, NULL, &hkey1, NULL);
1413 ok(ret == ERROR_SUCCESS && hkey1 != NULL,
1414 "RegOpenKeyEx with KEY_WOW64_32KEY failed (err=%u)\n", ret);
1415 RegCloseKey(hkey1);
1418 HeapFree(GetProcessHeap(), 0, sd);
1419 LocalFree(key_acl);
1420 FreeSid(world_sid);
1421 RegDeleteKeyA(hkRoot64, "");
1422 RegCloseKey(hkRoot64);
1423 RegDeleteKeyA(hkRoot32, "");
1424 RegCloseKey(hkRoot32);
1427 static void test_reg_close_key(void)
1429 DWORD ret = 0;
1430 HKEY hkHandle;
1432 /* successfully close key
1433 * hkHandle remains changed after call to RegCloseKey
1435 ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
1436 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1437 ret = RegCloseKey(hkHandle);
1438 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1440 /* try to close the key twice */
1441 ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
1442 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
1443 "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %d\n", ret);
1445 /* try to close a NULL handle */
1446 ret = RegCloseKey(NULL);
1447 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
1448 "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1450 /* Check to see if we didn't potentially close our main handle, which could happen on win98 as
1451 * win98 doesn't give a new handle when the same key is opened.
1452 * Not re-opening will make some next tests fail.
1454 if (hkey_main == hkHandle)
1456 trace("The main handle is most likely closed, so re-opening\n");
1457 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main );
1461 static void test_reg_delete_key(void)
1463 DWORD ret;
1464 HKEY key;
1466 ret = RegDeleteKeyA(hkey_main, NULL);
1468 /* There is a bug in NT4 and W2K that doesn't check if the subkey is NULL. If
1469 * there are also no subkeys available it will delete the key pointed to by hkey_main.
1470 * Not re-creating will make some next tests fail.
1472 if (ret == ERROR_SUCCESS)
1474 trace("We are probably running on NT4 or W2K as the main key is deleted,"
1475 " re-creating the main key\n");
1476 setup_main_key();
1478 else
1479 ok(ret == ERROR_INVALID_PARAMETER ||
1480 ret == ERROR_ACCESS_DENIED ||
1481 ret == ERROR_BADKEY, /* Win95 */
1482 "ret=%d\n", ret);
1484 ret = RegCreateKeyA(hkey_main, "deleteme", &key);
1485 ok(ret == ERROR_SUCCESS, "Could not create key, got %d\n", ret);
1486 ret = RegDeleteKeyA(key, "");
1487 ok(ret == ERROR_SUCCESS, "RegDeleteKeyA failed, got %d\n", ret);
1488 RegCloseKey(key);
1489 ret = RegOpenKeyA(hkey_main, "deleteme", &key);
1490 ok(ret == ERROR_FILE_NOT_FOUND, "Key was not deleted, got %d\n", ret);
1491 RegCloseKey(key);
1494 static BOOL set_privileges(LPCSTR privilege, BOOL set)
1496 TOKEN_PRIVILEGES tp;
1497 HANDLE hToken;
1498 LUID luid;
1500 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
1501 return FALSE;
1503 if(!LookupPrivilegeValueA(NULL, privilege, &luid))
1505 CloseHandle(hToken);
1506 return FALSE;
1509 tp.PrivilegeCount = 1;
1510 tp.Privileges[0].Luid = luid;
1512 if (set)
1513 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1514 else
1515 tp.Privileges[0].Attributes = 0;
1517 AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
1518 if (GetLastError() != ERROR_SUCCESS)
1520 CloseHandle(hToken);
1521 return FALSE;
1524 CloseHandle(hToken);
1525 return TRUE;
1528 static void test_reg_save_key(void)
1530 DWORD ret;
1532 if (!set_privileges(SE_BACKUP_NAME, TRUE) ||
1533 !set_privileges(SE_RESTORE_NAME, FALSE))
1535 win_skip("Failed to set SE_BACKUP_NAME privileges, skipping tests\n");
1536 return;
1539 ret = RegSaveKeyA(hkey_main, "saved_key", NULL);
1540 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1542 set_privileges(SE_BACKUP_NAME, FALSE);
1545 static void test_reg_load_key(void)
1547 DWORD ret;
1548 HKEY hkHandle;
1550 if (!set_privileges(SE_RESTORE_NAME, TRUE) ||
1551 !set_privileges(SE_BACKUP_NAME, FALSE))
1553 win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n");
1554 return;
1557 ret = RegLoadKeyA(HKEY_LOCAL_MACHINE, "Test", "saved_key");
1558 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1560 set_privileges(SE_RESTORE_NAME, FALSE);
1562 ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
1563 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1565 RegCloseKey(hkHandle);
1568 static void test_reg_unload_key(void)
1570 UNICODE_STRING key_name;
1571 OBJECT_ATTRIBUTES attr;
1572 NTSTATUS status;
1573 DWORD ret;
1574 HKEY key;
1576 if (!set_privileges(SE_RESTORE_NAME, TRUE) ||
1577 !set_privileges(SE_BACKUP_NAME, FALSE))
1579 win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n");
1580 return;
1583 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Test", 0, KEY_READ, &key);
1584 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1586 /* try to unload though the key handle is live */
1587 pRtlInitUnicodeString(&key_name, L"\\REGISTRY\\Machine\\Test");
1588 InitializeObjectAttributes(&attr, &key_name, OBJ_CASE_INSENSITIVE, NULL, NULL);
1589 status = pNtUnloadKey(&attr);
1590 ok(status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08x\n", status);
1592 RegCloseKey(key);
1594 ret = RegUnLoadKeyA(HKEY_LOCAL_MACHINE, "Test");
1595 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
1597 set_privileges(SE_RESTORE_NAME, FALSE);
1599 DeleteFileA("saved_key");
1600 DeleteFileA("saved_key.LOG");
1603 /* tests that show that RegConnectRegistry and
1604 OpenSCManager accept computer names without the
1605 \\ prefix (what MSDN says). */
1606 static void test_regconnectregistry( void)
1608 CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
1609 CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
1610 DWORD len = sizeof(compName) ;
1611 BOOL ret;
1612 LONG retl;
1613 HKEY hkey;
1614 SC_HANDLE schnd;
1616 SetLastError(0xdeadbeef);
1617 ret = GetComputerNameA(compName, &len);
1618 ok( ret, "GetComputerName failed err = %d\n", GetLastError());
1619 if( !ret) return;
1621 lstrcpyA(netwName, "\\\\");
1622 lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
1624 retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
1625 ok( !retl ||
1626 retl == ERROR_DLL_INIT_FAILED ||
1627 retl == ERROR_BAD_NETPATH, /* some win2k */
1628 "RegConnectRegistryA failed err = %d\n", retl);
1629 if( !retl) RegCloseKey( hkey);
1631 retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
1632 ok( !retl ||
1633 retl == ERROR_DLL_INIT_FAILED ||
1634 retl == ERROR_BAD_NETPATH, /* some win2k */
1635 "RegConnectRegistryA failed err = %d\n", retl);
1636 if( !retl) RegCloseKey( hkey);
1638 SetLastError(0xdeadbeef);
1639 schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
1640 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1642 win_skip("OpenSCManagerA is not implemented\n");
1643 return;
1646 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1647 CloseServiceHandle( schnd);
1649 SetLastError(0xdeadbeef);
1650 schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
1651 ok( schnd != NULL, "OpenSCManagerA failed err = %d\n", GetLastError());
1652 CloseServiceHandle( schnd);
1656 static void test_reg_query_value(void)
1658 HKEY subkey;
1659 CHAR val[MAX_PATH];
1660 WCHAR valW[5];
1661 LONG size, ret;
1663 static const WCHAR expected[] = {'d','a','t','a',0};
1665 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
1666 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1668 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
1669 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1671 /* try an invalid hkey */
1672 SetLastError(0xdeadbeef);
1673 size = MAX_PATH;
1674 ret = RegQueryValueA((HKEY)0xcafebabe, "subkey", val, &size);
1675 ok(ret == ERROR_INVALID_HANDLE ||
1676 ret == ERROR_BADKEY || /* Windows 98 returns BADKEY */
1677 ret == ERROR_ACCESS_DENIED, /* non-admin winxp */
1678 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1679 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1681 /* try a NULL hkey */
1682 SetLastError(0xdeadbeef);
1683 size = MAX_PATH;
1684 ret = RegQueryValueA(NULL, "subkey", val, &size);
1685 ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 98 returns BADKEY */
1686 "Expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
1687 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1689 /* try a NULL value */
1690 size = MAX_PATH;
1691 ret = RegQueryValueA(hkey_main, "subkey", NULL, &size);
1692 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1693 ok(size == 5, "Expected 5, got %d\n", size);
1695 /* try a NULL size */
1696 SetLastError(0xdeadbeef);
1697 val[0] = '\0';
1698 ret = RegQueryValueA(hkey_main, "subkey", val, NULL);
1699 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
1700 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1701 ok(!val[0], "Expected val to be untouched, got %s\n", val);
1703 /* try a NULL value and size */
1704 ret = RegQueryValueA(hkey_main, "subkey", NULL, NULL);
1705 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1707 /* try a size too small */
1708 SetLastError(0xdeadbeef);
1709 val[0] = '\0';
1710 size = 1;
1711 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1712 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1713 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1714 ok(!val[0], "Expected val to be untouched, got %s\n", val);
1715 ok(size == 5, "Expected 5, got %d\n", size);
1717 /* successfully read the value using 'subkey' */
1718 size = MAX_PATH;
1719 ret = RegQueryValueA(hkey_main, "subkey", val, &size);
1720 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1721 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1722 ok(size == 5, "Expected 5, got %d\n", size);
1724 /* successfully read the value using the subkey key */
1725 size = MAX_PATH;
1726 ret = RegQueryValueA(subkey, NULL, val, &size);
1727 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1728 ok(!lstrcmpA(val, "data"), "Expected 'data', got '%s'\n", val);
1729 ok(size == 5, "Expected 5, got %d\n", size);
1731 /* unicode - try size too small */
1732 SetLastError(0xdeadbeef);
1733 valW[0] = '\0';
1734 size = 0;
1735 ret = RegQueryValueW(subkey, NULL, valW, &size);
1736 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1738 win_skip("RegQueryValueW is not implemented\n");
1739 goto cleanup;
1741 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1742 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1743 ok(!valW[0], "Expected valW to be untouched\n");
1744 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1746 /* unicode - try size in WCHARS */
1747 SetLastError(0xdeadbeef);
1748 size = ARRAY_SIZE(valW);
1749 ret = RegQueryValueW(subkey, NULL, valW, &size);
1750 ok(ret == ERROR_MORE_DATA, "Expected ERROR_MORE_DATA, got %d\n", ret);
1751 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %d\n", GetLastError());
1752 ok(!valW[0], "Expected valW to be untouched\n");
1753 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1755 /* unicode - successfully read the value */
1756 size = sizeof(valW);
1757 ret = RegQueryValueW(subkey, NULL, valW, &size);
1758 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1759 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1760 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1762 /* unicode - set the value without a NULL terminator */
1763 ret = RegSetValueW(subkey, NULL, REG_SZ, expected, sizeof(expected)-sizeof(WCHAR));
1764 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1766 /* unicode - read the unterminated value, value is terminated for us */
1767 memset(valW, 'a', sizeof(valW));
1768 size = sizeof(valW);
1769 ret = RegQueryValueW(subkey, NULL, valW, &size);
1770 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1771 ok(!lstrcmpW(valW, expected), "Got wrong value\n");
1772 ok(size == sizeof(expected), "Got wrong size: %d\n", size);
1774 cleanup:
1775 RegDeleteKeyA(subkey, "");
1776 RegCloseKey(subkey);
1779 static void test_reg_query_info(void)
1781 HKEY subkey;
1782 HKEY subsubkey;
1783 LONG ret;
1784 char classbuffer[32];
1785 WCHAR classbufferW[32];
1786 char expectbuffer[32];
1787 WCHAR expectbufferW[32];
1788 char subkey_class[] = "subkey class";
1789 WCHAR subkey_classW[] = {'s','u','b','k','e','y',' ','c','l','a','s','s',0};
1790 char subsubkey_class[] = "subsubkey class";
1791 DWORD classlen;
1792 DWORD subkeys, maxsubkeylen, maxclasslen;
1793 DWORD values, maxvaluenamelen, maxvaluelen;
1794 DWORD sdlen;
1795 FILETIME lastwrite;
1797 ret = RegCreateKeyExA(hkey_main, "subkey", 0, subkey_class, 0, KEY_ALL_ACCESS, NULL, &subkey, NULL);
1798 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1800 /* all parameters NULL */
1801 ret = RegQueryInfoKeyA(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1802 ok(ret == ERROR_INVALID_HANDLE, "ret = %d\n", ret);
1804 ret = RegQueryInfoKeyW(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1805 ok(ret == ERROR_INVALID_HANDLE, "ret = %d\n", ret);
1807 /* not requesting any information */
1808 ret = RegQueryInfoKeyA(subkey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1809 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1811 ret = RegQueryInfoKeyW(subkey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1812 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1814 /* class without length is invalid */
1815 memset(classbuffer, 0x55, sizeof(classbuffer));
1816 ret = RegQueryInfoKeyA(subkey, classbuffer, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1817 ok(ret == ERROR_INVALID_PARAMETER, "ret = %d\n", ret);
1818 ok(classbuffer[0] == 0x55, "classbuffer[0] = 0x%x\n", classbuffer[0]);
1820 memset(classbufferW, 0x55, sizeof(classbufferW));
1821 ret = RegQueryInfoKeyW(subkey, classbufferW, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1822 ok(ret == ERROR_INVALID_PARAMETER, "ret = %d\n", ret);
1823 ok(classbufferW[0] == 0x5555, "classbufferW[0] = 0x%x\n", classbufferW[0]);
1825 /* empty key */
1826 sdlen = classlen =0;
1827 ret = RegQueryInfoKeyA(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1828 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1829 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1830 ok(subkeys == 0, "subkeys = %u\n", subkeys);
1831 ok(maxsubkeylen == 0, "maxsubkeylen = %u\n", maxsubkeylen);
1832 ok(maxclasslen == 0, "maxclasslen = %u\n", maxclasslen);
1833 ok(values == 0, "values = %u\n", values);
1834 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1835 ok(maxvaluelen == 0, "maxvaluelen = %u\n", maxvaluelen);
1836 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1837 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1838 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1840 sdlen = classlen = 0;
1841 ret = RegQueryInfoKeyW(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1842 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1843 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1844 ok(subkeys == 0, "subkeys = %u\n", subkeys);
1845 ok(maxsubkeylen == 0, "maxsubkeylen = %u\n", maxsubkeylen);
1846 ok(maxclasslen == 0, "maxclasslen = %u\n", maxclasslen);
1847 ok(values == 0, "values = %u\n", values);
1848 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1849 ok(maxvaluelen == 0, "maxvaluelen = %u\n", maxvaluelen);
1850 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1851 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1852 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1854 ret = RegCreateKeyExA(subkey, "subsubkey", 0, subsubkey_class, 0, KEY_ALL_ACCESS, NULL, &subsubkey, NULL);
1855 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1857 ret = RegSetValueExA(subkey, NULL, 0, REG_SZ, (const BYTE*)"data", 5);
1858 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1860 /* with subkey & default value */
1861 sdlen = classlen = 0;
1862 ret = RegQueryInfoKeyA(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1863 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1864 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1865 ok(subkeys == 1, "subkeys = %u\n", subkeys);
1866 ok(maxsubkeylen == strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen);
1867 ok(maxclasslen == strlen(subsubkey_class), "maxclasslen = %u\n", maxclasslen);
1868 ok(values == 1, "values = %u\n", values);
1869 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1870 ok(maxvaluelen == sizeof("data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1871 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1872 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1873 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1875 sdlen = classlen = 0;
1876 ret = RegQueryInfoKeyW(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1877 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1878 ok(classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1879 ok(subkeys == 1, "subkeys = %u\n", subkeys);
1880 ok(maxsubkeylen == strlen("subsubkey"), "maxsubkeylen = %u\n", maxsubkeylen);
1881 ok(maxclasslen == strlen(subsubkey_class), "maxclasslen = %u\n", maxclasslen);
1882 ok(values == 1, "values = %u\n", values);
1883 ok(maxvaluenamelen == 0, "maxvaluenamelen = %u\n", maxvaluenamelen);
1884 ok(maxvaluelen == sizeof("data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1885 todo_wine ok(sdlen != 0, "sdlen = %u\n", sdlen);
1886 ok(lastwrite.dwLowDateTime != 0, "lastwrite.dwLowDateTime = %u\n", lastwrite.dwLowDateTime);
1887 ok(lastwrite.dwHighDateTime != 0, "lastwrite.dwHighDateTime = %u\n", lastwrite.dwHighDateTime);
1889 ret = RegSetValueExA(subkey, "value one", 0, REG_SZ, (const BYTE*)"first value data", 17);
1890 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1892 ret = RegSetValueExA(subkey, "value 2", 0, REG_SZ, (const BYTE*)"second value data", 18);
1893 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
1895 /* with named value */
1896 classlen = 0;
1897 ret = RegQueryInfoKeyA(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1898 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1899 ok(values == 3, "values = %u\n", values);
1900 ok(maxvaluenamelen == strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen);
1901 ok(maxvaluelen == sizeof("second value data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1903 classlen = 0;
1904 ret = RegQueryInfoKeyW(subkey, NULL, &classlen, NULL, &subkeys, &maxsubkeylen, &maxclasslen, &values, &maxvaluenamelen, &maxvaluelen, &sdlen, &lastwrite);
1905 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1906 ok(values == 3, "values = %u\n", values);
1907 ok(maxvaluenamelen == strlen("value one"), "maxvaluenamelen = %u\n", maxvaluenamelen);
1908 ok(maxvaluelen == sizeof("second value data") * sizeof(WCHAR), "maxvaluelen = %u\n", maxvaluelen);
1910 /* class name with zero size buffer */
1911 memset(classbuffer, 0x55, sizeof(classbuffer));
1912 classlen = 0;
1913 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1914 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1915 ok(classlen == strlen(subkey_class) /* win2k */ ||
1916 classlen == 0, "classlen = %u\n", classlen);
1917 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1918 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)), "classbuffer was modified\n");
1920 memset(classbufferW, 0x55, sizeof(classbufferW));
1921 classlen = 0;
1922 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1923 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1924 ok(classlen == strlen(subkey_class) /* win2k */ ||
1925 classlen == 0, "classlen = %u\n", classlen);
1926 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1927 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)), "classbufferW was modified\n");
1929 /* class name with one char buffer */
1930 memset(classbuffer, 0x55, sizeof(classbuffer));
1931 classlen = 1;
1932 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1933 ok(ret == ERROR_MORE_DATA, "ret = %d\n", ret);
1934 ok(classlen == 0, "classlen = %u\n", classlen);
1935 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1936 expectbuffer[0] = 0;
1937 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)), "classbuffer was modified\n");
1939 memset(classbufferW, 0x55, sizeof(classbufferW));
1940 classlen = 1;
1941 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1942 /* failure-code changed to ERROR_MORE_DATA in recent win10 */
1943 ok((ret == ERROR_INSUFFICIENT_BUFFER) || (ret == ERROR_MORE_DATA), "ret = %d\n", ret);
1944 ok(classlen == 0 /* win8 */ ||
1945 classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1946 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1947 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)), "classbufferW was modified\n");
1949 /* class name with buffer one char too small */
1950 memset(classbuffer, 0x55, sizeof(classbuffer));
1951 classlen = sizeof(subkey_class) - 1;
1952 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1953 ok(ret == ERROR_MORE_DATA, "ret = %d\n", ret);
1954 ok(classlen == sizeof(subkey_class) - 2, "classlen = %u\n", classlen);
1955 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1956 strcpy(expectbuffer, subkey_class);
1957 expectbuffer[sizeof(subkey_class) - 2] = 0;
1958 expectbuffer[sizeof(subkey_class) - 1] = 0x55;
1959 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)),
1960 "classbuffer = %.*s, expected %s\n",
1961 (int)sizeof(classbuffer), classbuffer, expectbuffer);
1963 memset(classbufferW, 0x55, sizeof(classbufferW));
1964 classlen = sizeof(subkey_class) - 1;
1965 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1966 ok(ret == ERROR_INSUFFICIENT_BUFFER, "ret = %d\n", ret);
1967 ok(classlen == sizeof(subkey_class) - 2 /* win8 */ ||
1968 classlen == strlen(subkey_class), "classlen = %u\n", classlen);
1969 memset(expectbufferW, 0x55, sizeof(expectbufferW));
1970 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)), "classbufferW was modified\n");
1972 /* class name with large enough buffer */
1973 memset(classbuffer, 0x55, sizeof(classbuffer));
1974 classlen = sizeof(subkey_class);
1975 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1976 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1977 ok(classlen == sizeof(subkey_class) - 1, "classlen = %u\n", classlen);
1978 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1979 strcpy(expectbuffer, subkey_class);
1980 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)),
1981 "classbuffer = \"%.*s\", expected %s\n",
1982 (int)sizeof(classbuffer), classbuffer, expectbuffer);
1984 memset(classbuffer, 0x55, sizeof(classbuffer));
1985 classlen = 0xdeadbeef;
1986 ret = RegQueryInfoKeyA(subkey, classbuffer, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1987 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1988 ok(classlen == sizeof(subkey_class) - 1, "classlen = %u\n", classlen);
1989 memset(expectbuffer, 0x55, sizeof(expectbuffer));
1990 strcpy(expectbuffer, subkey_class);
1991 ok(!memcmp(classbuffer, expectbuffer, sizeof(classbuffer)),
1992 "classbuffer = \"%.*s\", expected %s\n",
1993 (int)sizeof(classbuffer), classbuffer, expectbuffer);
1995 memset(classbufferW, 0x55, sizeof(classbufferW));
1996 classlen = sizeof(subkey_class);
1997 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1998 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
1999 ok(classlen == sizeof(subkey_class) - 1, "classlen = %u\n", classlen);
2000 memset(expectbufferW, 0x55, sizeof(expectbufferW));
2001 lstrcpyW(expectbufferW, subkey_classW);
2002 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)),
2003 "classbufferW = %s, expected %s\n",
2004 wine_dbgstr_wn(classbufferW, ARRAY_SIZE(classbufferW)), wine_dbgstr_w(expectbufferW));
2006 memset(classbufferW, 0x55, sizeof(classbufferW));
2007 classlen = 0xdeadbeef;
2008 ret = RegQueryInfoKeyW(subkey, classbufferW, &classlen, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
2009 ok(ret == ERROR_SUCCESS, "ret = %d\n", ret);
2010 ok(classlen == sizeof(subkey_class) - 1, "classlen = %u\n", classlen);
2011 memset(expectbufferW, 0x55, sizeof(expectbufferW));
2012 lstrcpyW(expectbufferW, subkey_classW);
2013 ok(!memcmp(classbufferW, expectbufferW, sizeof(classbufferW)),
2014 "classbufferW = %s, expected %s\n",
2015 wine_dbgstr_wn(classbufferW, ARRAY_SIZE(classbufferW)), wine_dbgstr_w(expectbufferW));
2017 RegDeleteKeyA(subsubkey, "");
2018 RegCloseKey(subsubkey);
2019 RegDeleteKeyA(subkey, "");
2020 RegCloseKey(subkey);
2023 static void test_string_termination(void)
2025 HKEY subkey;
2026 LSTATUS ret;
2027 static const char string[] = "FullString";
2028 char name[11];
2029 BYTE buffer[11];
2030 DWORD insize, outsize, nsize;
2032 ret = RegCreateKeyA(hkey_main, "string_termination", &subkey);
2033 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2035 /* Off-by-one RegSetValueExA -> adds a trailing '\0'! */
2036 insize=sizeof(string)-1;
2037 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
2038 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
2039 outsize=insize;
2040 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
2041 ok(ret == ERROR_MORE_DATA, "RegQueryValueExA returned: %d\n", ret);
2043 /* Off-by-two RegSetValueExA -> no trailing '\0' */
2044 insize=sizeof(string)-2;
2045 ret = RegSetValueExA(subkey, "stringtest", 0, REG_SZ, (BYTE*)string, insize);
2046 ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", ret);
2047 outsize=0;
2048 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, NULL, &outsize);
2049 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
2050 ok(outsize == insize, "wrong size %u != %u\n", outsize, insize);
2052 /* RegQueryValueExA may return a string with no trailing '\0' */
2053 outsize=insize;
2054 memset(buffer, 0xbd, sizeof(buffer));
2055 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
2056 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
2057 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2058 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2059 debugstr_an((char*)buffer, outsize), outsize, string);
2060 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2062 /* RegQueryValueExA adds a trailing '\0' if there is room */
2063 outsize=insize+1;
2064 memset(buffer, 0xbd, sizeof(buffer));
2065 ret = RegQueryValueExA(subkey, "stringtest", NULL, NULL, buffer, &outsize);
2066 ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
2067 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2068 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2069 debugstr_an((char*)buffer, outsize), outsize, string);
2070 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2072 /* RegEnumValueA may return a string with no trailing '\0' */
2073 outsize=insize;
2074 memset(buffer, 0xbd, sizeof(buffer));
2075 nsize=sizeof(name);
2076 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
2077 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
2078 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
2079 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2080 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2081 debugstr_an((char*)buffer, outsize), outsize, string);
2082 ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2084 /* RegEnumValueA adds a trailing '\0' if there is room */
2085 outsize=insize+1;
2086 memset(buffer, 0xbd, sizeof(buffer));
2087 nsize=sizeof(name);
2088 ret = RegEnumValueA(subkey, 0, name, &nsize, NULL, NULL, buffer, &outsize);
2089 ok(ret == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", ret);
2090 ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
2091 ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
2092 ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
2093 debugstr_an((char*)buffer, outsize), outsize, string);
2094 ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
2096 RegDeleteKeyA(subkey, "");
2097 RegCloseKey(subkey);
2100 static void test_reg_copy_tree(void)
2102 HKEY src, dst, subkey;
2103 CHAR buffer[MAX_PATH];
2104 DWORD dwsize, type;
2105 LONG size, ret;
2107 if (!pRegCopyTreeA)
2109 win_skip("Skipping RegCopyTreeA tests, function not present\n");
2110 return;
2113 ret = RegCreateKeyA(hkey_main, "src", &src);
2114 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2115 ret = RegCreateKeyA(hkey_main, "dst", &dst);
2116 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2118 /* Copy nonexistent subkey */
2119 ret = pRegCopyTreeA(src, "nonexistent_subkey", dst);
2120 ok(ret == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
2122 /* Create test keys and values */
2123 ret = RegSetValueA(src, NULL, REG_SZ, "data", 4);
2124 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2125 ret = RegSetValueExA(src, "value", 0, REG_SZ, (const BYTE *)"data2", 5);
2126 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2128 ret = RegCreateKeyA(src, "subkey2", &subkey);
2129 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2130 ret = RegSetValueA(subkey, NULL, REG_SZ, "data3", 5);
2131 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2132 ret = RegSetValueExA(subkey, "value", 0, REG_SZ, (const BYTE *)"data4", 5);
2133 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2134 ret = RegCloseKey(subkey);
2135 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2137 ret = RegCreateKeyA(src, "subkey3", &subkey);
2138 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2139 ret = RegCloseKey(subkey);
2140 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2142 /* Copy subkey */
2143 ret = pRegCopyTreeA(src, "subkey2", dst);
2144 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2146 size = MAX_PATH;
2147 ret = RegQueryValueA(dst, NULL, buffer, &size);
2148 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2149 ok(!strcmp(buffer, "data3"), "Expected 'data3', got '%s'\n", buffer);
2151 dwsize = MAX_PATH;
2152 ret = RegQueryValueExA(dst, "value", NULL, &type, (BYTE *)buffer, &dwsize);
2153 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2154 ok(type == REG_SZ, "Expected REG_SZ, got %u\n", type);
2155 ok(!strcmp(buffer, "data4"), "Expected 'data4', got '%s'\n", buffer);
2157 /* Copy full tree */
2158 ret = pRegCopyTreeA(src, NULL, dst);
2159 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2161 size = MAX_PATH;
2162 ret = RegQueryValueA(dst, NULL, buffer, &size);
2163 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2164 ok(!strcmp(buffer, "data"), "Expected 'data', got '%s'\n", buffer);
2166 dwsize = MAX_PATH;
2167 ret = RegQueryValueExA(dst, "value", NULL, &type, (BYTE *)buffer, &dwsize);
2168 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2169 ok(type == REG_SZ, "Expected REG_SZ, got %u\n", type);
2170 ok(!strcmp(buffer, "data2"), "Expected 'data2', got '%s'\n", buffer);
2172 ret = RegOpenKeyA(dst, "subkey2", &subkey);
2173 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2174 size = MAX_PATH;
2175 ret = RegQueryValueA(subkey, NULL, buffer, &size);
2176 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2177 ok(!strcmp(buffer, "data3"), "Expected 'data3', got '%s'\n", buffer);
2178 dwsize = MAX_PATH;
2179 ret = RegQueryValueExA(subkey, "value", NULL, &type, (BYTE *)buffer, &dwsize);
2180 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2181 ok(type == REG_SZ, "Expected REG_SZ, got %u\n", type);
2182 ok(!strcmp(buffer, "data4"), "Expected 'data4', got '%s'\n", buffer);
2183 ret = RegCloseKey(subkey);
2184 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2186 ret = RegOpenKeyA(dst, "subkey3", &subkey);
2187 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2188 ret = RegCloseKey(subkey);
2189 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2191 delete_key(src);
2192 delete_key(dst);
2195 static void test_reg_delete_tree(void)
2197 CHAR buffer[MAX_PATH];
2198 HKEY subkey, subkey2;
2199 DWORD dwsize, type;
2200 LONG size, ret;
2202 if(!pRegDeleteTreeA) {
2203 win_skip("Skipping RegDeleteTreeA tests, function not present\n");
2204 return;
2207 ret = RegCreateKeyA(hkey_main, "subkey", &subkey);
2208 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2209 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
2210 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2211 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
2212 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2213 ret = RegSetValueA(subkey2, NULL, REG_SZ, "data2", 5);
2214 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2215 ret = RegCloseKey(subkey2);
2216 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2218 ret = pRegDeleteTreeA(subkey, "subkey2");
2219 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2220 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
2221 "subkey2 was not deleted\n");
2222 size = MAX_PATH;
2223 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
2224 "Default value of subkey no longer present\n");
2226 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
2227 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2228 ret = RegCloseKey(subkey2);
2229 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2230 ret = pRegDeleteTreeA(hkey_main, "subkey\\subkey2");
2231 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2232 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
2233 "subkey2 was not deleted\n");
2234 ok(!RegQueryValueA(subkey, NULL, buffer, &size),
2235 "Default value of subkey no longer present\n");
2237 ret = RegCreateKeyA(subkey, "subkey2", &subkey2);
2238 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2239 ret = RegCloseKey(subkey2);
2240 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2241 ret = RegCreateKeyA(subkey, "subkey3", &subkey2);
2242 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2243 ret = RegCloseKey(subkey2);
2244 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2245 ret = RegSetValueA(subkey, NULL, REG_SZ, "data", 4);
2246 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2247 ret = RegSetValueExA(subkey, "value", 0, REG_SZ, (const BYTE *)"data2", 5);
2248 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2249 ret = pRegDeleteTreeA(subkey, NULL);
2250 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2251 ok(!RegOpenKeyA(hkey_main, "subkey", &subkey),
2252 "subkey was deleted\n");
2253 ok(RegOpenKeyA(subkey, "subkey2", &subkey2),
2254 "subkey2 was not deleted\n");
2255 ok(RegOpenKeyA(subkey, "subkey3", &subkey2),
2256 "subkey3 was not deleted\n");
2257 size = MAX_PATH;
2258 ret = RegQueryValueA(subkey, NULL, buffer, &size);
2259 ok(ret == ERROR_SUCCESS,
2260 "Default value of subkey is not present\n");
2261 ok(!buffer[0], "Expected length 0 got length %u(%s)\n", lstrlenA(buffer), buffer);
2262 dwsize = MAX_PATH;
2263 ok(RegQueryValueExA(subkey, "value", NULL, &type, (BYTE *)buffer, &dwsize),
2264 "Value is still present\n");
2265 ret = RegCloseKey(subkey);
2266 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2268 ret = RegOpenKeyA(hkey_main, "subkey", &subkey);
2269 ok(ret == ERROR_SUCCESS, "subkey was deleted\n");
2270 ret = pRegDeleteTreeA(subkey, "");
2271 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2272 ret = RegCloseKey(subkey);
2273 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2275 ret = RegOpenKeyA(hkey_main, "subkey", &subkey);
2276 ok(ret == ERROR_SUCCESS, "subkey was deleted\n");
2277 ret = RegCloseKey(subkey);
2278 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
2280 ret = pRegDeleteTreeA(hkey_main, "not-here");
2281 ok(ret == ERROR_FILE_NOT_FOUND,
2282 "Expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
2285 static void test_rw_order(void)
2287 HKEY hKey;
2288 DWORD dw = 0;
2289 static const char keyname[] = "test_rw_order";
2290 char value_buf[2];
2291 DWORD values, value_len, value_name_max_len;
2292 LSTATUS ret;
2294 RegDeleteKeyA(HKEY_CURRENT_USER, keyname);
2295 ret = RegCreateKeyA(HKEY_CURRENT_USER, keyname, &hKey);
2296 if(ret != ERROR_SUCCESS) {
2297 skip("Couldn't create key. Skipping.\n");
2298 return;
2301 ok(!RegSetValueExA(hKey, "A", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2302 "RegSetValueExA for value \"A\" failed\n");
2303 ok(!RegSetValueExA(hKey, "C", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2304 "RegSetValueExA for value \"C\" failed\n");
2305 ok(!RegSetValueExA(hKey, "D", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2306 "RegSetValueExA for value \"D\" failed\n");
2307 ok(!RegSetValueExA(hKey, "B", 0, REG_DWORD, (LPBYTE)&dw, sizeof(dw)),
2308 "RegSetValueExA for value \"B\" failed\n");
2310 ok(!RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &values,
2311 &value_name_max_len, NULL, NULL, NULL), "RegQueryInfoKeyA failed\n");
2312 ok(values == 4, "Expected 4 values, got %u\n", values);
2314 /* Value enumeration preserves RegSetValueEx call order */
2315 value_len = 2;
2316 ok(!RegEnumValueA(hKey, 0, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2317 ok(strcmp(value_buf, "A") == 0, "Expected name \"A\", got %s\n", value_buf);
2318 value_len = 2;
2319 ok(!RegEnumValueA(hKey, 1, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2320 todo_wine ok(strcmp(value_buf, "C") == 0, "Expected name \"C\", got %s\n", value_buf);
2321 value_len = 2;
2322 ok(!RegEnumValueA(hKey, 2, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2323 todo_wine ok(strcmp(value_buf, "D") == 0, "Expected name \"D\", got %s\n", value_buf);
2324 value_len = 2;
2325 ok(!RegEnumValueA(hKey, 3, value_buf, &value_len, NULL, NULL, NULL, NULL), "RegEnumValueA failed\n");
2326 todo_wine ok(strcmp(value_buf, "B") == 0, "Expected name \"B\", got %s\n", value_buf);
2328 ok(!RegDeleteKeyA(HKEY_CURRENT_USER, keyname), "Failed to delete key\n");
2331 static void test_symlinks(void)
2333 static const WCHAR targetW[] = {'\\','S','o','f','t','w','a','r','e','\\','W','i','n','e',
2334 '\\','T','e','s','t','\\','t','a','r','g','e','t',0};
2335 BYTE buffer[1024];
2336 UNICODE_STRING target_str;
2337 WCHAR *target;
2338 HKEY key, link;
2339 NTSTATUS status;
2340 DWORD target_len, type, len, dw, err;
2342 if (!pRtlFormatCurrentUserKeyPath || !pNtDeleteKey)
2344 win_skip( "Can't perform symlink tests\n" );
2345 return;
2348 pRtlFormatCurrentUserKeyPath( &target_str );
2350 target_len = target_str.Length + sizeof(targetW);
2351 target = HeapAlloc( GetProcessHeap(), 0, target_len );
2352 memcpy( target, target_str.Buffer, target_str.Length );
2353 memcpy( target + target_str.Length/sizeof(WCHAR), targetW, sizeof(targetW) );
2355 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
2356 KEY_ALL_ACCESS, NULL, &link, NULL );
2357 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed: %u\n", err );
2359 /* REG_SZ is not allowed */
2360 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_SZ, (BYTE *)"foobar", sizeof("foobar") );
2361 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
2362 err = RegSetValueExA( link, "SymbolicLinkValue", 0, REG_LINK,
2363 (BYTE *)target, target_len - sizeof(WCHAR) );
2364 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
2365 /* other values are not allowed */
2366 err = RegSetValueExA( link, "link", 0, REG_LINK, (BYTE *)target, target_len - sizeof(WCHAR) );
2367 ok( err == ERROR_ACCESS_DENIED, "RegSetValueEx wrong error %u\n", err );
2369 /* try opening the target through the link */
2371 err = RegOpenKeyA( hkey_main, "link", &key );
2372 ok( err == ERROR_FILE_NOT_FOUND, "RegOpenKey wrong error %u\n", err );
2374 err = RegCreateKeyExA( hkey_main, "target", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
2375 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
2377 dw = 0xbeef;
2378 err = RegSetValueExA( key, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
2379 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
2380 RegCloseKey( key );
2382 err = RegOpenKeyA( hkey_main, "link", &key );
2383 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
2385 len = sizeof(buffer);
2386 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
2387 ok( err == ERROR_SUCCESS, "RegOpenKey failed error %u\n", err );
2388 ok( len == sizeof(DWORD), "wrong len %u\n", len );
2390 len = sizeof(buffer);
2391 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2392 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
2394 /* REG_LINK can be created in non-link keys */
2395 err = RegSetValueExA( key, "SymbolicLinkValue", 0, REG_LINK,
2396 (BYTE *)target, target_len - sizeof(WCHAR) );
2397 ok( err == ERROR_SUCCESS, "RegSetValueEx failed error %u\n", err );
2398 len = sizeof(buffer);
2399 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2400 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2401 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
2402 err = RegDeleteValueA( key, "SymbolicLinkValue" );
2403 ok( err == ERROR_SUCCESS, "RegDeleteValue failed error %u\n", err );
2405 RegCloseKey( key );
2407 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL );
2408 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
2410 len = sizeof(buffer);
2411 err = RegQueryValueExA( key, "value", NULL, &type, buffer, &len );
2412 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2413 ok( len == sizeof(DWORD), "wrong len %u\n", len );
2415 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2416 ok( err == ERROR_FILE_NOT_FOUND, "RegQueryValueEx wrong error %u\n", err );
2417 RegCloseKey( key );
2419 /* now open the symlink itself */
2421 err = RegOpenKeyExA( hkey_main, "link", REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, &key );
2422 ok( err == ERROR_SUCCESS, "RegOpenKeyEx failed error %u\n", err );
2423 len = sizeof(buffer);
2424 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2425 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2426 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
2427 RegCloseKey( key );
2429 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_OPEN_LINK,
2430 KEY_ALL_ACCESS, NULL, &key, NULL );
2431 ok( err == ERROR_SUCCESS, "RegCreateKeyEx failed error %u\n", err );
2432 len = sizeof(buffer);
2433 err = RegQueryValueExA( key, "SymbolicLinkValue", NULL, &type, buffer, &len );
2434 ok( err == ERROR_SUCCESS, "RegQueryValueEx failed error %u\n", err );
2435 ok( len == target_len - sizeof(WCHAR), "wrong len %u\n", len );
2436 RegCloseKey( key );
2438 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK,
2439 KEY_ALL_ACCESS, NULL, &key, NULL );
2440 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
2442 err = RegCreateKeyExA( hkey_main, "link", 0, NULL, REG_OPTION_CREATE_LINK | REG_OPTION_OPEN_LINK,
2443 KEY_ALL_ACCESS, NULL, &key, NULL );
2444 ok( err == ERROR_ALREADY_EXISTS, "RegCreateKeyEx wrong error %u\n", err );
2446 err = RegDeleteKeyA( hkey_main, "target" );
2447 ok( err == ERROR_SUCCESS, "RegDeleteKey failed error %u\n", err );
2449 err = RegDeleteKeyA( hkey_main, "link" );
2450 ok( err == ERROR_FILE_NOT_FOUND, "RegDeleteKey wrong error %u\n", err );
2452 status = pNtDeleteKey( link );
2453 ok( !status, "NtDeleteKey failed: 0x%08x\n", status );
2454 RegCloseKey( link );
2456 HeapFree( GetProcessHeap(), 0, target );
2457 pRtlFreeUnicodeString( &target_str );
2460 static DWORD get_key_value( HKEY root, const char *name, DWORD flags )
2462 HKEY key;
2463 DWORD err, type, dw, len = sizeof(dw);
2465 err = RegCreateKeyExA( root, name, 0, NULL, 0, flags | KEY_ALL_ACCESS, NULL, &key, NULL );
2466 if (err == ERROR_FILE_NOT_FOUND) return 0;
2467 ok( err == ERROR_SUCCESS, "%08x: RegCreateKeyEx failed: %u\n", flags, err );
2469 err = RegQueryValueExA( key, "value", NULL, &type, (BYTE *)&dw, &len );
2470 if (err == ERROR_FILE_NOT_FOUND)
2471 dw = 0;
2472 else
2473 ok( err == ERROR_SUCCESS, "%08x: RegQueryValueEx failed: %u\n", flags, err );
2474 RegCloseKey( key );
2475 return dw;
2478 static void _check_key_value( int line, HANDLE root, const char *name, DWORD flags, DWORD expect )
2480 DWORD dw = get_key_value( root, name, flags );
2481 ok_(__FILE__,line)( dw == expect, "%08x: wrong value %u/%u\n", flags, dw, expect );
2483 #define check_key_value(root,name,flags,expect) _check_key_value( __LINE__, root, name, flags, expect )
2485 static void test_redirection(void)
2487 DWORD err, type, dw, len;
2488 HKEY key, root32, root64, key32, key64, native, op_key;
2489 BOOL is_vista = FALSE;
2490 REGSAM opposite = (sizeof(void*) == 8 ? KEY_WOW64_32KEY : KEY_WOW64_64KEY);
2492 if (ptr_size != 64)
2494 BOOL is_wow64;
2495 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64)
2497 skip( "Not on Wow64, no redirection\n" );
2498 return;
2502 if (limited_user)
2504 skip("not enough privileges to modify HKLM\n");
2505 return;
2508 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2509 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &root64, NULL );
2510 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2512 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2513 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &root32, NULL );
2514 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2516 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
2517 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key64, NULL );
2518 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2520 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, NULL, 0,
2521 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key32, NULL );
2522 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2524 dw = 64;
2525 err = RegSetValueExA( key64, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
2526 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
2528 dw = 32;
2529 err = RegSetValueExA( key32, "value", 0, REG_DWORD, (BYTE *)&dw, sizeof(dw) );
2530 ok( err == ERROR_SUCCESS, "RegSetValueExA failed: %u\n", err );
2532 dw = 0;
2533 len = sizeof(dw);
2534 err = RegQueryValueExA( key32, "value", NULL, &type, (BYTE *)&dw, &len );
2535 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
2536 ok( dw == 32, "wrong value %u\n", dw );
2538 dw = 0;
2539 len = sizeof(dw);
2540 err = RegQueryValueExA( key64, "value", NULL, &type, (BYTE *)&dw, &len );
2541 ok( err == ERROR_SUCCESS, "RegQueryValueExA failed: %u\n", err );
2542 ok( dw == 64, "wrong value %u\n", dw );
2544 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2545 KEY_ALL_ACCESS, NULL, &key, NULL );
2546 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2548 if (ptr_size == 32)
2550 /* the Vista mechanism allows opening Wow6432Node from a 32-bit key too */
2551 /* the new (and simpler) Win7 mechanism doesn't */
2552 if (get_key_value( key, "Wow6432Node\\Wine\\Winetest", 0 ) == 32)
2554 trace( "using Vista-style Wow6432Node handling\n" );
2555 is_vista = TRUE;
2557 check_key_value( key, "Wine\\Winetest", 0, 32 );
2558 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2559 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2560 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
2561 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
2562 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
2564 else
2566 if (get_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY ) == 64)
2568 trace( "using Vista-style Wow6432Node handling\n" );
2569 is_vista = TRUE;
2571 check_key_value( key, "Wine\\Winetest", 0, 64 );
2572 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2574 RegCloseKey( key );
2576 if (ptr_size == 32)
2578 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2579 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2580 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2581 dw = get_key_value( key, "Wine\\Winetest", 0 );
2582 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2583 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2584 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2585 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2586 dw = get_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY );
2587 ok( dw == 32 || broken(dw == 64) /* xp64 */, "wrong value %u\n", dw );
2588 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2589 RegCloseKey( key );
2591 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2592 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2593 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2594 check_key_value( key, "Wine\\Winetest", 0, 32 );
2595 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2596 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2597 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, is_vista ? 32 : 0 );
2598 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 0 );
2599 check_key_value( key, "Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, is_vista ? 32 : 0 );
2600 RegCloseKey( key );
2602 else
2604 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2605 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2606 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2607 check_key_value( key, "Wine\\Winetest", 0, 64 );
2608 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2609 dw = get_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY );
2610 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2611 check_key_value( key, "Wow6432Node\\Wine\\Winetest", 0, 32 );
2612 RegCloseKey( key );
2614 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software", 0, NULL, 0,
2615 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2616 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2617 check_key_value( key, "Wine\\Winetest", 0, 32 );
2618 dw = get_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY );
2619 ok( dw == 32 || broken(dw == 64) /* vista */, "wrong value %u\n", dw );
2620 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2621 RegCloseKey( key );
2624 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", 0, ptr_size );
2625 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", 0, 32 );
2626 if (ptr_size == 64)
2628 /* KEY_WOW64 flags have no effect on 64-bit */
2629 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2630 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2631 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2632 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2634 else
2636 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_64KEY, 64 );
2637 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2638 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2639 check_key_value( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2642 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2643 KEY_ALL_ACCESS, NULL, &key, NULL );
2644 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2645 check_key_value( key, "Wine\\Winetest", 0, 32 );
2646 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2647 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2648 RegCloseKey( key );
2650 if (ptr_size == 32)
2652 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2653 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2654 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2655 dw = get_key_value( key, "Wine\\Winetest", 0 );
2656 ok( dw == (is_vista ? 64 : 32) || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2657 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2658 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2659 RegCloseKey( key );
2661 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node", 0, NULL, 0,
2662 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2663 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2664 check_key_value( key, "Wine\\Winetest", 0, 32 );
2665 check_key_value( key, "Wine\\Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2666 check_key_value( key, "Wine\\Winetest", KEY_WOW64_32KEY, 32 );
2667 RegCloseKey( key );
2670 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2671 KEY_ALL_ACCESS, NULL, &key, NULL );
2672 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2673 check_key_value( key, "Winetest", 0, 32 );
2674 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2675 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2676 RegCloseKey( key );
2678 if (ptr_size == 32)
2680 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2681 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2682 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2683 dw = get_key_value( key, "Winetest", 0 );
2684 ok( dw == 32 || (is_vista && dw == 64), "wrong value %u\n", dw );
2685 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2686 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2687 RegCloseKey( key );
2689 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wow6432Node\\Wine", 0, NULL, 0,
2690 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2691 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2692 check_key_value( key, "Winetest", 0, 32 );
2693 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2694 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2695 RegCloseKey( key );
2698 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2699 KEY_ALL_ACCESS, NULL, &key, NULL );
2700 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2701 check_key_value( key, "Winetest", 0, ptr_size );
2702 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : ptr_size );
2703 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2704 todo_wine_if (ptr_size != 32)
2705 ok( dw == 32, "wrong value %u\n", dw );
2706 RegCloseKey( key );
2708 if (ptr_size == 32)
2710 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2711 KEY_WOW64_64KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2712 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2713 dw = get_key_value( key, "Winetest", 0 );
2714 ok( dw == 64 || broken(dw == 32) /* xp64 */, "wrong value %u\n", dw );
2715 check_key_value( key, "Winetest", KEY_WOW64_64KEY, 64 );
2716 dw = get_key_value( key, "Winetest", KEY_WOW64_32KEY );
2717 todo_wine ok( dw == 32, "wrong value %u\n", dw );
2718 RegCloseKey( key );
2720 err = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine", 0, NULL, 0,
2721 KEY_WOW64_32KEY | KEY_ALL_ACCESS, NULL, &key, NULL );
2722 ok( err == ERROR_SUCCESS, "RegCreateKeyExA failed: %u\n", err );
2723 check_key_value( key, "Winetest", 0, 32 );
2724 check_key_value( key, "Winetest", KEY_WOW64_64KEY, is_vista ? 64 : 32 );
2725 check_key_value( key, "Winetest", KEY_WOW64_32KEY, 32 );
2726 RegCloseKey( key );
2729 if (pRegDeleteKeyExA)
2731 err = pRegDeleteKeyExA( key32, "", KEY_WOW64_32KEY, 0 );
2732 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2733 err = pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2734 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2735 pRegDeleteKeyExA( key64, "", KEY_WOW64_64KEY, 0 );
2736 pRegDeleteKeyExA( root64, "", KEY_WOW64_64KEY, 0 );
2738 else
2740 err = RegDeleteKeyA( key32, "" );
2741 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2742 err = RegDeleteKeyA( key64, "" );
2743 ok( err == ERROR_SUCCESS, "RegDeleteKey failed: %u\n", err );
2744 RegDeleteKeyA( key64, "" );
2745 RegDeleteKeyA( root64, "" );
2747 RegCloseKey( key32 );
2748 RegCloseKey( key64 );
2749 RegCloseKey( root32 );
2750 RegCloseKey( root64 );
2752 /* open key in native bit mode */
2753 err = RegOpenKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, KEY_ALL_ACCESS, &native);
2754 ok(err == ERROR_SUCCESS, "got %i\n", err);
2756 pRegDeleteKeyExA(native, "AWineTest", 0, 0);
2758 /* write subkey in opposite bit mode */
2759 err = RegOpenKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, KEY_ALL_ACCESS | opposite, &op_key);
2760 ok(err == ERROR_SUCCESS, "got %i\n", err);
2762 err = RegCreateKeyExA(op_key, "AWineTest", 0, NULL, 0, KEY_ALL_ACCESS | opposite,
2763 NULL, &key, NULL);
2764 ok(err == ERROR_SUCCESS || err == ERROR_ACCESS_DENIED, "got %i\n", err);
2765 if(err != ERROR_SUCCESS){
2766 win_skip("Can't write to registry\n");
2767 RegCloseKey(op_key);
2768 RegCloseKey(native);
2769 return;
2771 RegCloseKey(key);
2773 /* verify subkey is not present in native mode */
2774 err = RegOpenKeyExA(native, "AWineTest", 0, KEY_ALL_ACCESS, &key);
2775 ok(err == ERROR_FILE_NOT_FOUND ||
2776 broken(err == ERROR_SUCCESS), /* before Win7, HKCR is reflected instead of redirected */
2777 "got %i\n", err);
2779 err = pRegDeleteKeyExA(op_key, "AWineTest", opposite, 0);
2780 ok(err == ERROR_SUCCESS, "got %i\n", err);
2782 RegCloseKey(op_key);
2783 RegCloseKey(native);
2786 static void test_classesroot(void)
2788 HKEY hkey, hklm, hkcr, hkeysub1, hklmsub1, hkcrsub1, hklmsub2, hkcrsub2;
2789 DWORD size = 8;
2790 DWORD type = REG_SZ;
2791 static CHAR buffer[8];
2792 LONG res;
2794 /* create a key in the user's classes */
2795 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkey ))
2797 delete_key( hkey );
2798 RegCloseKey( hkey );
2800 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2801 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL );
2802 if (res == ERROR_ACCESS_DENIED)
2804 skip("not enough privileges to add a user class\n");
2805 return;
2807 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2809 /* try to open that key in hkcr */
2810 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2811 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2812 todo_wine ok(res == ERROR_SUCCESS ||
2813 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
2814 "test key not found in hkcr: %d\n", res);
2815 if (res)
2817 skip("HKCR key merging not supported\n");
2818 delete_key( hkey );
2819 RegCloseKey( hkey );
2820 return;
2823 todo_wine ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2825 /* set a value in user's classes */
2826 res = RegSetValueExA(hkey, "val1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2827 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2829 /* try to find the value in hkcr */
2830 res = RegQueryValueExA(hkcr, "val1", NULL, &type, (LPBYTE)buffer, &size);
2831 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2832 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2834 /* modify the value in hkcr */
2835 res = RegSetValueExA(hkcr, "val1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2836 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2838 /* check if the value is also modified in user's classes */
2839 res = RegQueryValueExA(hkey, "val1", NULL, &type, (LPBYTE)buffer, &size);
2840 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2841 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2843 /* set a value in hkcr */
2844 res = RegSetValueExA(hkcr, "val0", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2845 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2847 /* try to find the value in user's classes */
2848 res = RegQueryValueExA(hkey, "val0", NULL, &type, (LPBYTE)buffer, &size);
2849 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2850 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2852 /* modify the value in user's classes */
2853 res = RegSetValueExA(hkey, "val0", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2854 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2856 /* check if the value is also modified in hkcr */
2857 res = RegQueryValueExA(hkcr, "val0", NULL, &type, (LPBYTE)buffer, &size);
2858 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2859 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2861 /* cleanup */
2862 delete_key( hkey );
2863 delete_key( hkcr );
2864 RegCloseKey( hkey );
2865 RegCloseKey( hkcr );
2867 /* create a key in the hklm classes */
2868 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
2870 delete_key( hklm );
2871 RegCloseKey( hklm );
2873 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, REG_OPTION_NON_VOLATILE,
2874 KEY_ALL_ACCESS, NULL, &hklm, NULL );
2875 if (res == ERROR_ACCESS_DENIED)
2877 skip("not enough privileges to add a system class\n");
2878 return;
2880 ok(!IS_HKCR(hklm), "hkcr mask set in %p\n", hklm);
2882 /* try to open that key in hkcr */
2883 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2884 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2885 ok(res == ERROR_SUCCESS,
2886 "test key not found in hkcr: %d\n", res);
2887 ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2888 if (res)
2890 delete_key( hklm );
2891 RegCloseKey( hklm );
2892 return;
2895 /* set a value in hklm classes */
2896 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2897 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2899 /* try to find the value in hkcr */
2900 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2901 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2902 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2904 /* modify the value in hkcr */
2905 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2906 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2908 /* check that the value is modified in hklm classes */
2909 res = RegQueryValueExA(hklm, "val2", NULL, &type, (LPBYTE)buffer, &size);
2910 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2911 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2913 if (RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
2914 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkey, NULL )) return;
2915 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
2917 /* try to open that key in hkcr */
2918 res = RegOpenKeyExA( HKEY_CLASSES_ROOT, "WineTestCls", 0,
2919 KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcr );
2920 ok(res == ERROR_SUCCESS,
2921 "test key not found in hkcr: %d\n", res);
2922 ok(IS_HKCR(hkcr), "hkcr mask not set in %p\n", hkcr);
2924 /* set a value in user's classes */
2925 res = RegSetValueExA(hkey, "val2", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2926 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2928 /* try to find the value in hkcr */
2929 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2930 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2931 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2933 /* modify the value in hklm */
2934 res = RegSetValueExA(hklm, "val2", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2935 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2937 /* check that the value is not overwritten in hkcr or user's classes */
2938 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2939 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2940 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2941 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2942 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2943 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2945 /* modify the value in hkcr */
2946 res = RegSetValueExA(hkcr, "val2", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2947 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2949 /* check that the value is overwritten in hklm and user's classes */
2950 res = RegQueryValueExA(hkcr, "val2", NULL, &type, (LPBYTE)buffer, &size);
2951 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2952 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2953 res = RegQueryValueExA(hkey, "val2", NULL, &type, (LPBYTE)buffer, &size);
2954 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2955 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2957 /* create a subkey in hklm */
2958 if (RegCreateKeyExA( hklm, "subkey1", 0, NULL, 0,
2959 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hklmsub1, NULL )) return;
2960 ok(!IS_HKCR(hklmsub1), "hkcr mask set in %p\n", hklmsub1);
2961 /* try to open that subkey in hkcr */
2962 res = RegOpenKeyExA( hkcr, "subkey1", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hkcrsub1 );
2963 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
2964 ok(IS_HKCR(hkcrsub1), "hkcr mask not set in %p\n", hkcrsub1);
2966 /* set a value in hklm classes */
2967 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
2968 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2970 /* try to find the value in hkcr */
2971 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2972 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2973 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
2975 /* modify the value in hkcr */
2976 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
2977 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2979 /* check that the value is modified in hklm classes */
2980 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2981 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
2982 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
2984 /* create a subkey in user's classes */
2985 if (RegCreateKeyExA( hkey, "subkey1", 0, NULL, 0,
2986 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkeysub1, NULL )) return;
2987 ok(!IS_HKCR(hkeysub1), "hkcr mask set in %p\n", hkeysub1);
2989 /* set a value in user's classes */
2990 res = RegSetValueExA(hkeysub1, "subval1", 0, REG_SZ, (const BYTE *)"user", sizeof("user"));
2991 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
2993 /* try to find the value in hkcr */
2994 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
2995 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
2996 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
2998 /* modify the value in hklm */
2999 res = RegSetValueExA(hklmsub1, "subval1", 0, REG_SZ, (const BYTE *)"hklm", sizeof("hklm"));
3000 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
3002 /* check that the value is not overwritten in hkcr or user's classes */
3003 res = RegQueryValueExA(hkcrsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
3004 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
3005 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
3006 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
3007 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
3008 ok(!strcmp( buffer, "user" ), "value set to '%s'\n", buffer );
3010 /* modify the value in hkcr */
3011 res = RegSetValueExA(hkcrsub1, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
3012 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
3014 /* check that the value is not overwritten in hklm, but in user's classes */
3015 res = RegQueryValueExA(hklmsub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
3016 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
3017 ok(!strcmp( buffer, "hklm" ), "value set to '%s'\n", buffer );
3018 res = RegQueryValueExA(hkeysub1, "subval1", NULL, &type, (LPBYTE)buffer, &size);
3019 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d, GLE=%x\n", res, GetLastError());
3020 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
3022 /* new subkey in hkcr */
3023 if (RegCreateKeyExA( hkcr, "subkey2", 0, NULL, 0,
3024 KEY_QUERY_VALUE|KEY_SET_VALUE, NULL, &hkcrsub2, NULL )) return;
3025 ok(IS_HKCR(hkcrsub2), "hkcr mask not set in %p\n", hkcrsub2);
3026 res = RegSetValueExA(hkcrsub2, "subval1", 0, REG_SZ, (const BYTE *)"hkcr", sizeof("hkcr"));
3027 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d, GLE=%x\n", res, GetLastError());
3029 /* try to open that new subkey in user's classes and hklm */
3030 res = RegOpenKeyExA( hkey, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
3031 ok(res != ERROR_SUCCESS, "test key found in user's classes: %d\n", res);
3032 hklmsub2 = 0;
3033 res = RegOpenKeyExA( hklm, "subkey2", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hklmsub2 );
3034 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
3035 ok(!IS_HKCR(hklmsub2), "hkcr mask set in %p\n", hklmsub2);
3037 /* check that the value is present in hklm */
3038 res = RegQueryValueExA(hklmsub2, "subval1", NULL, &type, (LPBYTE)buffer, &size);
3039 ok(res == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", res);
3040 ok(!strcmp( buffer, "hkcr" ), "value set to '%s'\n", buffer );
3042 /* cleanup */
3043 RegCloseKey( hkeysub1 );
3044 RegCloseKey( hklmsub1 );
3046 /* delete subkey1 from hkcr (should point at user's classes) */
3047 res = RegDeleteKeyA(hkcr, "subkey1");
3048 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
3050 /* confirm key was removed in hkey but not hklm */
3051 res = RegOpenKeyExA(hkey, "subkey1", 0, KEY_READ, &hkeysub1);
3052 ok(res == ERROR_FILE_NOT_FOUND, "test key found in user's classes: %d\n", res);
3053 res = RegOpenKeyExA(hklm, "subkey1", 0, KEY_READ, &hklmsub1);
3054 ok(res == ERROR_SUCCESS, "test key not found in hklm: %d\n", res);
3055 ok(!IS_HKCR(hklmsub1), "hkcr mask set in %p\n", hklmsub1);
3057 /* delete subkey1 from hkcr again (which should now point at hklm) */
3058 res = RegDeleteKeyA(hkcr, "subkey1");
3059 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
3061 /* confirm hkey was removed in hklm */
3062 RegCloseKey( hklmsub1 );
3063 res = RegOpenKeyExA(hklm, "subkey1", 0, KEY_READ, &hklmsub1);
3064 ok(res == ERROR_FILE_NOT_FOUND, "test key found in hklm: %d\n", res);
3066 /* final cleanup */
3067 delete_key( hkey );
3068 delete_key( hklm );
3069 delete_key( hkcr );
3070 delete_key( hkeysub1 );
3071 delete_key( hklmsub1 );
3072 delete_key( hkcrsub1 );
3073 delete_key( hklmsub2 );
3074 delete_key( hkcrsub2 );
3075 RegCloseKey( hkey );
3076 RegCloseKey( hklm );
3077 RegCloseKey( hkcr );
3078 RegCloseKey( hkeysub1 );
3079 RegCloseKey( hklmsub1 );
3080 RegCloseKey( hkcrsub1 );
3081 RegCloseKey( hklmsub2 );
3082 RegCloseKey( hkcrsub2 );
3085 static void test_classesroot_enum(void)
3087 HKEY hkcu=0, hklm=0, hkcr=0, hkcusub[2]={0}, hklmsub[2]={0};
3088 DWORD size;
3089 static CHAR buffer[2];
3090 LONG res;
3092 /* prepare initial testing env in HKCU */
3093 if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", &hkcu ))
3095 delete_key( hkcu );
3096 RegCloseKey( hkcu );
3098 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Classes\\WineTestCls", 0, NULL, 0,
3099 KEY_SET_VALUE|KEY_ENUMERATE_SUB_KEYS, NULL, &hkcu, NULL );
3101 if (res != ERROR_SUCCESS)
3103 skip("failed to add a user class\n");
3104 return;
3107 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr );
3108 todo_wine ok(res == ERROR_SUCCESS ||
3109 broken(res == ERROR_FILE_NOT_FOUND /* WinNT */),
3110 "test key not found in hkcr: %d\n", res);
3111 if (res)
3113 skip("HKCR key merging not supported\n");
3114 delete_key( hkcu );
3115 RegCloseKey( hkcu );
3116 return;
3119 res = RegSetValueExA( hkcu, "X", 0, REG_SZ, (const BYTE *) "AA", 3 );
3120 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
3121 res = RegSetValueExA( hkcu, "Y", 0, REG_SZ, (const BYTE *) "B", 2 );
3122 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
3123 res = RegCreateKeyA( hkcu, "A", &hkcusub[0] );
3124 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
3125 res = RegCreateKeyA( hkcu, "B", &hkcusub[1] );
3126 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
3128 /* test on values in HKCU */
3129 size = sizeof(buffer);
3130 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3131 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3132 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
3133 size = sizeof(buffer);
3134 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
3135 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3136 ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer);
3137 size = sizeof(buffer);
3138 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
3139 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3141 res = RegEnumKeyA( hkcr, 0, buffer, size );
3142 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3143 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
3144 res = RegEnumKeyA( hkcr, 1, buffer, size );
3145 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3146 ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer);
3147 res = RegEnumKeyA( hkcr, 2, buffer, size );
3148 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3150 /* prepare test env in HKLM */
3151 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", &hklm ))
3153 delete_key( hklm );
3154 RegCloseKey( hklm );
3157 res = RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Classes\\WineTestCls", 0, NULL, 0,
3158 KEY_SET_VALUE|KEY_ENUMERATE_SUB_KEYS, NULL, &hklm, NULL );
3160 if (res == ERROR_ACCESS_DENIED)
3162 RegCloseKey( hkcusub[0] );
3163 RegCloseKey( hkcusub[1] );
3164 delete_key( hkcu );
3165 RegCloseKey( hkcu );
3166 RegCloseKey( hkcr );
3167 skip("not enough privileges to add a system class\n");
3168 return;
3171 res = RegSetValueExA( hklm, "X", 0, REG_SZ, (const BYTE *) "AB", 3 );
3172 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
3173 res = RegSetValueExA( hklm, "Z", 0, REG_SZ, (const BYTE *) "C", 2 );
3174 ok(res == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", res);
3175 res = RegCreateKeyA( hklm, "A", &hklmsub[0] );
3176 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
3177 res = RegCreateKeyA( hklm, "C", &hklmsub[1] );
3178 ok(res == ERROR_SUCCESS, "RegCreateKeyA failed: %d\n", res);
3180 /* test on values/keys in both HKCU and HKLM */
3181 size = sizeof(buffer);
3182 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3183 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3184 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
3185 size = sizeof(buffer);
3186 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
3187 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3188 ok(!strcmp( buffer, "Y" ), "expected 'Y', got '%s'\n", buffer);
3189 size = sizeof(buffer);
3190 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
3191 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3192 ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer);
3193 size = sizeof(buffer);
3194 res = RegEnumValueA( hkcr, 3, buffer, &size, NULL, NULL, NULL, NULL );
3195 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3197 res = RegEnumKeyA( hkcr, 0, buffer, size );
3198 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3199 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
3200 res = RegEnumKeyA( hkcr, 1, buffer, size );
3201 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3202 ok(!strcmp( buffer, "B" ), "expected 'B', got '%s'\n", buffer);
3203 res = RegEnumKeyA( hkcr, 2, buffer, size );
3204 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3205 ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer);
3206 res = RegEnumKeyA( hkcr, 3, buffer, size );
3207 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3209 /* delete values/keys from HKCU to test only on HKLM */
3210 RegCloseKey( hkcusub[0] );
3211 RegCloseKey( hkcusub[1] );
3212 delete_key( hkcu );
3213 RegCloseKey( hkcu );
3215 size = sizeof(buffer);
3216 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3217 ok(res == ERROR_KEY_DELETED ||
3218 res == ERROR_NO_SYSTEM_RESOURCES, /* Windows XP */
3219 "expected ERROR_KEY_DELETED, got %d\n", res);
3220 size = sizeof(buffer);
3221 res = RegEnumKeyA( hkcr, 0, buffer, size );
3222 ok(res == ERROR_KEY_DELETED ||
3223 res == ERROR_NO_SYSTEM_RESOURCES, /* Windows XP */
3224 "expected ERROR_KEY_DELETED, got %d\n", res);
3226 /* reopen HKCR handle */
3227 RegCloseKey( hkcr );
3228 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "WineTestCls", &hkcr );
3229 ok(res == ERROR_SUCCESS, "test key not found in hkcr: %d\n", res);
3230 if (res) goto cleanup;
3232 /* test on values/keys in HKLM */
3233 size = sizeof(buffer);
3234 res = RegEnumValueA( hkcr, 0, buffer, &size, NULL, NULL, NULL, NULL );
3235 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3236 ok(!strcmp( buffer, "X" ), "expected 'X', got '%s'\n", buffer);
3237 size = sizeof(buffer);
3238 res = RegEnumValueA( hkcr, 1, buffer, &size, NULL, NULL, NULL, NULL );
3239 ok(res == ERROR_SUCCESS, "RegEnumValueA failed: %d\n", res );
3240 ok(!strcmp( buffer, "Z" ), "expected 'Z', got '%s'\n", buffer);
3241 size = sizeof(buffer);
3242 res = RegEnumValueA( hkcr, 2, buffer, &size, NULL, NULL, NULL, NULL );
3243 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3245 res = RegEnumKeyA( hkcr, 0, buffer, size );
3246 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3247 ok(!strcmp( buffer, "A" ), "expected 'A', got '%s'\n", buffer);
3248 res = RegEnumKeyA( hkcr, 1, buffer, size );
3249 ok(res == ERROR_SUCCESS, "RegEnumKey failed: %d\n", res );
3250 ok(!strcmp( buffer, "C" ), "expected 'C', got '%s'\n", buffer);
3251 res = RegEnumKeyA( hkcr, 2, buffer, size );
3252 ok(res == ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n", res );
3254 cleanup:
3255 RegCloseKey( hklmsub[0] );
3256 RegCloseKey( hklmsub[1] );
3257 delete_key( hklm );
3258 RegCloseKey( hklm );
3259 RegCloseKey( hkcr );
3262 static void test_classesroot_mask(void)
3264 HKEY hkey;
3265 LSTATUS res;
3267 res = RegOpenKeyA( HKEY_CLASSES_ROOT, "CLSID", &hkey );
3268 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3269 todo_wine ok(IS_HKCR(hkey) || broken(!IS_HKCR(hkey)) /* WinNT */,
3270 "hkcr mask not set in %p\n", hkey);
3271 RegCloseKey( hkey );
3273 res = RegOpenKeyA( HKEY_CURRENT_USER, "Software", &hkey );
3274 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3275 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3276 RegCloseKey( hkey );
3278 res = RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software", &hkey );
3279 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3280 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3281 RegCloseKey( hkey );
3283 res = RegOpenKeyA( HKEY_USERS, ".Default", &hkey );
3284 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3285 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3286 RegCloseKey( hkey );
3288 res = RegOpenKeyA( HKEY_CURRENT_CONFIG, "Software", &hkey );
3289 ok(res == ERROR_SUCCESS, "RegOpenKeyA failed: %d\n", res);
3290 ok(!IS_HKCR(hkey), "hkcr mask set in %p\n", hkey);
3291 RegCloseKey( hkey );
3294 static void test_deleted_key(void)
3296 HKEY hkey, hkey2;
3297 char value[20];
3298 DWORD val_count, type;
3299 LONG res;
3301 /* Open the test key, then delete it while it's open */
3302 RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey );
3304 delete_key( hkey_main );
3306 val_count = sizeof(value);
3307 type = 0;
3308 res = RegEnumValueA( hkey, 0, value, &val_count, NULL, &type, 0, 0 );
3309 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3311 res = RegEnumKeyA( hkey, 0, value, sizeof(value) );
3312 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3314 val_count = sizeof(value);
3315 type = 0;
3316 res = RegQueryValueExA( hkey, "test", NULL, &type, (BYTE *)value, &val_count );
3317 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3319 res = RegSetValueExA( hkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
3320 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3322 res = RegOpenKeyA( hkey, "test", &hkey2 );
3323 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3324 if (res == 0)
3325 RegCloseKey( hkey2 );
3327 res = RegCreateKeyA( hkey, "test", &hkey2 );
3328 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3329 if (res == 0)
3330 RegCloseKey( hkey2 );
3332 res = RegFlushKey( hkey );
3333 ok(res == ERROR_KEY_DELETED, "expect ERROR_KEY_DELETED, got %i\n", res);
3335 RegCloseKey( hkey );
3337 setup_main_key();
3340 static void test_delete_value(void)
3342 LONG res;
3343 char longname[401];
3345 res = RegSetValueExA( hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6 );
3346 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
3348 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
3349 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
3351 res = RegDeleteValueA( hkey_main, "test" );
3352 ok(res == ERROR_SUCCESS, "expect ERROR_SUCCESS, got %i\n", res);
3354 res = RegQueryValueExA( hkey_main, "test", NULL, NULL, NULL, NULL);
3355 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
3357 res = RegDeleteValueA( hkey_main, "test" );
3358 ok(res == ERROR_FILE_NOT_FOUND, "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
3360 memset(longname, 'a', 400);
3361 longname[400] = 0;
3362 res = RegDeleteValueA( hkey_main, longname );
3363 ok(res == ERROR_FILE_NOT_FOUND || broken(res == ERROR_MORE_DATA), /* nt4, win2k */
3364 "expect ERROR_FILE_NOT_FOUND, got %i\n", res);
3366 /* Default registry value */
3367 res = RegSetValueExA(hkey_main, "", 0, REG_SZ, (const BYTE *)"value", 6);
3368 ok(res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
3370 res = RegQueryValueExA(hkey_main, "", NULL, NULL, NULL, NULL);
3371 ok(res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
3373 res = RegDeleteValueA(hkey_main, "" );
3374 ok(res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", res);
3376 res = RegQueryValueExA(hkey_main, "", NULL, NULL, NULL, NULL);
3377 ok(res == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", res);
3380 static void test_delete_key_value(void)
3382 HKEY subkey;
3383 LONG ret;
3385 if (!pRegDeleteKeyValueA)
3387 win_skip("RegDeleteKeyValue is not available.\n");
3388 return;
3391 ret = pRegDeleteKeyValueA(NULL, NULL, NULL);
3392 ok(ret == ERROR_INVALID_HANDLE, "got %d\n", ret);
3394 ret = pRegDeleteKeyValueA(hkey_main, NULL, NULL);
3395 ok(ret == ERROR_FILE_NOT_FOUND, "got %d\n", ret);
3397 ret = RegSetValueExA(hkey_main, "test", 0, REG_SZ, (const BYTE*)"value", 6);
3398 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3400 ret = RegQueryValueExA(hkey_main, "test", NULL, NULL, NULL, NULL);
3401 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3403 /* NULL subkey name means delete from open key */
3404 ret = pRegDeleteKeyValueA(hkey_main, NULL, "test");
3405 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3407 ret = RegQueryValueExA(hkey_main, "test", NULL, NULL, NULL, NULL);
3408 ok(ret == ERROR_FILE_NOT_FOUND, "got %d\n", ret);
3410 /* now with real subkey */
3411 ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_WRITE|KEY_READ, NULL, &subkey, NULL);
3412 ok(!ret, "failed with error %d\n", ret);
3414 ret = RegSetValueExA(subkey, "test", 0, REG_SZ, (const BYTE*)"value", 6);
3415 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3417 ret = RegQueryValueExA(subkey, "test", NULL, NULL, NULL, NULL);
3418 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3420 ret = pRegDeleteKeyValueA(hkey_main, "Subkey1", "test");
3421 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3423 ret = RegQueryValueExA(subkey, "test", NULL, NULL, NULL, NULL);
3424 ok(ret == ERROR_FILE_NOT_FOUND, "got %d\n", ret);
3426 /* Default registry value */
3427 ret = RegSetValueExA(subkey, "", 0, REG_SZ, (const BYTE *)"value", 6);
3428 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3430 ret = RegQueryValueExA(subkey, "", NULL, NULL, NULL, NULL);
3431 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3433 ret = pRegDeleteKeyValueA(hkey_main, "Subkey1", "" );
3434 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3436 ret = RegQueryValueExA(subkey, "", NULL, NULL, NULL, NULL);
3437 ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", ret);
3439 RegDeleteKeyA(subkey, "");
3440 RegCloseKey(subkey);
3443 static void test_RegOpenCurrentUser(void)
3445 HKEY key;
3446 LONG ret;
3448 key = HKEY_CURRENT_USER;
3449 ret = RegOpenCurrentUser(KEY_READ, &key);
3450 ok(!ret, "got %d, error %d\n", ret, GetLastError());
3451 ok(key != HKEY_CURRENT_USER, "got %p\n", key);
3452 RegCloseKey(key);
3455 struct notify_data {
3456 HKEY key;
3457 DWORD flags;
3458 HANDLE event;
3461 static DWORD WINAPI notify_change_thread(void *arg)
3463 struct notify_data *data = arg;
3464 LONG ret;
3466 ret = RegNotifyChangeKeyValue(data->key, TRUE,
3467 REG_NOTIFY_CHANGE_NAME|data->flags, data->event, TRUE);
3468 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3469 return 0;
3472 static void test_RegNotifyChangeKeyValue(void)
3474 struct notify_data data;
3475 HKEY key, subkey, subsubkey;
3476 HANDLE thread;
3477 HANDLE event;
3478 DWORD dwret;
3479 LONG ret;
3481 event = CreateEventW(NULL, FALSE, TRUE, NULL);
3482 ok(event != NULL, "CreateEvent failed, error %u\n", GetLastError());
3483 ret = RegCreateKeyA(hkey_main, "TestKey", &key);
3484 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3486 ret = RegNotifyChangeKeyValue(key, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, event, TRUE);
3487 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3488 dwret = WaitForSingleObject(event, 0);
3489 ok(dwret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", dwret);
3491 ret = RegCreateKeyA(key, "SubKey", &subkey);
3492 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3493 dwret = WaitForSingleObject(event, 0);
3494 ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret);
3496 /* watching deeper keys */
3497 ret = RegNotifyChangeKeyValue(key, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, event, TRUE);
3498 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3499 dwret = WaitForSingleObject(event, 0);
3500 ok(dwret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", dwret);
3502 ret = RegCreateKeyA(subkey, "SubKey", &subsubkey);
3503 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3504 dwret = WaitForSingleObject(event, 0);
3505 ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret);
3507 /* watching deeper values */
3508 ret = RegNotifyChangeKeyValue(key, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, event, TRUE);
3509 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3510 dwret = WaitForSingleObject(event, 0);
3511 ok(dwret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", dwret);
3513 ret = RegSetValueA(subsubkey, NULL, REG_SZ, "SubSubKeyValue", 0);
3514 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3515 dwret = WaitForSingleObject(event, 0);
3516 ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret);
3518 /* don't watch deeper values */
3519 RegCloseKey(key);
3520 ret = RegOpenKeyA(hkey_main, "TestKey", &key);
3521 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3523 ret = RegNotifyChangeKeyValue(key, FALSE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, event, TRUE);
3524 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3525 dwret = WaitForSingleObject(event, 0);
3526 ok(dwret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", dwret);
3528 ret = RegSetValueA(subsubkey, NULL, REG_SZ, "SubSubKeyValueNEW", 0);
3529 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3530 dwret = WaitForSingleObject(event, 0);
3531 ok(dwret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", dwret);
3533 RegDeleteKeyA(subkey, "SubKey");
3534 RegDeleteKeyA(key, "SubKey");
3535 RegCloseKey(subsubkey);
3536 RegCloseKey(subkey);
3537 RegCloseKey(key);
3539 /* test same thread with REG_NOTIFY_THREAD_AGNOSTIC */
3540 ret = RegOpenKeyA(hkey_main, "TestKey", &key);
3541 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3542 ret = RegNotifyChangeKeyValue(key, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_THREAD_AGNOSTIC,
3543 event, TRUE);
3544 if (ret == ERROR_INVALID_PARAMETER)
3546 win_skip("REG_NOTIFY_THREAD_AGNOSTIC is not supported\n");
3547 RegCloseKey(key);
3548 CloseHandle(event);
3549 return;
3552 ret = RegCreateKeyA(key, "SubKey", &subkey);
3553 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3554 dwret = WaitForSingleObject(event, 0);
3555 ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret);
3557 RegDeleteKeyA(key, "SubKey");
3558 RegCloseKey(subkey);
3559 RegCloseKey(key);
3561 /* test different thread without REG_NOTIFY_THREAD_AGNOSTIC */
3562 ret = RegOpenKeyA(hkey_main, "TestKey", &key);
3563 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3565 data.key = key;
3566 data.flags = 0;
3567 data.event = event;
3568 thread = CreateThread(NULL, 0, notify_change_thread, &data, 0, NULL);
3569 WaitForSingleObject(thread, INFINITE);
3570 CloseHandle(thread);
3572 /* the thread exiting causes event to signal on Windows
3573 this is worked around on Windows using REG_NOTIFY_THREAD_AGNOSTIC
3574 Wine already behaves as if the flag is set */
3575 dwret = WaitForSingleObject(event, 0);
3576 todo_wine
3577 ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret);
3578 RegCloseKey(key);
3580 /* test different thread with REG_NOTIFY_THREAD_AGNOSTIC */
3581 ret = RegOpenKeyA(hkey_main, "TestKey", &key);
3582 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3584 data.flags = REG_NOTIFY_THREAD_AGNOSTIC;
3585 thread = CreateThread(NULL, 0, notify_change_thread, &data, 0, NULL);
3586 WaitForSingleObject(thread, INFINITE);
3587 CloseHandle(thread);
3589 dwret = WaitForSingleObject(event, 0);
3590 ok(dwret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", dwret);
3592 ret = RegCreateKeyA(key, "SubKey", &subkey);
3593 ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
3595 dwret = WaitForSingleObject(event, 0);
3596 ok(dwret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", dwret);
3598 RegDeleteKeyA(key, "SubKey");
3599 RegDeleteKeyA(key, "");
3600 RegCloseKey(subkey);
3601 RegCloseKey(key);
3602 CloseHandle(event);
3605 #define cmp_li(a, b, c) cmp_li_real(a, b, c, __LINE__)
3606 static void cmp_li_real(LARGE_INTEGER *l1, LARGE_INTEGER *l2, LONGLONG slack, int line)
3608 LONGLONG diff = l2->QuadPart - l1->QuadPart;
3609 if (diff < 0) diff = -diff;
3610 ok_(__FILE__, line)(diff <= slack, "values don't match: %s/%s\n",
3611 wine_dbgstr_longlong(l1->QuadPart), wine_dbgstr_longlong(l2->QuadPart));
3614 static void test_RegQueryValueExPerformanceData(void)
3616 static const WCHAR globalW[] = { 'G','l','o','b','a','l',0 };
3617 static const WCHAR dummyW[5] = { 'd','u','m','m','y' };
3618 static const char * const names[] = { NULL, "", "Global", "2", "invalid counter name" };
3619 DWORD cbData, len, i, type;
3620 BYTE *value;
3621 DWORD dwret;
3622 LONG limit = 6;
3623 PERF_DATA_BLOCK *pdb;
3624 HKEY hkey;
3625 BYTE buf[256 + sizeof(PERF_DATA_BLOCK)];
3627 /* Test with data == NULL */
3628 dwret = RegQueryValueExA( HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, NULL, &cbData );
3629 ok( dwret == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", dwret );
3631 dwret = RegQueryValueExW( HKEY_PERFORMANCE_DATA, globalW, NULL, NULL, NULL, &cbData );
3632 ok( dwret == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", dwret );
3634 /* Test ERROR_MORE_DATA, start with small buffer */
3635 len = 10;
3636 value = HeapAlloc(GetProcessHeap(), 0, len);
3637 cbData = len;
3638 type = 0xdeadbeef;
3639 dwret = RegQueryValueExA( HKEY_PERFORMANCE_DATA, "Global", NULL, &type, value, &cbData );
3640 ok( dwret == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", dwret );
3641 ok(type == REG_BINARY, "got %u\n", type);
3642 while( dwret == ERROR_MORE_DATA && limit)
3644 len = len * 10;
3645 value = HeapReAlloc( GetProcessHeap(), 0, value, len );
3646 cbData = len;
3647 type = 0xdeadbeef;
3648 dwret = RegQueryValueExA( HKEY_PERFORMANCE_DATA, "Global", NULL, &type, value, &cbData );
3649 limit--;
3651 ok(limit > 0, "too many times ERROR_MORE_DATA returned\n");
3653 ok(dwret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", dwret);
3654 ok(type == REG_BINARY, "got %u\n", type);
3656 /* Check returned data */
3657 if (dwret == ERROR_SUCCESS)
3659 ok(len >= sizeof(PERF_DATA_BLOCK), "got size %d\n", len);
3660 if (len >= sizeof(PERF_DATA_BLOCK)) {
3661 pdb = (PERF_DATA_BLOCK*) value;
3662 ok(pdb->Signature[0] == 'P', "expected Signature[0] = 'P', got 0x%x\n", pdb->Signature[0]);
3663 ok(pdb->Signature[1] == 'E', "expected Signature[1] = 'E', got 0x%x\n", pdb->Signature[1]);
3664 ok(pdb->Signature[2] == 'R', "expected Signature[2] = 'R', got 0x%x\n", pdb->Signature[2]);
3665 ok(pdb->Signature[3] == 'F', "expected Signature[3] = 'F', got 0x%x\n", pdb->Signature[3]);
3666 /* TODO: check other field */
3670 HeapFree(GetProcessHeap(), 0, value);
3672 for (i = 0; i < ARRAY_SIZE(names); i++)
3674 cbData = 0xdeadbeef;
3675 dwret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, names[i], NULL, NULL, NULL, &cbData);
3676 ok(dwret == ERROR_MORE_DATA, "%u/%s: got %u\n", i, names[i], dwret);
3677 ok(cbData == 0, "got %u\n", cbData);
3679 cbData = 0;
3680 dwret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, names[i], NULL, NULL, NULL, &cbData);
3681 ok(dwret == ERROR_MORE_DATA, "%u/%s: got %u\n", i, names[i], dwret);
3682 ok(cbData == 0, "got %u\n", cbData);
3684 cbData = 0xdeadbeef;
3685 dwret = RegQueryValueExA(HKEY_PERFORMANCE_TEXT, names[i], NULL, NULL, NULL, &cbData);
3686 todo_wine
3687 ok(dwret == ERROR_MORE_DATA, "%u/%s: got %u\n", i, names[i], dwret);
3688 ok(cbData == 0, "got %u\n", cbData);
3690 cbData = 0;
3691 dwret = RegQueryValueExA(HKEY_PERFORMANCE_TEXT, names[i], NULL, NULL, NULL, &cbData);
3692 todo_wine
3693 ok(dwret == ERROR_MORE_DATA, "%u/%s: got %u\n", i, names[i], dwret);
3694 ok(cbData == 0, "got %u\n", cbData);
3696 cbData = 0xdeadbeef;
3697 dwret = RegQueryValueExA(HKEY_PERFORMANCE_NLSTEXT, names[i], NULL, NULL, NULL, &cbData);
3698 todo_wine
3699 ok(dwret == ERROR_MORE_DATA, "%u/%s: got %u\n", i, names[i], dwret);
3700 ok(cbData == 0, "got %u\n", cbData);
3702 cbData = 0;
3703 dwret = RegQueryValueExA(HKEY_PERFORMANCE_NLSTEXT, names[i], NULL, NULL, NULL, &cbData);
3704 todo_wine
3705 ok(dwret == ERROR_MORE_DATA, "%u/%s: got %u\n", i, names[i], dwret);
3706 ok(cbData == 0, "got %u\n", cbData);
3709 memset(buf, 0x77, sizeof(buf));
3710 type = 0xdeadbeef;
3711 cbData = sizeof(buf);
3712 dwret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "invalid counter name", NULL, &type, buf, &cbData);
3713 ok(dwret == ERROR_SUCCESS, "got %u\n", dwret);
3714 ok(type == REG_BINARY, "got %u\n", type);
3715 if (dwret == ERROR_SUCCESS)
3717 SYSTEMTIME st;
3718 WCHAR sysname[MAX_COMPUTERNAME_LENGTH + 1];
3719 DWORD sysname_len;
3720 LARGE_INTEGER counter, freq, ftime;
3722 GetSystemTime(&st);
3723 GetSystemTimeAsFileTime((FILETIME *)&ftime);
3724 QueryPerformanceCounter(&counter);
3725 QueryPerformanceFrequency(&freq);
3727 sysname_len = MAX_COMPUTERNAME_LENGTH + 1;
3728 GetComputerNameW(sysname, &sysname_len);
3730 pdb = (PERF_DATA_BLOCK *)buf;
3731 ok(pdb->Signature[0] == 'P', "got '%c'\n", pdb->Signature[0]);
3732 ok(pdb->Signature[1] == 'E', "got '%c'\n", pdb->Signature[1]);
3733 ok(pdb->Signature[2] == 'R', "got '%c'\n", pdb->Signature[2]);
3734 ok(pdb->Signature[3] == 'F', "got '%c'\n", pdb->Signature[3]);
3736 ok(pdb->LittleEndian == 1, "got %u\n", pdb->LittleEndian);
3737 ok(pdb->Version == 1, "got %u\n", pdb->Version);
3738 ok(pdb->Revision == 1, "got %u\n", pdb->Revision);
3739 len = (sizeof(*pdb) + pdb->SystemNameLength + 7) & ~7;
3740 ok(pdb->TotalByteLength == len, "got %u vs %u\n", pdb->TotalByteLength, len);
3741 ok(pdb->HeaderLength == pdb->TotalByteLength, "got %u\n", pdb->HeaderLength);
3742 ok(pdb->NumObjectTypes == 0, "got %u\n", pdb->NumObjectTypes);
3743 todo_wine
3744 ok(pdb->DefaultObject != 0, "got %u\n", pdb->DefaultObject);
3745 ok(pdb->SystemTime.wYear == st.wYear, "got %u\n", pdb->SystemTime.wYear);
3746 ok(pdb->SystemTime.wMonth == st.wMonth, "got %u\n", pdb->SystemTime.wMonth);
3747 ok(pdb->SystemTime.wDayOfWeek == st.wDayOfWeek, "got %u\n", pdb->SystemTime.wDayOfWeek);
3748 ok(pdb->SystemTime.wDay == st.wDay, "got %u\n", pdb->SystemTime.wDay);
3749 if (U(pdb->PerfTime).LowPart != 0x77777777) /* TestBot is broken */
3750 cmp_li(&pdb->PerfTime, &counter, freq.QuadPart);
3751 if (U(pdb->PerfFreq).LowPart != 0x77777777) /* TestBot is broken */
3752 cmp_li(&pdb->PerfFreq, &freq, 0);
3753 cmp_li(&pdb->PerfTime100nSec, &ftime, 200000); /* TestBot needs huge slack value */
3754 ok(pdb->SystemNameLength == (sysname_len + 1) * sizeof(WCHAR), "expected %u, got %u\n",
3755 (sysname_len + 1) * 2 /*sizeof(WCHAR)*/, pdb->SystemNameLength);
3756 ok(pdb->SystemNameOffset == sizeof(*pdb), "got %u\n", pdb->SystemNameOffset);
3757 ok(!lstrcmpW(sysname, (LPCWSTR)(pdb + 1)), "%s != %s\n",
3758 wine_dbgstr_w(sysname), wine_dbgstr_w((LPCWSTR)(pdb + 1)));
3760 len = pdb->TotalByteLength - (sizeof(*pdb) + pdb->SystemNameLength);
3761 if (len)
3763 BYTE remainder[8], *p;
3765 memset(remainder, 0x77, sizeof(remainder));
3766 p = buf + sizeof(*pdb) + pdb->SystemNameLength;
3767 ok(!memcmp(p, remainder, len), "remainder: %02x,%02x...\n", p[0], p[1]);
3771 dwret = RegOpenKeyA(HKEY_PERFORMANCE_DATA, NULL, &hkey);
3772 todo_wine
3773 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3775 dwret = RegOpenKeyA(HKEY_PERFORMANCE_DATA, "Global", &hkey);
3776 todo_wine
3777 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3779 dwret = RegOpenKeyExA(HKEY_PERFORMANCE_DATA, "Global", 0, KEY_READ, &hkey);
3780 todo_wine
3781 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3783 dwret = RegQueryValueA(HKEY_PERFORMANCE_DATA, "Global", NULL, (LONG *)&cbData);
3784 todo_wine
3785 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3787 dwret = RegSetValueA(HKEY_PERFORMANCE_DATA, "Global", REG_SZ, "dummy", 4);
3788 todo_wine
3789 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3791 dwret = RegSetValueExA(HKEY_PERFORMANCE_DATA, "Global", 0, REG_SZ, (const BYTE *)"dummy", 40);
3792 todo_wine
3793 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3795 cbData = sizeof(buf);
3796 dwret = RegEnumKeyA(HKEY_PERFORMANCE_DATA, 0, (LPSTR)buf, cbData);
3797 todo_wine
3798 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3800 cbData = sizeof(buf);
3801 dwret = RegEnumValueA(HKEY_PERFORMANCE_DATA, 0, (LPSTR)buf, &cbData, NULL, NULL, NULL, NULL);
3802 todo_wine
3803 ok(dwret == ERROR_MORE_DATA, "got %u\n", dwret);
3804 todo_wine
3805 ok(cbData == sizeof(buf), "got %u\n", cbData);
3807 dwret = RegEnumValueA(HKEY_PERFORMANCE_DATA, 0, NULL, &cbData, NULL, NULL, NULL, NULL);
3808 ok(dwret == ERROR_INVALID_PARAMETER, "got %u\n", dwret);
3810 if (pRegSetKeyValueW)
3812 dwret = pRegSetKeyValueW(HKEY_PERFORMANCE_DATA, NULL, globalW, REG_SZ, dummyW, sizeof(dummyW));
3813 todo_wine
3814 ok(dwret == ERROR_INVALID_HANDLE, "got %u\n", dwret);
3817 dwret = RegCloseKey(HKEY_PERFORMANCE_DATA);
3818 ok(dwret == ERROR_SUCCESS, "got %u\n", dwret);
3821 static void test_RegLoadMUIString(void)
3823 HMODULE hUser32, hResDll, hFile;
3824 int (WINAPI *pLoadStringW)(HMODULE, UINT, WCHAR *, int);
3825 LONG ret;
3826 HKEY hkey;
3827 DWORD type, size, text_size;
3828 UINT i;
3829 char buf[64], *p, sysdir[MAX_PATH];
3830 char with_env_var[128], filename[MAX_PATH], tmp_path[MAX_PATH];
3831 WCHAR textW[64], bufW[64];
3832 WCHAR curdirW[MAX_PATH], sysdirW[MAX_PATH];
3833 const static char tz_value[] = "MUI_Std";
3834 const static WCHAR tz_valueW[] = {'M','U','I','_','S','t','d', 0};
3835 struct {
3836 const char* value;
3837 DWORD type;
3838 BOOL use_sysdir;
3839 DWORD expected;
3840 DWORD broken_ret;
3841 } test_case[] = {
3842 /* 0 */
3843 { "", REG_SZ, FALSE, ERROR_INVALID_DATA },
3844 { "not a MUI string", REG_SZ, FALSE, ERROR_INVALID_DATA },
3845 { "@unknown.dll", REG_SZ, TRUE, ERROR_INVALID_DATA },
3846 { "@unknown.dll,-10", REG_SZ, TRUE, ERROR_FILE_NOT_FOUND },
3847 /* 4 */
3848 { with_env_var, REG_SZ, FALSE, ERROR_SUCCESS },
3849 { with_env_var, REG_EXPAND_SZ, FALSE, ERROR_SUCCESS },
3850 { "%WineMuiTest1%", REG_EXPAND_SZ, TRUE, ERROR_INVALID_DATA },
3851 { "@%WineMuiTest2%", REG_EXPAND_SZ, TRUE, ERROR_SUCCESS },
3852 /* 8 */
3853 { "@%WineMuiExe%,a", REG_SZ, FALSE, ERROR_INVALID_DATA },
3854 { "@%WineMuiExe%,-4", REG_SZ, FALSE, ERROR_NOT_FOUND, ERROR_FILE_NOT_FOUND },
3855 { "@%WineMuiExe%,-39", REG_SZ, FALSE, ERROR_RESOURCE_NAME_NOT_FOUND },
3856 { "@%WineMuiDat%,-16", REG_EXPAND_SZ, FALSE, ERROR_BAD_EXE_FORMAT, ERROR_FILE_NOT_FOUND },
3859 if (!pRegLoadMUIStringA || !pRegLoadMUIStringW)
3861 win_skip("RegLoadMUIString is not available\n");
3862 return;
3865 hUser32 = LoadLibraryA("user32.dll");
3866 ok(hUser32 != NULL, "cannot load user32.dll\n");
3867 pLoadStringW = (void *)GetProcAddress(hUser32, "LoadStringW");
3868 ok(pLoadStringW != NULL, "failed to get LoadStringW address\n");
3870 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
3871 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\UTC", 0,
3872 KEY_READ, &hkey);
3873 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3875 size = ARRAY_SIZE(buf);
3876 ret = RegQueryValueExA(hkey, tz_value, NULL, &type, (BYTE *)buf, &size);
3877 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
3878 ok(buf[0] == '@', "got %s\n", buf);
3880 /* setup MUI string for tests */
3881 strcpy(with_env_var, "@%windir%\\system32\\");
3882 strcat(with_env_var, &buf[1]);
3883 SetEnvironmentVariableA("WineMuiTest1", buf);
3884 SetEnvironmentVariableA("WineMuiTest2", &buf[1]);
3886 /* load expecting text */
3887 p = strrchr(buf, ',');
3888 *p = '\0';
3889 i = atoi(p + 2); /* skip ',-' */
3890 hResDll = LoadLibraryExA(&buf[1], NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
3891 memset(textW, 0xaa, sizeof(textW));
3892 ret = pLoadStringW(hResDll, i, textW, ARRAY_SIZE(textW));
3893 ok(ret > 0, "failed to load string resource\n");
3894 text_size = (ret + 1) * sizeof(WCHAR);
3895 FreeLibrary(hResDll);
3896 FreeLibrary(hUser32);
3898 ret = GetSystemDirectoryW(sysdirW, ARRAY_SIZE(sysdirW));
3899 ok(ret > 0, "GetSystemDirectoryW failed\n");
3900 ret = GetSystemDirectoryA(sysdir, ARRAY_SIZE(sysdir));
3901 ok(ret > 0, "GetSystemDirectoryA failed\n");
3903 /* change the current directory to system32 */
3904 GetCurrentDirectoryW(ARRAY_SIZE(curdirW), curdirW);
3905 SetCurrentDirectoryW(sysdirW);
3907 size = 0xdeadbeef;
3908 ret = pRegLoadMUIStringW(hkey, tz_valueW, NULL, 0, &size, 0, NULL);
3909 ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret);
3910 ok(size == text_size, "got %u, expected %u\n", size, text_size);
3912 memset(bufW, 0xff, sizeof(bufW));
3913 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)+1, &size, 0, NULL);
3914 ok(ret == ERROR_INVALID_PARAMETER, "got %d, expected ERROR_INVALID_PARAMETER\n", ret);
3915 ok(bufW[0] == 0xffff, "got 0x%04x, expected 0xffff\n", bufW[0]);
3917 size = 0xdeadbeef;
3918 memset(bufW, 0xff, sizeof(bufW));
3919 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)*2, &size, 0, NULL);
3920 ok(ret == ERROR_MORE_DATA, "got %d, expected ERROR_MORE_DATA\n", ret);
3921 ok(size == text_size || broken(size == text_size + sizeof(WCHAR) /* vista */),
3922 "got %u, expected %u\n", size, text_size);
3923 ok(bufW[0] == 0xffff, "got 0x%04x, expected 0xffff\n", bufW[0]);
3925 memset(bufW, 0xff, sizeof(bufW));
3926 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)*2, &size, REG_MUI_STRING_TRUNCATE, NULL);
3927 ok(ret == ERROR_INVALID_PARAMETER, "got %d, expected ERROR_INVALID_PARAMETER\n", ret);
3928 ok(bufW[0] == 0xffff, "got 0x%04x, expected 0xffff\n", bufW[0]);
3930 memset(bufW, 0xff, sizeof(bufW));
3931 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)*2, NULL, 0xdeadbeef, NULL);
3932 ok(ret == ERROR_INVALID_PARAMETER, "got %d, expected ERROR_INVALID_PARAMETER\n", ret);
3933 ok(bufW[0] == 0xffff, "got 0x%04x, expected 0xffff\n", bufW[0]);
3935 memset(bufW, 0xff, sizeof(bufW));
3936 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, sizeof(WCHAR)*2, NULL, REG_MUI_STRING_TRUNCATE, NULL);
3937 ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret);
3938 ok(bufW[0] == textW[0], "got 0x%04x, expected 0x%04x\n", bufW[0], textW[0]);
3939 ok(bufW[1] == 0, "got 0x%04x, expected nul\n", bufW[1]);
3941 size = 0xdeadbeef;
3942 memset(bufW, 0xff, sizeof(bufW));
3943 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, NULL);
3944 ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret);
3945 ok(size == text_size, "got %u, expected %u\n", size, text_size);
3946 ok(!memcmp(textW, bufW, size), "got %s, expected %s\n",
3947 wine_dbgstr_wn(bufW, size / sizeof(WCHAR)), wine_dbgstr_wn(textW, text_size / sizeof(WCHAR)));
3949 ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, NULL);
3950 ok(ret == ERROR_CALL_NOT_IMPLEMENTED, "got %d, expected ERROR_CALL_NOT_IMPLEMENTED\n", ret);
3952 /* change the current directory to other than system32 directory */
3953 SetCurrentDirectoryA("\\");
3955 size = 0xdeadbeef;
3956 memset(bufW, 0xff, sizeof(bufW));
3957 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, sysdirW);
3958 ok(ret == ERROR_SUCCESS, "got %d, expected ERROR_SUCCESS\n", ret);
3959 ok(size == text_size, "got %u, expected %u\n", size, text_size);
3960 ok(!memcmp(textW, bufW, size), "got %s, expected %s\n",
3961 wine_dbgstr_wn(bufW, size / sizeof(WCHAR)), wine_dbgstr_wn(textW, text_size / sizeof(WCHAR)));
3963 ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, sysdir);
3964 ok(ret == ERROR_CALL_NOT_IMPLEMENTED, "got %d, expected ERROR_CALL_NOT_IMPLEMENTED\n", ret);
3966 ret = pRegLoadMUIStringW(hkey, tz_valueW, bufW, ARRAY_SIZE(bufW), &size, 0, NULL);
3967 ok(ret == ERROR_FILE_NOT_FOUND, "got %d, expected ERROR_FILE_NOT_FOUND\n", ret);
3969 ret = pRegLoadMUIStringA(hkey, tz_value, buf, ARRAY_SIZE(buf), &size, 0, NULL);
3970 ok(ret == ERROR_CALL_NOT_IMPLEMENTED, "got %d, expected ERROR_CALL_NOT_IMPLEMENTED\n", ret);
3972 RegCloseKey(hkey);
3974 GetModuleFileNameA(NULL, filename, ARRAY_SIZE(filename));
3975 SetEnvironmentVariableA("WineMuiExe", filename);
3977 GetTempPathA(ARRAY_SIZE(tmp_path), tmp_path);
3978 GetTempFileNameA(tmp_path, "mui", 0, filename);
3979 SetEnvironmentVariableA("WineMuiDat", filename);
3981 /* write dummy data to the file, i.e. it's not a PE file. */
3982 hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
3983 ok(hFile != INVALID_HANDLE_VALUE, "can't open %s\n", filename);
3984 WriteFile(hFile, filename, strlen(filename), &size, NULL);
3985 CloseHandle(hFile);
3987 for (i = 0; i < ARRAY_SIZE(test_case); i++)
3989 size = test_case[i].value ? strlen(test_case[i].value) + 1 : 0;
3990 ret = RegSetValueExA(hkey_main, tz_value, 0, test_case[i].type,
3991 (const BYTE *)test_case[i].value, size);
3992 ok(ret == ERROR_SUCCESS, "[%2u] got %d\n", i, ret);
3994 size = 0xdeadbeef;
3995 memset(bufW, 0xff, sizeof(bufW));
3996 ret = pRegLoadMUIStringW(hkey_main, tz_valueW, bufW, ARRAY_SIZE(bufW),
3997 &size, 0,
3998 test_case[i].use_sysdir ? sysdirW : NULL);
3999 ok(ret == test_case[i].expected ||
4000 broken(test_case[i].value[0] == '%' && ret == ERROR_SUCCESS /* vista */) ||
4001 broken(test_case[i].broken_ret && ret == test_case[i].broken_ret /* vista */),
4002 "[%2u] expected %d, got %d\n", i, test_case[i].expected, ret);
4003 if (ret == ERROR_SUCCESS && test_case[i].expected == ERROR_SUCCESS)
4005 ok(size == text_size, "[%2u] got %u, expected %u\n", i, size, text_size);
4006 ok(!memcmp(bufW, textW, size), "[%2u] got %s, expected %s\n", i,
4007 wine_dbgstr_wn(bufW, size/sizeof(WCHAR)),
4008 wine_dbgstr_wn(textW, text_size/sizeof(WCHAR)));
4012 SetCurrentDirectoryW(curdirW);
4013 DeleteFileA(filename);
4014 SetEnvironmentVariableA("WineMuiTest1", NULL);
4015 SetEnvironmentVariableA("WineMuiTest2", NULL);
4016 SetEnvironmentVariableA("WineMuiExe", NULL);
4017 SetEnvironmentVariableA("WineMuiDat", NULL);
4020 static void test_EnumDynamicTimeZoneInformation(void)
4022 LSTATUS status;
4023 HKEY key, subkey;
4024 WCHAR name[32];
4025 WCHAR keyname[128];
4026 WCHAR sysdir[MAX_PATH];
4027 DWORD index, ret, gle, size;
4028 DYNAMIC_TIME_ZONE_INFORMATION bogus_dtzi, dtzi;
4029 static const WCHAR stdW[] = {'S','t','d',0};
4030 static const WCHAR dltW[] = {'D','l','t',0};
4031 static const WCHAR tziW[] = {'T','Z','I',0};
4032 static const WCHAR mui_stdW[] = {'M','U','I','_','S','t','d',0};
4033 static const WCHAR mui_dltW[] = {'M','U','I','_','D','l','t',0};
4034 struct tz_reg_data
4036 LONG bias;
4037 LONG std_bias;
4038 LONG dlt_bias;
4039 SYSTEMTIME std_date;
4040 SYSTEMTIME dlt_date;
4041 } tz_data;
4043 if (!pEnumDynamicTimeZoneInformation)
4045 win_skip("EnumDynamicTimeZoneInformation is not supported.\n");
4046 return;
4049 if (pRegLoadMUIStringW)
4050 GetSystemDirectoryW(sysdir, ARRAY_SIZE(sysdir));
4052 SetLastError(0xdeadbeef);
4053 ret = pEnumDynamicTimeZoneInformation(0, NULL);
4054 gle = GetLastError();
4055 ok(gle == 0xdeadbeef, "got 0x%x\n", gle);
4056 ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret);
4058 memset(&bogus_dtzi, 0xcc, sizeof(bogus_dtzi));
4059 memset(&dtzi, 0xcc, sizeof(dtzi));
4060 SetLastError(0xdeadbeef);
4061 ret = pEnumDynamicTimeZoneInformation(-1, &dtzi);
4062 gle = GetLastError();
4063 ok(gle == 0xdeadbeef, "got 0x%x\n", gle);
4064 ok(ret == ERROR_NO_MORE_ITEMS, "got %d\n", ret);
4065 ok(!memcmp(&dtzi, &bogus_dtzi, sizeof(dtzi)), "mismatch\n");
4067 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
4068 "Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", 0,
4069 KEY_ENUMERATE_SUB_KEYS|KEY_QUERY_VALUE, &key);
4070 ok(status == ERROR_SUCCESS, "got %d\n", status);
4071 index = 0;
4072 while (!(status = RegEnumKeyW(key, index, keyname, ARRAY_SIZE(keyname))))
4074 subkey = NULL;
4075 status = RegOpenKeyExW(key, keyname, 0, KEY_QUERY_VALUE, &subkey);
4076 ok(status == ERROR_SUCCESS, "got %d\n", status);
4078 memset(&dtzi, 0xcc, sizeof(dtzi));
4079 SetLastError(0xdeadbeef);
4080 ret = pEnumDynamicTimeZoneInformation(index, &dtzi);
4081 gle = GetLastError();
4082 /* recently added time zones may not have MUI strings */
4083 ok(gle == ERROR_SUCCESS ||
4084 gle == ERROR_RESOURCE_TYPE_NOT_FOUND /* Win10 1809 32-bit */ ||
4085 gle == ERROR_MUI_FILE_NOT_FOUND /* Win10 1809 64-bit */,
4086 "got 0x%x\n", gle);
4087 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
4088 ok(!lstrcmpW(dtzi.TimeZoneKeyName, keyname), "expected %s, got %s\n",
4089 wine_dbgstr_w(keyname), wine_dbgstr_w(dtzi.TimeZoneKeyName));
4091 if (gle == ERROR_SUCCESS)
4093 size = sizeof(name);
4094 memset(name, 0, sizeof(name));
4095 if (pRegLoadMUIStringW)
4096 status = pRegLoadMUIStringW(subkey, mui_stdW, name, size, &size, 0, sysdir);
4097 else
4098 status = pRegGetValueW(subkey, NULL, stdW, RRF_RT_REG_SZ, NULL, name, &size);
4099 ok(status == ERROR_SUCCESS, "status %d name %s\n", status, wine_dbgstr_w(name));
4100 ok(!memcmp(&dtzi.StandardName, name, size),
4101 "expected %s, got %s\n", wine_dbgstr_w(name), wine_dbgstr_w(dtzi.StandardName));
4103 size = sizeof(name);
4104 memset(name, 0, sizeof(name));
4105 if (pRegLoadMUIStringW)
4106 status = pRegLoadMUIStringW(subkey, mui_dltW, name, size, &size, 0, sysdir);
4107 else
4108 status = pRegGetValueW(subkey, NULL, dltW, RRF_RT_REG_SZ, NULL, name, &size);
4109 ok(status == ERROR_SUCCESS, "status %d name %s\n", status, wine_dbgstr_w(name));
4110 ok(!memcmp(&dtzi.DaylightName, name, size),
4111 "expected %s, got %s\n", wine_dbgstr_w(name), wine_dbgstr_w(dtzi.DaylightName));
4113 else
4115 ok(!dtzi.StandardName[0], "expected empty StandardName\n");
4116 ok(!dtzi.DaylightName[0], "expected empty DaylightName\n");
4119 ok(!dtzi.DynamicDaylightTimeDisabled, "got %d\n", dtzi.DynamicDaylightTimeDisabled);
4121 size = sizeof(tz_data);
4122 status = pRegGetValueW(key, keyname, tziW, RRF_RT_REG_BINARY, NULL, &tz_data, &size);
4123 ok(status == ERROR_SUCCESS, "got %d\n", status);
4125 ok(dtzi.Bias == tz_data.bias, "expected %d, got %d\n",
4126 tz_data.bias, dtzi.Bias);
4127 ok(dtzi.StandardBias == tz_data.std_bias, "expected %d, got %d\n",
4128 tz_data.std_bias, dtzi.StandardBias);
4129 ok(dtzi.DaylightBias == tz_data.dlt_bias, "expected %d, got %d\n",
4130 tz_data.dlt_bias, dtzi.DaylightBias);
4132 ok(!memcmp(&dtzi.StandardDate, &tz_data.std_date, sizeof(dtzi.StandardDate)),
4133 "expected %s, got %s\n",
4134 dbgstr_SYSTEMTIME(&tz_data.std_date), dbgstr_SYSTEMTIME(&dtzi.StandardDate));
4136 ok(!memcmp(&dtzi.DaylightDate, &tz_data.dlt_date, sizeof(dtzi.DaylightDate)),
4137 "expected %s, got %s\n",
4138 dbgstr_SYSTEMTIME(&tz_data.dlt_date), dbgstr_SYSTEMTIME(&dtzi.DaylightDate));
4140 RegCloseKey(subkey);
4141 index++;
4143 ok(status == ERROR_NO_MORE_ITEMS, "got %d\n", status);
4145 memset(&dtzi, 0xcc, sizeof(dtzi));
4146 SetLastError(0xdeadbeef);
4147 ret = pEnumDynamicTimeZoneInformation(index, &dtzi);
4148 gle = GetLastError();
4149 ok(gle == 0xdeadbeef, "got 0x%x\n", gle);
4150 ok(ret == ERROR_NO_MORE_ITEMS, "got %d\n", ret);
4151 ok(!memcmp(&dtzi, &bogus_dtzi, sizeof(dtzi)), "mismatch\n");
4153 RegCloseKey(key);
4156 START_TEST(registry)
4158 /* Load pointers for functions that are not available in all Windows versions */
4159 InitFunctionPtrs();
4161 setup_main_key();
4162 check_user_privs();
4163 test_set_value();
4164 create_test_entries();
4165 test_enum_value();
4166 test_query_value_ex();
4167 test_get_value();
4168 test_reg_open_key();
4169 test_reg_create_key();
4170 test_reg_close_key();
4171 test_reg_delete_key();
4172 test_reg_query_value();
4173 test_reg_query_info();
4174 test_string_termination();
4175 test_symlinks();
4176 test_redirection();
4177 test_classesroot();
4178 test_classesroot_enum();
4179 test_classesroot_mask();
4180 test_reg_save_key();
4181 test_reg_load_key();
4182 test_reg_unload_key();
4183 test_reg_copy_tree();
4184 test_reg_delete_tree();
4185 test_rw_order();
4186 test_deleted_key();
4187 test_delete_value();
4188 test_delete_key_value();
4189 test_RegOpenCurrentUser();
4190 test_RegNotifyChangeKeyValue();
4191 test_RegQueryValueExPerformanceData();
4192 test_RegLoadMUIString();
4193 test_EnumDynamicTimeZoneInformation();
4195 /* cleanup */
4196 delete_key( hkey_main );
4198 test_regconnectregistry();