include: Update the PEB and TEB structures.
[wine.git] / dlls / wbemprox / reg.c
blobcd7db81aed7e8a1c5022faf8b0bd175ad164f3a7
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 return E_OUTOFMEMORY;
191 strings = tmp;
193 if ((res = RegEnumKeyW( hkey, i, buf, len )) == ERROR_NO_MORE_ITEMS)
195 if (i) res = ERROR_SUCCESS;
196 break;
198 if (res) break;
199 if (!(strings[i] = SysAllocString( buf )))
201 for (i--; i >= 0; i--) SysFreeString( strings[i] );
202 hr = E_OUTOFMEMORY;
203 break;
205 i++;
207 if (hr == S_OK && !res)
209 hr = to_bstr_array( strings, i, names );
210 free_bstr_array( strings, i );
212 set_variant( VT_UI4, res, NULL, retval );
213 RegCloseKey( hkey );
214 free( strings );
215 return hr;
218 HRESULT reg_enum_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
220 VARIANT defkey, subkey, names, retval;
221 IWbemClassObject *sig, *out_params = NULL;
222 HRESULT hr;
224 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
226 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
227 if (hr != S_OK) return hr;
228 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
229 if (hr != S_OK) return hr;
231 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"EnumKey", PARAM_OUT, &sig );
232 if (hr != S_OK)
234 VariantClear( &subkey );
235 return hr;
237 if (out)
239 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
240 if (hr != S_OK)
242 VariantClear( &subkey );
243 IWbemClassObject_Release( sig );
244 return hr;
247 VariantInit( &names );
248 hr = enum_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, context, &retval );
249 if (hr != S_OK) goto done;
250 if (out_params)
252 if (!V_UI4( &retval ))
254 hr = IWbemClassObject_Put( out_params, L"sNames", 0, &names, CIM_STRING|CIM_FLAG_ARRAY );
255 if (hr != S_OK) goto done;
257 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
260 done:
261 VariantClear( &names );
262 VariantClear( &subkey );
263 IWbemClassObject_Release( sig );
264 if (hr == S_OK && out)
266 *out = out_params;
267 IWbemClassObject_AddRef( out_params );
269 if (out_params) IWbemClassObject_Release( out_params );
270 return hr;
273 static HRESULT enum_values( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT *types, IWbemContext *context,
274 VARIANT *retval )
276 HKEY hkey = NULL;
277 HRESULT hr = S_OK;
278 BSTR *value_names = NULL;
279 DWORD count, buflen, len, *value_types = NULL;
280 LONG res, i = 0;
281 WCHAR *buf = NULL;
283 TRACE("%p, %s\n", root, debugstr_w(subkey));
285 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_QUERY_VALUE | get_access_mask( context ), &hkey ))) goto done;
286 if ((res = RegQueryInfoKeyW( hkey, NULL, NULL, NULL, NULL, NULL, NULL, &count, &buflen, NULL, NULL, NULL )))
287 goto done;
289 hr = E_OUTOFMEMORY;
290 if (!(buf = malloc( (buflen + 1) * sizeof(WCHAR) ))) goto done;
291 if (!(value_names = malloc( count * sizeof(BSTR) ))) goto done;
292 if (!(value_types = malloc( count * sizeof(DWORD) ))) goto done;
294 hr = S_OK;
295 for (;;)
297 len = buflen + 1;
298 res = RegEnumValueW( hkey, i, buf, &len, NULL, &value_types[i], NULL, NULL );
299 if (res == ERROR_NO_MORE_ITEMS)
301 if (i) res = ERROR_SUCCESS;
302 break;
304 if (res) break;
305 if (!(value_names[i] = SysAllocString( buf )))
307 for (i--; i >= 0; i--) SysFreeString( value_names[i] );
308 hr = E_OUTOFMEMORY;
309 break;
311 i++;
313 if (hr == S_OK && !res)
315 hr = to_bstr_array( value_names, i, names );
316 free_bstr_array( value_names, i );
317 if (hr == S_OK) hr = to_i4_array( value_types, i, types );
320 done:
321 set_variant( VT_UI4, res, NULL, retval );
322 RegCloseKey( hkey );
323 free( value_names );
324 free( value_types );
325 free( buf );
326 return hr;
329 HRESULT reg_enum_values( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
331 VARIANT defkey, subkey, names, types, retval;
332 IWbemClassObject *sig, *out_params = NULL;
333 HRESULT hr;
335 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
337 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
338 if (hr != S_OK) return hr;
339 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
340 if (hr != S_OK) return hr;
342 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"EnumValues", PARAM_OUT, &sig );
343 if (hr != S_OK)
345 VariantClear( &subkey );
346 return hr;
348 if (out)
350 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
351 if (hr != S_OK)
353 VariantClear( &subkey );
354 IWbemClassObject_Release( sig );
355 return hr;
358 VariantInit( &names );
359 VariantInit( &types );
360 hr = enum_values( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), &names, &types, context, &retval );
361 if (hr != S_OK) goto done;
362 if (out_params)
364 if (!V_UI4( &retval ))
366 hr = IWbemClassObject_Put( out_params, L"sNames", 0, &names, CIM_STRING|CIM_FLAG_ARRAY );
367 if (hr != S_OK) goto done;
368 hr = IWbemClassObject_Put( out_params, L"Types", 0, &types, CIM_SINT32|CIM_FLAG_ARRAY );
369 if (hr != S_OK) goto done;
371 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
374 done:
375 VariantClear( &types );
376 VariantClear( &names );
377 VariantClear( &subkey );
378 IWbemClassObject_Release( sig );
379 if (hr == S_OK && out)
381 *out = out_params;
382 IWbemClassObject_AddRef( out_params );
384 if (out_params) IWbemClassObject_Release( out_params );
385 return hr;
388 static HRESULT get_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, VARIANT *value,
389 IWbemContext *context, VARIANT *retval )
391 DWORD size, mask, flags = RRF_RT_REG_SZ;
392 HRESULT hr = S_OK;
393 BSTR str = NULL;
394 LONG res;
396 TRACE("%p, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name));
398 mask = get_access_mask( context );
400 if (mask & KEY_WOW64_64KEY)
401 flags |= RRF_SUBKEY_WOW6464KEY;
402 else if (mask & KEY_WOW64_32KEY)
403 flags |= RRF_SUBKEY_WOW6432KEY;
405 if ((res = RegGetValueW( root, subkey, name, flags, NULL, NULL, &size ))) goto done;
406 if (!(str = SysAllocStringLen( NULL, size / sizeof(WCHAR) - 1 ))) return E_OUTOFMEMORY;
407 if (!(res = RegGetValueW( root, subkey, name, flags, NULL, str, &size ))) set_variant( VT_BSTR, 0, str, value );
409 done:
410 set_variant( VT_UI4, res, NULL, retval );
411 if (res) SysFreeString( str );
412 return hr;
415 HRESULT reg_get_stringvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
417 VARIANT defkey, subkey, name, value, retval;
418 IWbemClassObject *sig, *out_params = NULL;
419 HRESULT hr;
421 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
423 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
424 if (hr != S_OK) return hr;
425 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
426 if (hr != S_OK) return hr;
427 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
428 if (hr != S_OK)
430 VariantClear( &subkey );
431 return hr;
434 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"GetStringValue", PARAM_OUT, &sig );
435 if (hr != S_OK)
437 VariantClear( &name );
438 VariantClear( &subkey );
439 return hr;
441 if (out)
443 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
444 if (hr != S_OK)
446 VariantClear( &name );
447 VariantClear( &subkey );
448 IWbemClassObject_Release( sig );
449 return hr;
452 VariantInit( &value );
453 hr = get_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, context, &retval );
454 if (hr != S_OK) goto done;
455 if (out_params)
457 if (!V_UI4( &retval ))
459 hr = IWbemClassObject_Put( out_params, L"sValue", 0, &value, CIM_STRING );
460 if (hr != S_OK) goto done;
462 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
465 done:
466 VariantClear( &name );
467 VariantClear( &subkey );
468 IWbemClassObject_Release( sig );
469 if (hr == S_OK && out)
471 *out = out_params;
472 IWbemClassObject_AddRef( out_params );
474 if (out_params) IWbemClassObject_Release( out_params );
475 return hr;
478 static HRESULT to_ui1_array( BYTE *value, DWORD size, VARIANT *var )
480 SAFEARRAY *sa;
481 HRESULT hr;
482 LONG i;
484 if (!(sa = SafeArrayCreateVector( VT_UI1, 0, size ))) return E_OUTOFMEMORY;
485 for (i = 0; i < size; i++)
487 if ((hr = SafeArrayPutElement( sa, &i, &value[i] )) != S_OK)
489 SafeArrayDestroy( sa );
490 return hr;
493 set_variant( VT_UI1|VT_ARRAY, 0, sa, var );
494 return S_OK;
497 static HRESULT get_binaryvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, VARIANT *value,
498 IWbemContext *context, VARIANT *retval )
500 DWORD size, mask, flags = RRF_RT_REG_BINARY;
501 HRESULT hr = S_OK;
502 BYTE *buf = NULL;
503 LONG res;
505 TRACE("%p, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name));
507 mask = get_access_mask( context );
509 if (mask & KEY_WOW64_64KEY)
510 flags |= RRF_SUBKEY_WOW6464KEY;
511 else if (mask & KEY_WOW64_32KEY)
512 flags |= RRF_SUBKEY_WOW6432KEY;
514 if ((res = RegGetValueW( root, subkey, name, flags, NULL, NULL, &size ))) goto done;
515 if (!(buf = malloc( size ))) return E_OUTOFMEMORY;
516 if (!(res = RegGetValueW( root, subkey, name, flags, NULL, buf, &size ))) hr = to_ui1_array( buf, size, value );
518 done:
519 set_variant( VT_UI4, res, NULL, retval );
520 free( buf );
521 return hr;
524 HRESULT reg_get_binaryvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
526 VARIANT defkey, subkey, name, value, retval;
527 IWbemClassObject *sig, *out_params = NULL;
528 HRESULT hr;
530 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
532 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
533 if (hr != S_OK) return hr;
534 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
535 if (hr != S_OK) return hr;
536 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
537 if (hr != S_OK)
539 VariantClear( &subkey );
540 return hr;
543 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"GetBinaryValue", PARAM_OUT, &sig );
544 if (hr != S_OK)
546 VariantClear( &name );
547 VariantClear( &subkey );
548 return hr;
550 if (out)
552 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
553 if (hr != S_OK)
555 VariantClear( &name );
556 VariantClear( &subkey );
557 IWbemClassObject_Release( sig );
558 return hr;
561 VariantInit( &value );
562 hr = get_binaryvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), &value, context, &retval );
563 if (hr != S_OK) goto done;
564 if (out_params)
566 if (!V_UI4( &retval ))
568 hr = IWbemClassObject_Put( out_params, L"uValue", 0, &value, CIM_UINT8|CIM_FLAG_ARRAY );
569 if (hr != S_OK) goto done;
571 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
574 done:
575 VariantClear( &name );
576 VariantClear( &subkey );
577 IWbemClassObject_Release( sig );
578 if (hr == S_OK && out)
580 *out = out_params;
581 IWbemClassObject_AddRef( out_params );
583 if (out_params) IWbemClassObject_Release( out_params );
584 return hr;
587 static void set_stringvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, const WCHAR *value,
588 IWbemContext *context, VARIANT *retval )
590 HKEY hkey;
591 LONG res;
593 TRACE("%p, %s, %s, %s\n", root, debugstr_w(subkey), debugstr_w(name), debugstr_w(value));
595 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_SET_VALUE | get_access_mask( context ), &hkey )))
597 set_variant( VT_UI4, res, NULL, retval );
598 return;
601 res = RegSetKeyValueW( hkey, NULL, name, REG_SZ, value, (lstrlenW( value ) + 1) * sizeof(*value) );
602 set_variant( VT_UI4, res, NULL, retval );
603 RegCloseKey( hkey );
606 HRESULT reg_set_stringvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
608 VARIANT defkey, subkey, name, value, retval;
609 IWbemClassObject *sig, *out_params = NULL;
610 HRESULT hr;
612 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
614 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
615 if (hr != S_OK) return hr;
616 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
617 if (hr != S_OK) return hr;
618 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
619 if (hr != S_OK)
621 VariantClear( &subkey );
622 return hr;
624 hr = IWbemClassObject_Get( in, L"sValue", 0, &value, NULL, NULL );
625 if (hr != S_OK)
627 VariantClear( &name );
628 VariantClear( &subkey );
629 return hr;
632 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"SetStringValue", PARAM_OUT, &sig );
633 if (hr != S_OK)
635 VariantClear( &name );
636 VariantClear( &subkey );
637 VariantClear( &value );
638 return hr;
640 if (out)
642 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
643 if (hr != S_OK)
645 VariantClear( &name );
646 VariantClear( &subkey );
647 VariantClear( &value );
648 IWbemClassObject_Release( sig );
649 return hr;
653 set_stringvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), V_BSTR(&value), context, &retval );
654 if (out_params)
655 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
657 VariantClear( &name );
658 VariantClear( &subkey );
659 VariantClear( &value );
660 IWbemClassObject_Release( sig );
661 if (hr == S_OK && out)
663 *out = out_params;
664 IWbemClassObject_AddRef( out_params );
666 if (out_params) IWbemClassObject_Release( out_params );
667 return hr;
670 static void set_dwordvalue( HKEY root, const WCHAR *subkey, const WCHAR *name, DWORD value, IWbemContext *context,
671 VARIANT *retval )
673 HKEY hkey;
674 LONG res;
676 TRACE( "%p, %s, %s, %#lx\n", root, debugstr_w(subkey), debugstr_w(name), value );
678 if ((res = RegOpenKeyExW( root, subkey, 0, KEY_SET_VALUE | get_access_mask( context ), &hkey )))
680 set_variant( VT_UI4, res, NULL, retval );
681 return;
684 res = RegSetKeyValueW( hkey, NULL, name, REG_DWORD, &value, sizeof(value) );
685 set_variant( VT_UI4, res, NULL, retval );
686 RegCloseKey( hkey );
689 HRESULT reg_set_dwordvalue( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
691 VARIANT defkey, subkey, name, value, retval;
692 IWbemClassObject *sig, *out_params = NULL;
693 HRESULT hr;
695 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
697 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
698 if (hr != S_OK) return hr;
699 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
700 if (hr != S_OK) return hr;
701 hr = IWbemClassObject_Get( in, L"sValueName", 0, &name, NULL, NULL );
702 if (hr != S_OK)
704 VariantClear( &subkey );
705 return hr;
707 hr = IWbemClassObject_Get( in, L"uValue", 0, &value, NULL, NULL );
708 if (hr != S_OK)
710 VariantClear( &name );
711 VariantClear( &subkey );
712 return hr;
715 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"SetDWORDValue", PARAM_OUT, &sig );
716 if (hr != S_OK)
718 VariantClear( &name );
719 VariantClear( &subkey );
720 return hr;
722 if (out)
724 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
725 if (hr != S_OK)
727 VariantClear( &name );
728 VariantClear( &subkey );
729 IWbemClassObject_Release( sig );
730 return hr;
733 set_dwordvalue( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), V_BSTR(&name), V_UI4(&value), context, &retval );
734 if (out_params)
735 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
737 VariantClear( &name );
738 VariantClear( &subkey );
739 IWbemClassObject_Release( sig );
740 if (hr == S_OK && out)
742 *out = out_params;
743 IWbemClassObject_AddRef( out_params );
745 if (out_params) IWbemClassObject_Release( out_params );
746 return hr;
749 static void delete_key( HKEY root, const WCHAR *subkey, IWbemContext *context, VARIANT *retval )
751 LONG res;
753 TRACE("%p, %s\n", root, debugstr_w(subkey));
755 res = RegDeleteKeyExW( root, subkey, get_access_mask( context ), 0 );
756 set_variant( VT_UI4, res, NULL, retval );
759 HRESULT reg_delete_key( IWbemClassObject *obj, IWbemContext *context, IWbemClassObject *in, IWbemClassObject **out )
761 VARIANT defkey, subkey, retval;
762 IWbemClassObject *sig, *out_params = NULL;
763 HRESULT hr;
765 TRACE("%p, %p, %p, %p\n", obj, context, in, out);
767 hr = IWbemClassObject_Get( in, L"hDefKey", 0, &defkey, NULL, NULL );
768 if (hr != S_OK) return hr;
769 hr = IWbemClassObject_Get( in, L"sSubKeyName", 0, &subkey, NULL, NULL );
770 if (hr != S_OK) return hr;
772 hr = create_signature( WBEMPROX_NAMESPACE_CIMV2, L"StdRegProv", L"DeleteKey", PARAM_OUT, &sig );
773 if (hr != S_OK)
775 VariantClear( &subkey );
776 return hr;
778 if (out)
780 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
781 if (hr != S_OK)
783 VariantClear( &subkey );
784 IWbemClassObject_Release( sig );
785 return hr;
788 delete_key( (HKEY)(INT_PTR)V_I4(&defkey), V_BSTR(&subkey), context, &retval );
789 if (out_params)
790 hr = IWbemClassObject_Put( out_params, L"ReturnValue", 0, &retval, CIM_UINT32 );
792 VariantClear( &subkey );
793 IWbemClassObject_Release( sig );
794 if (hr == S_OK && out)
796 *out = out_params;
797 IWbemClassObject_AddRef( out_params );
799 if (out_params) IWbemClassObject_Release( out_params );
800 return hr;