22a46891d49fca5a47b51a8a608031b1725ee075
[reactos.git] / rostests / winetests / wshom / wshom.c
1 /*
2 * Copyright 2011 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COBJMACROS
22 #define CONST_VTABLE
23
24 #include <windef.h>
25 #include <winbase.h>
26 #include <winreg.h>
27 #include <initguid.h>
28 #include <dispex.h>
29 #include <wshom.h>
30 #include <wine/test.h>
31
32 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
33
34 #define EXPECT_HR(hr,hr_exp) \
35 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
36
37 static void test_wshshell(void)
38 {
39 static const WCHAR notepadW[] = {'n','o','t','e','p','a','d','.','e','x','e',0};
40 static const WCHAR desktopW[] = {'D','e','s','k','t','o','p',0};
41 static const WCHAR lnk1W[] = {'f','i','l','e','.','l','n','k',0};
42 static const WCHAR pathW[] = {'%','P','A','T','H','%',0};
43 static const WCHAR sysW[] = {'S','Y','S','T','E','M',0};
44 static const WCHAR path2W[] = {'P','A','T','H',0};
45 static const WCHAR dummydirW[] = {'d','e','a','d','p','a','r','r','o','t',0};
46 static const WCHAR emptyW[] = {'e','m','p','t','y',0};
47 IWshEnvironment *env;
48 IWshExec *shexec;
49 IWshShell3 *sh3;
50 IDispatchEx *dispex;
51 IWshCollection *coll;
52 IDispatch *disp, *shortcut;
53 IUnknown *shell, *unk;
54 IFolderCollection *folders;
55 IWshShortcut *shcut;
56 ITypeInfo *ti;
57 HRESULT hr;
58 TYPEATTR *tattr;
59 DISPPARAMS dp;
60 EXCEPINFO ei;
61 VARIANT arg, res, arg2;
62 BSTR str, ret;
63 DWORD retval;
64 UINT err;
65
66 hr = CoCreateInstance(&CLSID_WshShell, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
67 &IID_IDispatch, (void**)&disp);
68 ok(hr == S_OK, "got 0x%08x\n", hr);
69
70 hr = IDispatch_QueryInterface(disp, &IID_IWshShell3, (void**)&shell);
71 EXPECT_HR(hr, S_OK);
72 IDispatch_Release(disp);
73
74 hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
75 EXPECT_HR(hr, E_NOINTERFACE);
76
77 hr = IUnknown_QueryInterface(shell, &IID_IWshShell3, (void**)&sh3);
78 EXPECT_HR(hr, S_OK);
79
80 hr = IWshShell3_QueryInterface(sh3, &IID_IObjectWithSite, (void**)&unk);
81 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
82
83 hr = IWshShell3_QueryInterface(sh3, &IID_IWshShell, (void**)&unk);
84 ok(hr == S_OK, "got 0x%08x\n", hr);
85 IUnknown_Release(unk);
86
87 hr = IWshShell3_QueryInterface(sh3, &IID_IWshShell2, (void**)&unk);
88 ok(hr == S_OK, "got 0x%08x\n", hr);
89 IUnknown_Release(unk);
90
91 hr = IWshShell3_get_SpecialFolders(sh3, &coll);
92 EXPECT_HR(hr, S_OK);
93
94 hr = IWshCollection_QueryInterface(coll, &IID_IFolderCollection, (void**)&folders);
95 EXPECT_HR(hr, E_NOINTERFACE);
96
97 hr = IWshCollection_QueryInterface(coll, &IID_IDispatch, (void**)&disp);
98 EXPECT_HR(hr, S_OK);
99
100 hr = IDispatch_GetTypeInfo(disp, 0, 0, &ti);
101 EXPECT_HR(hr, S_OK);
102
103 hr = ITypeInfo_GetTypeAttr(ti, &tattr);
104 EXPECT_HR(hr, S_OK);
105 ok(IsEqualIID(&tattr->guid, &IID_IWshCollection), "got wrong type guid\n");
106 ITypeInfo_ReleaseTypeAttr(ti, tattr);
107
108 /* try to call Item() with normal IDispatch procedure */
109 str = SysAllocString(desktopW);
110 V_VT(&arg) = VT_BSTR;
111 V_BSTR(&arg) = str;
112 dp.rgvarg = &arg;
113 dp.rgdispidNamedArgs = NULL;
114 dp.cArgs = 1;
115 dp.cNamedArgs = 0;
116 hr = IDispatch_Invoke(disp, DISPID_VALUE, &IID_NULL, 1033, DISPATCH_PROPERTYGET, &dp, &res, &ei, &err);
117 EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
118
119 /* try Item() directly, it returns directory path apparently */
120 V_VT(&res) = VT_EMPTY;
121 hr = IWshCollection_Item(coll, &arg, &res);
122 EXPECT_HR(hr, S_OK);
123 ok(V_VT(&res) == VT_BSTR, "got res type %d\n", V_VT(&res));
124 SysFreeString(str);
125 VariantClear(&res);
126
127 /* CreateShortcut() */
128 str = SysAllocString(lnk1W);
129 hr = IWshShell3_CreateShortcut(sh3, str, &shortcut);
130 EXPECT_HR(hr, S_OK);
131 SysFreeString(str);
132 hr = IDispatch_QueryInterface(shortcut, &IID_IWshShortcut, (void**)&shcut);
133 EXPECT_HR(hr, S_OK);
134
135 hr = IWshShortcut_get_Arguments(shcut, NULL);
136 ok(hr == E_POINTER, "got 0x%08x\n", hr);
137
138 hr = IWshShortcut_get_IconLocation(shcut, NULL);
139 ok(hr == E_POINTER, "got 0x%08x\n", hr);
140
141 IWshShortcut_Release(shcut);
142 IDispatch_Release(shortcut);
143
144 /* ExpandEnvironmentStrings */
145 hr = IWshShell3_ExpandEnvironmentStrings(sh3, NULL, NULL);
146 ok(hr == E_POINTER, "got 0x%08x\n", hr);
147
148 str = SysAllocString(pathW);
149 hr = IWshShell3_ExpandEnvironmentStrings(sh3, str, NULL);
150 ok(hr == E_POINTER, "got 0x%08x\n", hr);
151 SysFreeString(str);
152
153 V_VT(&arg) = VT_BSTR;
154 V_BSTR(&arg) = SysAllocString(sysW);
155 hr = IWshShell3_get_Environment(sh3, &arg, &env);
156 ok(hr == S_OK, "got 0x%08x\n", hr);
157 VariantClear(&arg);
158
159 hr = IWshEnvironment_get_Item(env, NULL, NULL);
160 ok(hr == E_POINTER, "got 0x%08x\n", hr);
161
162 ret = (BSTR)0x1;
163 hr = IWshEnvironment_get_Item(env, NULL, &ret);
164 ok(hr == S_OK, "got 0x%08x\n", hr);
165 ok(ret && !*ret, "got %p\n", ret);
166 SysFreeString(ret);
167
168 /* invalid var name */
169 str = SysAllocString(lnk1W);
170 hr = IWshEnvironment_get_Item(env, str, NULL);
171 ok(hr == E_POINTER, "got 0x%08x\n", hr);
172
173 ret = NULL;
174 hr = IWshEnvironment_get_Item(env, str, &ret);
175 ok(hr == S_OK, "got 0x%08x\n", hr);
176 ok(ret && *ret == 0, "got %s\n", wine_dbgstr_w(ret));
177 SysFreeString(ret);
178 SysFreeString(str);
179
180 /* valid name */
181 str = SysAllocString(path2W);
182 hr = IWshEnvironment_get_Item(env, str, &ret);
183 ok(hr == S_OK, "got 0x%08x\n", hr);
184 ok(ret && *ret != 0, "got %s\n", wine_dbgstr_w(ret));
185 SysFreeString(ret);
186 SysFreeString(str);
187
188 IWshEnvironment_Release(env);
189
190 V_VT(&arg) = VT_I2;
191 V_I2(&arg) = 0;
192 V_VT(&arg2) = VT_ERROR;
193 V_ERROR(&arg2) = DISP_E_PARAMNOTFOUND;
194
195 str = SysAllocString(notepadW);
196 hr = IWshShell3_Run(sh3, str, &arg, &arg2, NULL);
197 ok(hr == E_POINTER, "got 0x%08x\n", hr);
198
199 retval = 10;
200 hr = IWshShell3_Run(sh3, str, NULL, &arg2, &retval);
201 ok(hr == E_POINTER, "got 0x%08x\n", hr);
202 ok(retval == 10, "got %u\n", retval);
203
204 retval = 10;
205 hr = IWshShell3_Run(sh3, str, &arg, NULL, &retval);
206 ok(hr == E_POINTER, "got 0x%08x\n", hr);
207 ok(retval == 10, "got %u\n", retval);
208
209 retval = 10;
210 V_VT(&arg2) = VT_ERROR;
211 V_ERROR(&arg2) = 0;
212 hr = IWshShell3_Run(sh3, str, &arg, &arg2, &retval);
213 ok(hr == DISP_E_TYPEMISMATCH, "got 0x%08x\n", hr);
214 ok(retval == 10, "got %u\n", retval);
215
216 SysFreeString(str);
217
218 /* current directory */
219 if (0) /* crashes on native */
220 {
221 hr = IWshShell3_get_CurrentDirectory(sh3, NULL);
222 }
223
224 str = NULL;
225 hr = IWshShell3_get_CurrentDirectory(sh3, &str);
226 ok(hr == S_OK, "got 0x%08x\n", hr);
227 ok(str && str[0] != 0, "got empty string\n");
228 SysFreeString(str);
229
230 hr = IWshShell3_put_CurrentDirectory(sh3, NULL);
231 ok(hr == E_INVALIDARG ||
232 broken(hr == HRESULT_FROM_WIN32(ERROR_NOACCESS)), "got 0x%08x\n", hr);
233
234 str = SysAllocString(emptyW);
235 hr = IWshShell3_put_CurrentDirectory(sh3, str);
236 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
237 SysFreeString(str);
238
239 str = SysAllocString(dummydirW);
240 hr = IWshShell3_put_CurrentDirectory(sh3, str);
241 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
242 SysFreeString(str);
243
244 /* Exec */
245 hr = IWshShell3_Exec(sh3, NULL, NULL);
246 ok(hr == E_POINTER, "got 0x%08x\n", hr);
247
248 hr = IWshShell3_Exec(sh3, NULL, &shexec);
249 ok(hr == DISP_E_EXCEPTION, "got 0x%08x\n", hr);
250
251 str = SysAllocString(emptyW);
252 hr = IWshShell3_Exec(sh3, str, &shexec);
253 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
254 SysFreeString(str);
255
256 IWshCollection_Release(coll);
257 IDispatch_Release(disp);
258 IWshShell3_Release(sh3);
259 IUnknown_Release(shell);
260 }
261
262 /* delete key and all its subkeys */
263 static DWORD delete_key(HKEY hkey)
264 {
265 char name[MAX_PATH];
266 DWORD ret;
267
268 while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name)))) {
269 HKEY tmp;
270 if (!(ret = RegOpenKeyExA(hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp))) {
271 ret = delete_key(tmp);
272 RegCloseKey(tmp);
273 }
274 if (ret) break;
275 }
276 if (ret != ERROR_NO_MORE_ITEMS) return ret;
277 RegDeleteKeyA(hkey, "");
278 return 0;
279 }
280
281 static void test_registry(void)
282 {
283 static const WCHAR keypathW[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',
284 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t','\\',0};
285 static const WCHAR regsz2W[] = {'r','e','g','s','z','2',0};
286 static const WCHAR regszW[] = {'r','e','g','s','z',0};
287 static const WCHAR regdwordW[] = {'r','e','g','d','w','o','r','d',0};
288 static const WCHAR regbinaryW[] = {'r','e','g','b','i','n','a','r','y',0};
289 static const WCHAR regmultiszW[] = {'r','e','g','m','u','l','t','i','s','z',0};
290
291 static const WCHAR regsz1W[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',
292 'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t','\\','r','e','g','s','z','1',0};
293 static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
294 static const WCHAR fooW[] = {'f','o','o',0};
295 static const WCHAR brokenW[] = {'H','K','E','Y','_','b','r','o','k','e','n','_','k','e','y',0};
296 static const WCHAR broken2W[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','a',0};
297 WCHAR pathW[MAX_PATH];
298 DWORD dwvalue, type;
299 VARIANT value, v;
300 IWshShell3 *sh3;
301 VARTYPE vartype;
302 LONG bound;
303 HRESULT hr;
304 BSTR name;
305 HKEY root;
306 LONG ret;
307 UINT dim;
308
309 hr = CoCreateInstance(&CLSID_WshShell, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
310 &IID_IWshShell3, (void**)&sh3);
311 ok(hr == S_OK, "got 0x%08x\n", hr);
312
313 /* RegRead() */
314 V_VT(&value) = VT_I2;
315 hr = IWshShell3_RegRead(sh3, NULL, &value);
316 ok(hr == E_POINTER, "got 0x%08x\n", hr);
317 ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
318
319 name = SysAllocString(brokenW);
320 hr = IWshShell3_RegRead(sh3, name, NULL);
321 ok(hr == E_POINTER, "got 0x%08x\n", hr);
322 V_VT(&value) = VT_I2;
323 hr = IWshShell3_RegRead(sh3, name, &value);
324 ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got 0x%08x\n", hr);
325 ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
326 SysFreeString(name);
327
328 name = SysAllocString(broken2W);
329 V_VT(&value) = VT_I2;
330 hr = IWshShell3_RegRead(sh3, name, &value);
331 ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got 0x%08x\n", hr);
332 ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
333 SysFreeString(name);
334
335 ret = RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &root);
336 ok(ret == 0, "got %d\n", ret);
337
338 ret = RegSetValueExA(root, "regsz", 0, REG_SZ, (const BYTE*)"foobar", 7);
339 ok(ret == 0, "got %d\n", ret);
340
341 ret = RegSetValueExA(root, "regsz2", 0, REG_SZ, (const BYTE*)"foobar\0f", 9);
342 ok(ret == 0, "got %d\n", ret);
343
344 ret = RegSetValueExA(root, "regmultisz", 0, REG_MULTI_SZ, (const BYTE*)"foo\0bar\0", 9);
345 ok(ret == 0, "got %d\n", ret);
346
347 dwvalue = 10;
348 ret = RegSetValueExA(root, "regdword", 0, REG_DWORD, (const BYTE*)&dwvalue, sizeof(dwvalue));
349 ok(ret == 0, "got %d\n", ret);
350
351 dwvalue = 11;
352 ret = RegSetValueExA(root, "regbinary", 0, REG_BINARY, (const BYTE*)&dwvalue, sizeof(dwvalue));
353 ok(ret == 0, "got %d\n", ret);
354
355 /* REG_SZ */
356 lstrcpyW(pathW, keypathW);
357 lstrcatW(pathW, regszW);
358 name = SysAllocString(pathW);
359 VariantInit(&value);
360 hr = IWshShell3_RegRead(sh3, name, &value);
361 ok(hr == S_OK, "got 0x%08x\n", hr);
362 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
363 ok(!lstrcmpW(V_BSTR(&value), foobarW), "got %s\n", wine_dbgstr_w(V_BSTR(&value)));
364 VariantClear(&value);
365 SysFreeString(name);
366
367 /* REG_SZ with embedded NULL */
368 lstrcpyW(pathW, keypathW);
369 lstrcatW(pathW, regsz2W);
370 name = SysAllocString(pathW);
371 VariantInit(&value);
372 hr = IWshShell3_RegRead(sh3, name, &value);
373 ok(hr == S_OK, "got 0x%08x\n", hr);
374 ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
375 ok(SysStringLen(V_BSTR(&value)) == 6, "len %d\n", SysStringLen(V_BSTR(&value)));
376 VariantClear(&value);
377 SysFreeString(name);
378
379 /* REG_DWORD */
380 lstrcpyW(pathW, keypathW);
381 lstrcatW(pathW, regdwordW);
382 name = SysAllocString(pathW);
383 VariantInit(&value);
384 hr = IWshShell3_RegRead(sh3, name, &value);
385 ok(hr == S_OK, "got 0x%08x\n", hr);
386 ok(V_VT(&value) == VT_I4, "got %d\n", V_VT(&value));
387 ok(V_I4(&value) == 10, "got %d\n", V_I4(&value));
388 SysFreeString(name);
389
390 /* REG_BINARY */
391 lstrcpyW(pathW, keypathW);
392 lstrcatW(pathW, regbinaryW);
393 name = SysAllocString(pathW);
394 VariantInit(&value);
395 hr = IWshShell3_RegRead(sh3, name, &value);
396 ok(hr == S_OK, "got 0x%08x\n", hr);
397 ok(V_VT(&value) == (VT_ARRAY|VT_VARIANT), "got 0x%x\n", V_VT(&value));
398 dim = SafeArrayGetDim(V_ARRAY(&value));
399 ok(dim == 1, "got %u\n", dim);
400
401 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &bound);
402 ok(hr == S_OK, "got 0x%08x\n", hr);
403 ok(bound == 0, "got %u\n", bound);
404
405 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &bound);
406 ok(hr == S_OK, "got 0x%08x\n", hr);
407 ok(bound == 3, "got %u\n", bound);
408
409 hr = SafeArrayGetVartype(V_ARRAY(&value), &vartype);
410 ok(hr == S_OK, "got 0x%08x\n", hr);
411 ok(vartype == VT_VARIANT, "got %d\n", vartype);
412
413 bound = 0;
414 hr = SafeArrayGetElement(V_ARRAY(&value), &bound, &v);
415 ok(hr == S_OK, "got 0x%08x\n", hr);
416 ok(V_VT(&v) == VT_UI1, "got %d\n", V_VT(&v));
417 ok(V_UI1(&v) == 11, "got %u\n", V_UI1(&v));
418 VariantClear(&v);
419 VariantClear(&value);
420 SysFreeString(name);
421
422 /* REG_MULTI_SZ */
423 lstrcpyW(pathW, keypathW);
424 lstrcatW(pathW, regmultiszW);
425 name = SysAllocString(pathW);
426 VariantInit(&value);
427 hr = IWshShell3_RegRead(sh3, name, &value);
428 ok(hr == S_OK, "got 0x%08x\n", hr);
429 ok(V_VT(&value) == (VT_ARRAY|VT_VARIANT), "got 0x%x\n", V_VT(&value));
430 SysFreeString(name);
431
432 dim = SafeArrayGetDim(V_ARRAY(&value));
433 ok(dim == 1, "got %u\n", dim);
434
435 hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &bound);
436 ok(hr == S_OK, "got 0x%08x\n", hr);
437 ok(bound == 0, "got %u\n", bound);
438
439 hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &bound);
440 ok(hr == S_OK, "got 0x%08x\n", hr);
441 ok(bound == 1, "got %u\n", bound);
442
443 hr = SafeArrayGetVartype(V_ARRAY(&value), &vartype);
444 ok(hr == S_OK, "got 0x%08x\n", hr);
445 ok(vartype == VT_VARIANT, "got %d\n", vartype);
446
447 bound = 0;
448 hr = SafeArrayGetElement(V_ARRAY(&value), &bound, &v);
449 ok(hr == S_OK, "got 0x%08x\n", hr);
450 ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
451 ok(!lstrcmpW(V_BSTR(&v), fooW), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
452 VariantClear(&v);
453 VariantClear(&value);
454
455 name = SysAllocString(regsz1W);
456 V_VT(&value) = VT_I2;
457 hr = IWshShell3_RegRead(sh3, name, &value);
458 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
459 ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
460 VariantClear(&value);
461 SysFreeString(name);
462
463 delete_key(root);
464
465 /* RegWrite() */
466 ret = RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &root);
467 ok(ret == 0, "got %d\n", ret);
468
469 hr = IWshShell3_RegWrite(sh3, NULL, NULL, NULL);
470 ok(hr == E_POINTER, "got 0x%08x\n", hr);
471
472 lstrcpyW(pathW, keypathW);
473 lstrcatW(pathW, regszW);
474 name = SysAllocString(pathW);
475
476 hr = IWshShell3_RegWrite(sh3, name, NULL, NULL);
477 ok(hr == E_POINTER, "got 0x%08x\n", hr);
478
479 VariantInit(&value);
480 hr = IWshShell3_RegWrite(sh3, name, &value, NULL);
481 ok(hr == E_POINTER, "got 0x%08x\n", hr);
482
483 hr = IWshShell3_RegWrite(sh3, name, &value, &value);
484 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
485
486 /* type is optional */
487 V_VT(&v) = VT_ERROR;
488 V_ERROR(&v) = DISP_E_PARAMNOTFOUND;
489 hr = IWshShell3_RegWrite(sh3, name, &value, &v);
490 ok(hr == S_OK, "got 0x%08x\n", hr);
491
492 /* default type is REG_SZ */
493 V_VT(&value) = VT_I4;
494 V_I4(&value) = 12;
495 hr = IWshShell3_RegWrite(sh3, name, &value, &v);
496 ok(hr == S_OK, "got 0x%08x\n", hr);
497
498 type = REG_NONE;
499 ret = RegQueryValueExA(root, "regsz", 0, &type, NULL, NULL);
500 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
501 ok(type == REG_SZ, "got %d\n", type);
502
503 ret = RegDeleteValueA(root, "regsz");
504 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
505 V_VT(&value) = VT_BSTR;
506 V_BSTR(&value) = SysAllocString(regszW);
507 hr = IWshShell3_RegWrite(sh3, name, &value, &v);
508 ok(hr == S_OK, "got 0x%08x\n", hr);
509 VariantClear(&value);
510
511 type = REG_NONE;
512 ret = RegQueryValueExA(root, "regsz", 0, &type, NULL, NULL);
513 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
514 ok(type == REG_SZ, "got %d\n", type);
515
516 ret = RegDeleteValueA(root, "regsz");
517 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
518 V_VT(&value) = VT_R4;
519 V_R4(&value) = 1.2;
520 hr = IWshShell3_RegWrite(sh3, name, &value, &v);
521 ok(hr == S_OK, "got 0x%08x\n", hr);
522 VariantClear(&value);
523
524 type = REG_NONE;
525 ret = RegQueryValueExA(root, "regsz", 0, &type, NULL, NULL);
526 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
527 ok(type == REG_SZ, "got %d\n", type);
528
529 ret = RegDeleteValueA(root, "regsz");
530 ok(ret == ERROR_SUCCESS, "got %d\n", ret);
531 V_VT(&value) = VT_R4;
532 V_R4(&value) = 1.2;
533 V_VT(&v) = VT_I2;
534 V_I2(&v) = 1;
535 hr = IWshShell3_RegWrite(sh3, name, &value, &v);
536 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
537 VariantClear(&value);
538
539 SysFreeString(name);
540
541 delete_key(root);
542 IWshShell3_Release(sh3);
543 }
544
545 START_TEST(wshom)
546 {
547 IUnknown *unk;
548 HRESULT hr;
549
550 CoInitialize(NULL);
551
552 hr = CoCreateInstance(&CLSID_WshShell, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
553 &IID_IUnknown, (void**)&unk);
554 if (FAILED(hr)) {
555 win_skip("Could not create WshShell object: %08x\n", hr);
556 return;
557 }
558 IUnknown_Release(unk);
559
560 test_wshshell();
561 test_registry();
562
563 CoUninitialize();
564 }