dsdmo: Add Flanger effect stub.
[wine.git] / dlls / wbemprox / reg.c
blobcdfb5d280072ca17450b2cf7212551cb8e4b06eb
1 /*
2 * StdRegProv implementation
4 * Copyright 2012 Hans Leidekker for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wbemcli.h"
29 #include "wine/debug.h"
30 #include "wbemprox_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
34 static HRESULT to_bstr_array( BSTR *strings, DWORD count, VARIANT *var )
36 SAFEARRAY *sa;
37 HRESULT hr;
38 LONG i;
40 if (!(sa = SafeArrayCreateVector( VT_BSTR, 0, count ))) return E_OUTOFMEMORY;
41 for (i = 0; i < count; i++)
43 if ((hr = SafeArrayPutElement( sa, &i, strings[i] )) != S_OK)
45 SafeArrayDestroy( sa );
46 return hr;
49 set_variant( VT_BSTR|VT_ARRAY, 0, sa, var );
50 return S_OK;
53 static void free_bstr_array( BSTR *strings, DWORD count )
55 while (count--)
56 SysFreeString( *(strings++) );
59 static HRESULT to_i4_array( DWORD *values, DWORD count, VARIANT *var )
61 SAFEARRAY *sa;
62 HRESULT hr;
63 LONG i;
65 if (!(sa = SafeArrayCreateVector( VT_I4, 0, count ))) return E_OUTOFMEMORY;
66 for (i = 0; i < count; i++)
68 if ((hr = SafeArrayPutElement( sa, &i, &values[i] )) != S_OK)
70 SafeArrayDestroy( sa );
71 return hr;
74 set_variant( VT_I4|VT_ARRAY, 0, sa, var );
75 return S_OK;
78 static unsigned int get_access_mask( IWbemContext *context )
80 VARIANT value;
82 if (!context) return 0;
84 V_VT( &value ) = VT_EMPTY;
85 if (FAILED(IWbemContext_GetValue( context, L"__ProviderArchitecture", 0, &value )))
86 return 0;
88 if (FAILED(VariantChangeType( &value, &value, 0, VT_I4 )))
90 VariantClear( &value );
91 return 0;
94 if (V_I4( &value ) == 32)
95 return KEY_WOW64_32KEY;
96 else if (V_I4( &value ) == 64)
97 return KEY_WOW64_64KEY;
99 return 0;
102 static HRESULT create_key( HKEY root, const WCHAR *subkey, IWbemContext *context, VARIANT *retval )
104 LONG res;
105 HKEY hkey;
107 TRACE("%p, %s\n", root, debugstr_w(subkey));
109 res = RegCreateKeyExW( root, subkey, 0, NULL, 0, get_access_mask( context ), NULL, &hkey, NULL );
110 set_variant( VT_UI4, res, NULL, retval );
111 if (!res)
113 RegCloseKey( hkey );
114 return S_OK;
116 return HRESULT_FROM_WIN32( res );
119 HRESULT reg_create_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
121 VARIANT defkey, subkey, retval;
122 IWbemClassObject *sig, *out_params = NULL;
123 HRESULT hr;
125 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
127 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
128 if (hr != S_OK) return hr;
129 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
130 if (hr != S_OK) return hr;
132 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"CreateKey", PARAM_OUT, &sig );
133 if (hr != S_OK)
135 VariantClear( &subkey );
136 return hr;
138 if (out)
140 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
141 if (hr != S_OK)
143 VariantClear( &subkey );
144 IWbemClassObject_Release( sig );
145 return hr;
148 hr = create_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), context, &retval );
149 if (hr == S_OK && out_params)
150 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
152 VariantClear( &subkey );
153 IWbemClassObject_Release( sig );
154 if (hr == S_OK && out)
156 *out = out_params;
157 IWbemClassObject_AddRef( out_params );
159 if (out_params) IWbemClassObject_Release( out_params );
160 return hr;
163 static HRESULT enum_key( HKEY root, const WCHAR *subkey, VARIANT *names, IWbemContext *context, VARIANT *retval )
165 HKEY hkey;
166 HRESULT hr = S_OK;
167 WCHAR buf[256];
168 BSTR *strings, *tmp;
169 DWORD count = 2, len = ARRAY_SIZE( buf );
170 LONG res, i = 0;
172 TRACE("%p, %s\n", root, debugstr_w(subkey));
174 if (!(strings = malloc( count * sizeof(BSTR) ))) return E_OUTOFMEMORY;
175 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_ENUMERATE_SUB_KEYS | get_access_mask( context ), &hkey )))
177 set_variant( VT_UI4, res, NULL, retval );
178 free( strings );
179 return S_OK;
181 for (;;)
183 if (i >= count)
185 count *= 2;
186 if (!(tmp = realloc( strings, count * sizeof(BSTR) )))
188 RegCloseKey( hkey );
189 free( strings );
190 return E_OUTOFMEMORY;
192 strings = tmp;
194 if ((res = RegEnumKeyW( hkey, i, buf, len )) == ERROR_NO_MORE_ITEMS)
196 if (i) res = ERROR_SUCCESS;
197 break;
199 if (res) break;
200 if (!(strings[i] = SysAllocString( buf )))
202 for (i--; i >= 0; i--) SysFreeString( strings[i] );
203 hr = E_OUTOFMEMORY;
204 break;
206 i++;
208 if (hr == S_OK && !res)
210 hr = to_bstr_array( strings, i, names );
211 free_bstr_array( strings, i );
213 set_variant( VT_UI4, res, NULL, retval );
214 RegCloseKey( hkey );
215 free( strings );
216 return hr;
219 HRESULT reg_enum_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
221 VARIANT defkey, subkey, names, retval;
222 IWbemClassObject *sig, *out_params = NULL;
223 HRESULT hr;
225 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
227 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
228 if (hr != S_OK) return hr;
229 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
230 if (hr != S_OK) return hr;
232 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"EnumKey", PARAM_OUT, &sig );
233 if (hr != S_OK)
235 VariantClear( &subkey );
236 return hr;
238 if (out)
240 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
241 if (hr != S_OK)
243 VariantClear( &subkey );
244 IWbemClassObject_Release( sig );
245 return hr;
248 VariantInit( &names );
249 hr = enum_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, context, &retval );
250 if (hr != S_OK) goto done;
251 if (out_params)
253 if (!V_UI4( &retval ))
255 hr = IWbemClassObject_Put( out_params, L"sNames", 0, &names, CIM_STRING|CIM_FLAG_ARRAY );
256 if (hr != S_OK) goto done;
258 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
261 done:
262 VariantClear( &names );
263 VariantClear( &subkey );
264 IWbemClassObject_Release( sig );
265 if (hr == S_OK && out)
267 *out = out_params;
268 IWbemClassObject_AddRef( out_params );
270 if (out_params) IWbemClassObject_Release( out_params );
271 return hr;
274 static HRESULT enum_values( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *types, IWbemContext *context,
275 VARIANT *retval )
277 HKEY hkey = NULL;
278 HRESULT hr = S_OK;
279 BSTR *value_names = NULL;
280 DWORD count, buflen, len, *value_types = NULL;
281 LONG res, i = 0;
282 WCHAR *buf = NULL;
284 TRACE("%p, %s\n", root, debugstr_w(subkey));
286 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_QUERY_VALUE | get_access_mask( context ), &hkey ))) goto done;
287 if ((res = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, NULL, NULL, &count, &buflen, NULL, NULL, NULL )))
288 goto done;
290 hr = E_OUTOFMEMORY;
291 if (!(buf = malloc( (buflen + 1) * sizeof(WCHAR) ))) goto done;
292 if (!(value_names = malloc( count * sizeof(BSTR) ))) goto done;
293 if (!(value_types = malloc( count * sizeof(DWORD) ))) goto done;
295 hr = S_OK;
296 for (;;)
298 len = buflen + 1;
299 res = RegEnumValueW( hkey, i, buf, &len, NULL, &value_types[i], NULL, NULL );
300 if (res == ERROR_NO_MORE_ITEMS)
302 if (i) res = ERROR_SUCCESS;
303 break;
305 if (res) break;
306 if (!(value_names[i] = SysAllocString( buf )))
308 for (i--; i >= 0; i--) SysFreeString( value_names[i] );
309 hr = E_OUTOFMEMORY;
310 break;
312 i++;
314 if (hr == S_OK && !res)
316 hr = to_bstr_array( value_names, i, names );
317 free_bstr_array( value_names, i );
318 if (hr == S_OK) hr = to_i4_array( value_types, i, types );
321 done:
322 set_variant( VT_UI4, res, NULL, retval );
323 RegCloseKey( hkey );
324 free( value_names );
325 free( value_types );
326 free( buf );
327 return hr;
330 HRESULT reg_enum_values( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
332 VARIANT defkey, subkey, names, types, retval;
333 IWbemClassObject *sig, *out_params = NULL;
334 HRESULT hr;
336 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
338 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
339 if (hr != S_OK) return hr;
340 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
341 if (hr != S_OK) return hr;
343 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"EnumValues", PARAM_OUT, &sig );
344 if (hr != S_OK)
346 VariantClear( &subkey );
347 return hr;
349 if (out)
351 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
352 if (hr != S_OK)
354 VariantClear( &subkey );
355 IWbemClassObject_Release( sig );
356 return hr;
359 VariantInit( &names );
360 VariantInit( &types );
361 hr = enum_values( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, &types, context, &retval );
362 if (hr != S_OK) goto done;
363 if (out_params)
365 if (!V_UI4( &retval ))
367 hr = IWbemClassObject_Put( out_params, L"sNames", 0, &names, CIM_STRING|CIM_FLAG_ARRAY );
368 if (hr != S_OK) goto done;
369 hr = IWbemClassObject_Put( out_params, L"Types", 0, &types, CIM_SINT32|CIM_FLAG_ARRAY );
370 if (hr != S_OK) goto done;
372 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
375 done:
376 VariantClear( &types );
377 VariantClear( &names );
378 VariantClear( &subkey );
379 IWbemClassObject_Release( sig );
380 if (hr == S_OK && out)
382 *out = out_params;
383 IWbemClassObject_AddRef( out_params );
385 if (out_params) IWbemClassObject_Release( out_params );
386 return hr;
389 static HRESULT get_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, VARIANT *value,
390 IWbemContext *context, VARIANT *retval )
392 DWORD size, mask, flags = RRF_RT_REG_SZ;
393 HRESULT hr = S_OK;
394 BSTR str = NULL;
395 LONG res;
397 TRACE("%p, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name));
399 mask = get_access_mask( context );
401 if (mask & KEY_WOW64_64KEY)
402 flags |= RRF_SUBKEY_WOW6464KEY;
403 else if (mask & KEY_WOW64_32KEY)
404 flags |= RRF_SUBKEY_WOW6432KEY;
406 if ((res = RegGetValueW( root, subkey, name, flags, NULL, NULL, &size ))) goto done;
407 if (!(str = SysAllocStringLen( NULL, size / sizeof(WCHAR) - 1 ))) return E_OUTOFMEMORY;
408 if (!(res = RegGetValueW( root, subkey, name, flags, NULL, str, &size ))) set_variant( VT_BSTR, 0, str, value );
410 done:
411 set_variant( VT_UI4, res, NULL, retval );
412 if (res) SysFreeString( str );
413 return hr;
416 HRESULT reg_get_stringvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
418 VARIANT defkey, subkey, name, value, retval;
419 IWbemClassObject *sig, *out_params = NULL;
420 HRESULT hr;
422 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
424 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
425 if (hr != S_OK) return hr;
426 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
427 if (hr != S_OK) return hr;
428 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
429 if (hr != S_OK)
431 VariantClear( &subkey );
432 return hr;
435 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"GetStringValue", PARAM_OUT, &sig );
436 if (hr != S_OK)
438 VariantClear( &name );
439 VariantClear( &subkey );
440 return hr;
442 if (out)
444 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
445 if (hr != S_OK)
447 VariantClear( &name );
448 VariantClear( &subkey );
449 IWbemClassObject_Release( sig );
450 return hr;
453 VariantInit( &value );
454 hr = get_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, context, &retval );
455 if (hr != S_OK) goto done;
456 if (out_params)
458 if (!V_UI4( &retval ))
460 hr = IWbemClassObject_Put( out_params, L"sValue", 0, &value, CIM_STRING );
461 if (hr != S_OK) goto done;
463 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
466 done:
467 VariantClear( &name );
468 VariantClear( &subkey );
469 IWbemClassObject_Release( sig );
470 if (hr == S_OK && out)
472 *out = out_params;
473 IWbemClassObject_AddRef( out_params );
475 if (out_params) IWbemClassObject_Release( out_params );
476 return hr;
479 static HRESULT to_ui1_array( BYTE *value, DWORD size, VARIANT *var )
481 SAFEARRAY *sa;
482 HRESULT hr;
483 LONG i;
485 if (!(sa = SafeArrayCreateVector( VT_UI1, 0, size ))) return E_OUTOFMEMORY;
486 for (i = 0; i < size; i++)
488 if ((hr = SafeArrayPutElement( sa, &i, &value[i] )) != S_OK)
490 SafeArrayDestroy( sa );
491 return hr;
494 set_variant( VT_UI1|VT_ARRAY, 0, sa, var );
495 return S_OK;
498 static HRESULT get_binaryvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, VARIANT *value,
499 IWbemContext *context, VARIANT *retval )
501 DWORD size, mask, flags = RRF_RT_REG_BINARY;
502 HRESULT hr = S_OK;
503 BYTE *buf = NULL;
504 LONG res;
506 TRACE("%p, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name));
508 mask = get_access_mask( context );
510 if (mask & KEY_WOW64_64KEY)
511 flags |= RRF_SUBKEY_WOW6464KEY;
512 else if (mask & KEY_WOW64_32KEY)
513 flags |= RRF_SUBKEY_WOW6432KEY;
515 if ((res = RegGetValueW( root, subkey, name, flags, NULL, NULL, &size ))) goto done;
516 if (!(buf = malloc( size ))) return E_OUTOFMEMORY;
517 if (!(res = RegGetValueW( root, subkey, name, flags, NULL, buf, &size ))) hr = to_ui1_array( buf, size, value );
519 done:
520 set_variant( VT_UI4, res, NULL, retval );
521 free( buf );
522 return hr;
525 HRESULT reg_get_binaryvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
527 VARIANT defkey, subkey, name, value, retval;
528 IWbemClassObject *sig, *out_params = NULL;
529 HRESULT hr;
531 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
533 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
534 if (hr != S_OK) return hr;
535 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
536 if (hr != S_OK) return hr;
537 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
538 if (hr != S_OK)
540 VariantClear( &subkey );
541 return hr;
544 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"GetBinaryValue", PARAM_OUT, &sig );
545 if (hr != S_OK)
547 VariantClear( &name );
548 VariantClear( &subkey );
549 return hr;
551 if (out)
553 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
554 if (hr != S_OK)
556 VariantClear( &name );
557 VariantClear( &subkey );
558 IWbemClassObject_Release( sig );
559 return hr;
562 VariantInit( &value );
563 hr = get_binaryvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, context, &retval );
564 if (hr != S_OK) goto done;
565 if (out_params)
567 if (!V_UI4( &retval ))
569 hr = IWbemClassObject_Put( out_params, L"uValue", 0, &value, CIM_UINT8|CIM_FLAG_ARRAY );
570 if (hr != S_OK) goto done;
572 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
575 done:
576 VariantClear( &name );
577 VariantClear( &subkey );
578 IWbemClassObject_Release( sig );
579 if (hr == S_OK && out)
581 *out = out_params;
582 IWbemClassObject_AddRef( out_params );
584 if (out_params) IWbemClassObject_Release( out_params );
585 return hr;
588 static void set_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, const WCHAR *value,
589 IWbemContext *context, VARIANT *retval )
591 HKEY hkey;
592 LONG res;
594 TRACE("%p, %s, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name), debugstr_w(value));
596 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_SET_VALUE | get_access_mask( context ), &hkey )))
598 set_variant( VT_UI4, res, NULL, retval );
599 return;
602 res = RegSetKeyValueW( hkey, NULL, name, REG_SZ, value, (lstrlenW( value ) + 1) * sizeof(*value) );
603 set_variant( VT_UI4, res, NULL, retval );
604 RegCloseKey( hkey );
607 HRESULT reg_set_stringvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
609 VARIANT defkey, subkey, name, value, retval;
610 IWbemClassObject *sig, *out_params = NULL;
611 HRESULT hr;
613 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
615 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
616 if (hr != S_OK) return hr;
617 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
618 if (hr != S_OK) return hr;
619 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
620 if (hr != S_OK)
622 VariantClear( &subkey );
623 return hr;
625 hr = IWbemClassObject_Get( in, L"sValue", 0, &value, NULL, NULL );
626 if (hr != S_OK)
628 VariantClear( &name );
629 VariantClear( &subkey );
630 return hr;
633 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"SetStringValue", PARAM_OUT, &sig );
634 if (hr != S_OK)
636 VariantClear( &name );
637 VariantClear( &subkey );
638 VariantClear( &value );
639 return hr;
641 if (out)
643 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
644 if (hr != S_OK)
646 VariantClear( &name );
647 VariantClear( &subkey );
648 VariantClear( &value );
649 IWbemClassObject_Release( sig );
650 return hr;
654 set_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), V_BSTR(&value), context, &retval );
655 if (out_params)
656 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
658 VariantClear( &name );
659 VariantClear( &subkey );
660 VariantClear( &value );
661 IWbemClassObject_Release( sig );
662 if (hr == S_OK && out)
664 *out = out_params;
665 IWbemClassObject_AddRef( out_params );
667 if (out_params) IWbemClassObject_Release( out_params );
668 return hr;
671 static void set_dwordvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, DWORD value, IWbemContext *context,
672 VARIANT *retval )
674 HKEY hkey;
675 LONG res;
677 TRACE( "%p, %s, %s, %#lx\n", root, debugstr_w(subkey), debugstr_w(name), value );
679 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_SET_VALUE | get_access_mask( context ), &hkey )))
681 set_variant( VT_UI4, res, NULL, retval );
682 return;
685 res = RegSetKeyValueW( hkey, NULL, name, REG_DWORD, &value, sizeof(value) );
686 set_variant( VT_UI4, res, NULL, retval );
687 RegCloseKey( hkey );
690 HRESULT reg_set_dwordvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
692 VARIANT defkey, subkey, name, value, retval;
693 IWbemClassObject *sig, *out_params = NULL;
694 HRESULT hr;
696 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
698 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
699 if (hr != S_OK) return hr;
700 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
701 if (hr != S_OK) return hr;
702 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
703 if (hr != S_OK)
705 VariantClear( &subkey );
706 return hr;
708 hr = IWbemClassObject_Get( in, L"uValue", 0, &value, NULL, NULL );
709 if (hr != S_OK)
711 VariantClear( &name );
712 VariantClear( &subkey );
713 return hr;
716 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"SetDWORDValue", PARAM_OUT, &sig );
717 if (hr != S_OK)
719 VariantClear( &name );
720 VariantClear( &subkey );
721 return hr;
723 if (out)
725 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
726 if (hr != S_OK)
728 VariantClear( &name );
729 VariantClear( &subkey );
730 IWbemClassObject_Release( sig );
731 return hr;
734 set_dwordvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), V_UI4(&value), context, &retval );
735 if (out_params)
736 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
738 VariantClear( &name );
739 VariantClear( &subkey );
740 IWbemClassObject_Release( sig );
741 if (hr == S_OK && out)
743 *out = out_params;
744 IWbemClassObject_AddRef( out_params );
746 if (out_params) IWbemClassObject_Release( out_params );
747 return hr;
750 static void delete_key( HKEY root, const WCHAR *subkey, IWbemContext *context, VARIANT *retval )
752 LONG res;
754 TRACE("%p, %s\n", root, debugstr_w(subkey));
756 res = RegDeleteKeyExW( root, subkey, get_access_mask( context ), 0 );
757 set_variant( VT_UI4, res, NULL, retval );
760 HRESULT reg_delete_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
762 VARIANT defkey, subkey, retval;
763 IWbemClassObject *sig, *out_params = NULL;
764 HRESULT hr;
766 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
768 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
769 if (hr != S_OK) return hr;
770 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
771 if (hr != S_OK) return hr;
773 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"DeleteKey", PARAM_OUT, &sig );
774 if (hr != S_OK)
776 VariantClear( &subkey );
777 return hr;
779 if (out)
781 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
782 if (hr != S_OK)
784 VariantClear( &subkey );
785 IWbemClassObject_Release( sig );
786 return hr;
789 delete_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), context, &retval );
790 if (out_params)
791 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
793 VariantClear( &subkey );
794 IWbemClassObject_Release( sig );
795 if (hr == S_OK && out)
797 *out = out_params;
798 IWbemClassObject_AddRef( out_params );
800 if (out_params) IWbemClassObject_Release( out_params );
801 return hr;