1 /*
2  * Copyright 2012 Hans Leidekker 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 COBJMACROS
20 
21 #include <stdio.h>
22 #include "windows.h"
23 #include "ocidl.h"
24 #include "sddl.h"
25 #include "initguid.h"
26 #include "objidl.h"
27 #include "wbemcli.h"
28 #include "wine/test.h"
29 
30 static const WCHAR wqlW[] = {'w','q','l',0};
31 
32 static HRESULT exec_query( IWbemServices *services, const WCHAR *str, IEnumWbemClassObject **result )
33 {
34     static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
35     static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
36     HRESULT hr;
37     IWbemClassObject *obj;
38     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( str );
39     LONG flags = WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY;
40     ULONG count;
41 
42     hr = IWbemServices_ExecQuery( services, wql, query, flags, NULL, result );
43     if (hr == S_OK)
44     {
45         trace("%s\n", wine_dbgstr_w(str));
46         for (;;)
47         {
48             VARIANT var;
49 
50             IEnumWbemClassObject_Next( *result, 10000, 1, &obj, &count );
51             if (!count) break;
52 
53             if (IWbemClassObject_Get( obj, captionW, 0, &var, NULL, NULL ) == WBEM_S_NO_ERROR)
54             {
55                 trace("caption: %s\n", wine_dbgstr_w(V_BSTR(&var)));
56                 VariantClear( &var );
57             }
58             if (IWbemClassObject_Get( obj, descriptionW, 0, &var, NULL, NULL ) == WBEM_S_NO_ERROR)
59             {
60                 trace("description: %s\n", wine_dbgstr_w(V_BSTR(&var)));
61                 VariantClear( &var );
62             }
63             IWbemClassObject_Release( obj );
64         }
65     }
66     SysFreeString( wql );
67     SysFreeString( query );
68     return hr;
69 }
70 
71 static void test_select( IWbemServices *services )
72 {
73     static const WCHAR emptyW[] = {0};
74     static const WCHAR sqlW[] = {'S','Q','L',0};
75     static const WCHAR query1[] =
76         {'S','E','L','E','C','T',' ','H','O','T','F','I','X','I','D',' ','F','R','O','M',' ',
77          'W','i','n','3','2','_','Q','u','i','c','k','F','i','x','E','n','g','i','n','e','e','r','i','n','g',0};
78     static const WCHAR query2[] =
79         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',0};
80     static const WCHAR query3[] =
81         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
82          'L','o','g','i','c','a','l','D','i','s','k',' ','W','H','E','R','E',' ',
83          '\"','N','T','F','S','\"',' ','=',' ','F','i','l','e','S','y','s','t','e','m',0};
84     static const WCHAR query4[] =
85         {'S','E','L','E','C','T',' ','a',' ','F','R','O','M',' ','b',0};
86     static const WCHAR query5[] =
87         {'S','E','L','E','C','T',' ','a',' ','F','R','O','M',' ','W','i','n','3','2','_','B','i','o','s',0};
88     static const WCHAR query6[] =
89         {'S','E','L','E','C','T',' ','D','e','s','c','r','i','p','t','i','o','n',' ','F','R','O','M',' ',
90          'W','i','n','3','2','_','B','i','o','s',0};
91     static const WCHAR query7[] =
92         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
93          'P','r','o','c','e','s','s',' ','W','H','E','R','E',' ','C','a','p','t','i','o','n',' ',
94          'L','I','K','E',' ','\'','%','%','R','E','G','E','D','I','T','%','\'',0};
95     static const WCHAR query8[] =
96         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
97          'D','i','s','k','D','r','i','v','e',' ','W','H','E','R','E',' ','D','e','v','i','c','e','I','D','=',
98          '\"','\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0','\"',0};
99     static const WCHAR query9[] =
100         {'S','E','L','E','C','T','\n','a','\r','F','R','O','M','\t','b',0};
101     static const WCHAR query10[] =
102         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
103          'P','r','o','c','e','s','s',' ','W','H','E','R','E',' ','C','a','p','t','i','o','n',' ',
104          'L','I','K','E',' ','"','%','f','i','r','e','f','o','x','.','e','x','e','"',0};
105     static const WCHAR query11[] =
106         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
107          'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',' ','w','h','e','r','e',' ',
108          'a','v','a','i','l','a','b','i','l','i','t','y',' ','=',' ','\'','3','\'',0};
109     static const WCHAR query12[] =
110         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',
111          ' ','W','H','E','R','E',' ','N','A','M','E',' ','<','>',' ','N','U','L','L', 0};
112     static const WCHAR query13[] =
113         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_','B','I','O','S',
114          ' ','W','H','E','R','E',' ','N','U','L','L',' ','=',' ','N','A','M','E', 0};
115     static const WCHAR *test[] = { query1, query2, query3, query4, query5, query6, query7, query8, query9, query10,
116                                    query11, query12, query13 };
117     HRESULT hr;
118     IEnumWbemClassObject *result;
119     BSTR wql = SysAllocString( wqlW );
120     BSTR sql = SysAllocString( sqlW );
121     BSTR query = SysAllocString( query1 );
122     UINT i;
123 
124     hr = IWbemServices_ExecQuery( services, NULL, NULL, 0, NULL, &result );
125     ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
126 
127     hr = IWbemServices_ExecQuery( services, NULL, query, 0, NULL, &result );
128     ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
129 
130     hr = IWbemServices_ExecQuery( services, wql, NULL, 0, NULL, &result );
131     ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
132 
133     hr = IWbemServices_ExecQuery( services, sql, query, 0, NULL, &result );
134     ok( hr == WBEM_E_INVALID_QUERY_TYPE, "query failed %08x\n", hr );
135 
136     hr = IWbemServices_ExecQuery( services, sql, NULL, 0, NULL, &result );
137     ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
138 
139     SysFreeString( query );
140     query = SysAllocString( emptyW );
141     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
142     ok( hr == WBEM_E_INVALID_PARAMETER, "query failed %08x\n", hr );
143 
144     for (i = 0; i < ARRAY_SIZE( test ); i++)
145     {
146         hr = exec_query( services, test[i], &result );
147         ok( hr == S_OK, "query %u failed: %08x\n", i, hr );
148         if (result) IEnumWbemClassObject_Release( result );
149     }
150 
151     SysFreeString( wql );
152     SysFreeString( sql );
153     SysFreeString( query );
154 }
155 
156 static void test_associators( IWbemServices *services )
157 {
158     static const WCHAR query1[] =
159         {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
160          'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',0};
161     static const WCHAR query2[] =
162         {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
163          'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
164          'W','H','E','R','E',' ','A','s','s','o','c','C','l','a','s','s',' ','=',' ','W','i','n','3','2','_',
165          'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
166     static const WCHAR *test[] = { query1, query2 };
167     HRESULT hr;
168     IEnumWbemClassObject *result;
169     UINT i;
170 
171     for (i = 0; i < ARRAY_SIZE( test ); i++)
172     {
173         hr = exec_query( services, test[i], &result );
174         todo_wine ok( hr == S_OK, "query %u failed: %08x\n", i, hr );
175         if (result) IEnumWbemClassObject_Release( result );
176     }
177 }
178 
179 static void test_Win32_Service( IWbemServices *services )
180 {
181     static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
182     static const WCHAR pauseserviceW[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
183     static const WCHAR resumeserviceW[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
184     static const WCHAR startserviceW[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
185     static const WCHAR stopserviceW[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
186     static const WCHAR stateW[] = {'S','t','a','t','e',0};
187     static const WCHAR stoppedW[] = {'S','t','o','p','p','e','d',0};
188     static const WCHAR serviceW[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e','.',
189         'N','a','m','e','=','"','S','p','o','o','l','e','r','"',0};
190     static const WCHAR emptyW[] = {0};
191     BSTR class = SysAllocString( serviceW ), empty = SysAllocString( emptyW ), method;
192     IWbemClassObject *service, *out;
193     VARIANT state, retval;
194     CIMTYPE type;
195     HRESULT hr;
196 
197     hr = IWbemServices_GetObject( services, class, 0, NULL, &service, NULL );
198     if (hr != S_OK)
199     {
200         win_skip( "Win32_Service not available\n" );
201         goto out;
202     }
203     type = 0xdeadbeef;
204     VariantInit( &state );
205     hr = IWbemClassObject_Get( service, stateW, 0, &state, &type, NULL );
206     ok( hr == S_OK, "failed to get service state %08x\n", hr );
207     ok( V_VT( &state ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &state ) );
208     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
209 
210     if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
211     {
212         out = NULL;
213         method = SysAllocString( startserviceW );
214         hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
215         ok( hr == S_OK, "failed to execute method %08x\n", hr );
216         SysFreeString( method );
217 
218         VariantInit( &retval );
219         hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
220         ok( hr == S_OK, "failed to get return value %08x\n", hr );
221         ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
222         IWbemClassObject_Release( out );
223     }
224     out = NULL;
225     method = SysAllocString( pauseserviceW );
226     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
227     ok( hr == S_OK, "failed to execute method %08x\n", hr );
228     SysFreeString( method );
229 
230     VariantInit( &retval );
231     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
232     ok( hr == S_OK, "failed to get return value %08x\n", hr );
233     ok( V_I4( &retval ), "unexpected success\n" );
234     IWbemClassObject_Release( out );
235 
236     out = NULL;
237     method = SysAllocString( resumeserviceW );
238     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
239     ok( hr == S_OK, "failed to execute method %08x\n", hr );
240     SysFreeString( method );
241 
242     VariantInit( &retval );
243     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
244     ok( hr == S_OK, "failed to get return value %08x\n", hr );
245     ok( V_I4( &retval ), "unexpected success\n" );
246     IWbemClassObject_Release( out );
247 
248     if (!lstrcmpW( V_BSTR( &state ), stoppedW ))
249     {
250         out = NULL;
251         method = SysAllocString( stopserviceW );
252         hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
253         ok( hr == S_OK, "failed to execute method %08x\n", hr );
254         SysFreeString( method );
255 
256         VariantInit( &retval );
257         hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, NULL, NULL );
258         ok( hr == S_OK, "failed to get return value %08x\n", hr );
259         ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
260         IWbemClassObject_Release( out );
261     }
262     VariantClear( &state );
263     IWbemClassObject_Release( service );
264 
265     service = NULL;
266     hr = IWbemServices_GetObject( services, NULL, 0, NULL, &service, NULL );
267     ok( hr == S_OK, "got %08x\n", hr );
268     if (service) IWbemClassObject_Release( service );
269 
270     service = NULL;
271     hr = IWbemServices_GetObject( services, empty, 0, NULL, &service, NULL );
272     ok( hr == S_OK, "got %08x\n", hr );
273     if (service) IWbemClassObject_Release( service );
274 
275 out:
276     SysFreeString( empty );
277     SysFreeString( class );
278 }
279 
280 static void test_Win32_Bios( IWbemServices *services )
281 {
282     static const WCHAR queryW[] =
283         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_', 'B','i','o','s',0};
284     static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
285     static const WCHAR identificationcodeW[] = {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
286     static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
287     static const WCHAR nameW[] = {'N','a','m','e',0};
288     static const WCHAR releasedateW[] = {'R','e','l','e','a','s','e','D','a','t','e',0};
289     static const WCHAR serialnumberW[] = {'S','e','r','i','a','l','N','u','m','b','e','r',0};
290     static const WCHAR smbiosbiosversionW[] = {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
291     static const WCHAR smbiosmajorversionW[] = {'S','M','B','I','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
292     static const WCHAR smbiosminorversionW[] = {'S','M','B','I','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
293     static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
294     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
295     IEnumWbemClassObject *result;
296     IWbemClassObject *obj;
297     CIMTYPE type;
298     ULONG count;
299     VARIANT val;
300     HRESULT hr;
301 
302     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
303     ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
304 
305     hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
306     ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
307 
308     type = 0xdeadbeef;
309     VariantInit( &val );
310     hr = IWbemClassObject_Get( obj, descriptionW, 0, &val, &type, NULL );
311     ok( hr == S_OK, "failed to get description %08x\n", hr );
312     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
313     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
314     trace( "description: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
315     VariantClear( &val );
316 
317     type = 0xdeadbeef;
318     VariantInit( &val );
319     hr = IWbemClassObject_Get( obj, identificationcodeW, 0, &val, &type, NULL );
320     ok( hr == S_OK, "failed to get identication code %08x\n", hr );
321     ok( V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
322     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
323     VariantClear( &val );
324 
325     type = 0xdeadbeef;
326     VariantInit( &val );
327     hr = IWbemClassObject_Get( obj, manufacturerW, 0, &val, &type, NULL );
328     ok( hr == S_OK, "failed to get manufacturer %08x\n", hr );
329     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
330     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
331     trace( "manufacturer: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
332     VariantClear( &val );
333 
334     type = 0xdeadbeef;
335     VariantInit( &val );
336     hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
337     ok( hr == S_OK, "failed to get name %08x\n", hr );
338     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
339     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
340     trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
341     VariantClear( &val );
342 
343     type = 0xdeadbeef;
344     VariantInit( &val );
345     hr = IWbemClassObject_Get( obj, releasedateW, 0, &val, &type, NULL );
346     ok( hr == S_OK, "failed to get release date %08x\n", hr );
347     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
348     ok( type == CIM_DATETIME, "unexpected type 0x%x\n", type );
349     trace( "release date: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
350     VariantClear( &val );
351 
352     type = 0xdeadbeef;
353     VariantInit( &val );
354     hr = IWbemClassObject_Get( obj, serialnumberW, 0, &val, &type, NULL );
355     ok( hr == S_OK, "failed to get serial number %08x\n", hr );
356     ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL /* Testbot VMs */,
357         "unexpected variant type 0x%x\n", V_VT( &val ) );
358     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
359     VariantClear( &val );
360 
361     type = 0xdeadbeef;
362     VariantInit( &val );
363     hr = IWbemClassObject_Get( obj, smbiosbiosversionW, 0, &val, &type, NULL );
364     ok( hr == S_OK, "failed to get bios version %08x\n", hr );
365     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
366     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
367     trace( "bios version: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
368     VariantClear( &val );
369 
370     type = 0xdeadbeef;
371     VariantInit( &val );
372     hr = IWbemClassObject_Get( obj, smbiosmajorversionW, 0, &val, &type, NULL );
373     ok( hr == S_OK, "failed to get bios major version %08x\n", hr );
374     ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
375     ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
376     trace( "bios major version: %u\n", V_I4( &val ) );
377 
378     type = 0xdeadbeef;
379     VariantInit( &val );
380     hr = IWbemClassObject_Get( obj, smbiosminorversionW, 0, &val, &type, NULL );
381     ok( hr == S_OK, "failed to get bios minor version %08x\n", hr );
382     ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
383     ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
384     trace( "bios minor version: %u\n", V_I4( &val ) );
385 
386     type = 0xdeadbeef;
387     VariantInit( &val );
388     hr = IWbemClassObject_Get( obj, versionW, 0, &val, &type, NULL );
389     ok( hr == S_OK, "failed to get version %08x\n", hr );
390     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
391     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
392     trace( "version: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
393     VariantClear( &val );
394 
395     IWbemClassObject_Release( obj );
396     IEnumWbemClassObject_Release( result );
397     SysFreeString( query );
398     SysFreeString( wql );
399 }
400 
401 static void test_Win32_Process( IWbemServices *services, BOOL use_full_path )
402 {
403     static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
404     static const WCHAR getownerW[] = {'G','e','t','O','w','n','e','r',0};
405     static const WCHAR userW[] = {'U','s','e','r',0};
406     static const WCHAR domainW[] = {'D','o','m','a','i','n',0};
407     static const WCHAR processW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
408     static const WCHAR idW[] = {'I','D',0};
409     static const WCHAR fmtW[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','.',
410         'H','a','n','d','l','e','=','"','%','u','"',0};
411     static const WCHAR full_path_fmt[] =
412         {'\\','\\','%','s','\\','R','O','O','T','\\','C','I','M','V','2',':',0};
413     static const LONG expected_flavor = WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
414                                         WBEM_FLAVOR_NOT_OVERRIDABLE |
415                                         WBEM_FLAVOR_ORIGIN_PROPAGATED;
416     WCHAR full_path[MAX_COMPUTERNAME_LENGTH + ARRAY_SIZE(full_path_fmt)];
417     BSTR class, method;
418     IWbemClassObject *process, *sig_in, *out;
419     IWbemQualifierSet *qualifiers;
420     VARIANT user, domain, retval, val;
421     DWORD full_path_len = 0;
422     LONG flavor;
423     CIMTYPE type;
424     HRESULT hr;
425 
426     if (use_full_path)
427     {
428         WCHAR server[MAX_COMPUTERNAME_LENGTH+1];
429 
430         full_path_len = ARRAY_SIZE(server);
431         ok( GetComputerNameW(server, &full_path_len), "GetComputerName failed\n" );
432         full_path_len = wsprintfW(full_path, full_path_fmt, server);
433     }
434 
435     class = SysAllocStringLen( NULL, full_path_len + ARRAY_SIZE( processW ) );
436     memcpy( class, full_path, full_path_len * sizeof(WCHAR) );
437     memcpy( class + full_path_len, processW, sizeof(processW) );
438     hr = IWbemServices_GetObject( services, class, 0, NULL, &process, NULL );
439     SysFreeString( class );
440     if (hr != S_OK)
441     {
442         win_skip( "Win32_Process not available\n" );
443         return;
444     }
445     sig_in = (void*)0xdeadbeef;
446     hr = IWbemClassObject_GetMethod( process, getownerW, 0, &sig_in, NULL );
447     ok( hr == S_OK, "failed to get GetOwner method %08x\n", hr );
448     ok( !sig_in, "sig_in != NULL\n");
449     IWbemClassObject_Release( process );
450 
451     out = NULL;
452     method = SysAllocString( getownerW );
453     class = SysAllocStringLen( NULL, full_path_len + ARRAY_SIZE( fmtW ) + 10 );
454     memcpy( class, full_path, full_path_len * sizeof(WCHAR) );
455     wsprintfW( class + full_path_len, fmtW, GetCurrentProcessId() );
456     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
457     ok( hr == S_OK, "failed to execute method %08x\n", hr );
458     SysFreeString( method );
459     SysFreeString( class );
460 
461     type = 0xdeadbeef;
462     VariantInit( &retval );
463     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
464     ok( hr == S_OK, "failed to get return value %08x\n", hr );
465     ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
466     ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
467     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
468 
469     type = 0xdeadbeef;
470     VariantInit( &user );
471     hr = IWbemClassObject_Get( out, userW, 0, &user, &type, NULL );
472     ok( hr == S_OK, "failed to get user %08x\n", hr );
473     ok( V_VT( &user ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &user ) );
474     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
475     trace("%s\n", wine_dbgstr_w(V_BSTR(&user)));
476 
477     type = 0xdeadbeef;
478     VariantInit( &domain );
479     hr = IWbemClassObject_Get( out, domainW, 0, &domain, &type, NULL );
480     ok( hr == S_OK, "failed to get domain %08x\n", hr );
481     ok( V_VT( &domain ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &domain ) );
482     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
483     trace("%s\n", wine_dbgstr_w(V_BSTR(&domain)));
484 
485     hr = IWbemClassObject_GetPropertyQualifierSet( out, userW, &qualifiers );
486     ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
487 
488     flavor = -1;
489     V_I4(&val) = -1;
490     V_VT(&val) = VT_ERROR;
491     hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
492     ok( hr == S_OK, "got %08x\n", hr );
493     ok( flavor == expected_flavor, "got %d\n", flavor );
494     ok( V_VT(&val) == VT_I4, "got %u\n", V_VT(&val) );
495     ok( V_I4(&val) == 0, "got %u\n", V_I4(&val) );
496     VariantClear( &val );
497 
498     IWbemQualifierSet_Release( qualifiers );
499     hr = IWbemClassObject_GetPropertyQualifierSet( out, domainW, &qualifiers );
500     ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
501 
502     flavor = -1;
503     V_I4(&val) = -1;
504     V_VT(&val) = VT_ERROR;
505     hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
506     ok( hr == S_OK, "got %08x\n", hr );
507     ok( flavor == expected_flavor, "got %d\n", flavor );
508     ok( V_VT(&val) == VT_I4, "got %u\n", V_VT(&val) );
509     ok( V_I4(&val) == 1, "got %u\n", V_I4(&val) );
510     VariantClear( &val );
511 
512     IWbemQualifierSet_Release( qualifiers );
513     hr = IWbemClassObject_GetPropertyQualifierSet( out, returnvalueW, &qualifiers );
514     ok( hr == S_OK, "failed to get qualifier set %08x\n", hr );
515 
516     hr = IWbemQualifierSet_Get( qualifiers, idW, 0, &val, &flavor );
517     ok( hr == WBEM_E_NOT_FOUND, "got %08x\n", hr );
518 
519     IWbemQualifierSet_Release( qualifiers );
520     VariantClear( &user );
521     VariantClear( &domain );
522     IWbemClassObject_Release( out );
523 }
524 
525 static void test_Win32_ComputerSystem( IWbemServices *services )
526 {
527     static const WCHAR backslashW[] = {'\\',0};
528     static const WCHAR memorytypeW[] = {'M','e','m','o','r','y','T','y','p','e',0};
529     static const WCHAR modelW[] = {'M','o','d','e','l',0};
530     static const WCHAR nameW[] = {'N','a','m','e',0};
531     static const WCHAR usernameW[] = {'U','s','e','r','N','a','m','e',0};
532     static const WCHAR queryW[] =
533         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
534          'C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
535     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
536     IEnumWbemClassObject *result;
537     IWbemClassObject *service;
538     VARIANT value;
539     CIMTYPE type;
540     HRESULT hr;
541     WCHAR compname[MAX_COMPUTERNAME_LENGTH + 1];
542     WCHAR username[128];
543     DWORD len, count;
544 
545     len = ARRAY_SIZE( compname );
546     if (!GetComputerNameW( compname, &len ))
547         compname[0] = 0;
548 
549     lstrcpyW( username, compname );
550     lstrcatW( username, backslashW );
551     len = ARRAY_SIZE( username ) - lstrlenW( username );
552     if (!GetUserNameW( username + lstrlenW( username ), &len ))
553         username[0] = 0;
554 
555     if (!compname[0] || !username[0])
556     {
557         skip( "Failed to get user or computer name\n" );
558         goto out;
559     }
560 
561     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
562     if (hr != S_OK)
563     {
564         win_skip( "Win32_ComputerSystem not available\n" );
565         goto out;
566     }
567 
568     hr = IEnumWbemClassObject_Next( result, 10000, 1, &service, &count );
569     ok( hr == S_OK, "got %08x\n", hr );
570 
571     type = 0xdeadbeef;
572     VariantInit( &value );
573     hr = IWbemClassObject_Get( service, memorytypeW, 0, &value, &type, NULL );
574     ok( hr == WBEM_E_NOT_FOUND, "got %08x\n", hr );
575 
576     type = 0xdeadbeef;
577     VariantInit( &value );
578     hr = IWbemClassObject_Get( service, modelW, 0, &value, &type, NULL );
579     ok( hr == S_OK, "failed to get model %08x\n", hr );
580     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
581     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
582     trace( "model: %s\n", wine_dbgstr_w(V_BSTR( &value )) );
583     VariantClear( &value );
584 
585     type = 0xdeadbeef;
586     VariantInit( &value );
587     hr = IWbemClassObject_Get( service, nameW, 0, &value, &type, NULL );
588     ok( hr == S_OK, "failed to get computer name %08x\n", hr );
589     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
590     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
591     ok( !lstrcmpiW( V_BSTR( &value ), compname ), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(compname) );
592     VariantClear( &value );
593 
594     type = 0xdeadbeef;
595     VariantInit( &value );
596     hr = IWbemClassObject_Get( service, usernameW, 0, &value, &type, NULL );
597     ok( hr == S_OK, "failed to get computer name %08x\n", hr );
598     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
599     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
600     ok( !lstrcmpiW( V_BSTR( &value ), username ), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value)), wine_dbgstr_w(username) );
601     VariantClear( &value );
602 
603     IWbemClassObject_Release( service );
604     IEnumWbemClassObject_Release( result );
605 out:
606     SysFreeString( query );
607     SysFreeString( wql );
608 }
609 
610 static void test_Win32_SystemEnclosure( IWbemServices *services )
611 {
612     static const WCHAR queryW[] =
613         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
614          'S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
615     static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
616     static const WCHAR chassistypesW[] = {'C','h','a','s','s','i','s','T','y','p','e','s',0};
617     static const WCHAR descriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
618     static const WCHAR lockpresentW[] = {'L','o','c','k','P','r','e','s','e','n','t',0};
619     static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
620     static const WCHAR nameW[] = {'N','a','m','e',0};
621     static const WCHAR tagW[] = {'T','a','g',0};
622     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
623     IEnumWbemClassObject *result;
624     IWbemClassObject *obj;
625     CIMTYPE type;
626     ULONG count;
627     VARIANT val;
628     DWORD *data;
629     HRESULT hr;
630 
631     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
632     ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
633 
634     hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
635     ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
636 
637     type = 0xdeadbeef;
638     VariantInit( &val );
639     hr = IWbemClassObject_Get( obj, captionW, 0, &val, &type, NULL );
640     ok( hr == S_OK, "failed to get caption %08x\n", hr );
641     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
642     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
643     trace( "caption: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
644     VariantClear( &val );
645 
646     type = 0xdeadbeef;
647     VariantInit( &val );
648     hr = IWbemClassObject_Get( obj, chassistypesW, 0, &val, &type, NULL );
649     ok( hr == S_OK, "failed to get chassis types %08x\n", hr );
650     ok( V_VT( &val ) == (VT_I4|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &val ) );
651     ok( type == (CIM_UINT16|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
652     hr = SafeArrayAccessData( V_ARRAY( &val ), (void **)&data );
653     ok( hr == S_OK, "SafeArrayAccessData failed %x\n", hr );
654     if (SUCCEEDED(hr))
655     {
656         LONG i, lower, upper;
657 
658         hr = SafeArrayGetLBound( V_ARRAY( &val ), 1, &lower );
659         ok( hr == S_OK, "SafeArrayGetLBound failed %x\n", hr );
660         hr = SafeArrayGetUBound( V_ARRAY( &val ), 1, &upper );
661         ok( hr == S_OK, "SafeArrayGetUBound failed %x\n", hr );
662         if (V_VT( &val ) == (VT_I4|VT_ARRAY))
663         {
664             for (i = 0; i < upper - lower + 1; i++)
665                 trace( "chassis type: %u\n", data[i] );
666         }
667         hr = SafeArrayUnaccessData( V_ARRAY( &val ) );
668         ok( hr == S_OK, "SafeArrayUnaccessData failed %x\n", hr );
669     }
670     VariantClear( &val );
671 
672     type = 0xdeadbeef;
673     VariantInit( &val );
674     hr = IWbemClassObject_Get( obj, descriptionW, 0, &val, &type, NULL );
675     ok( hr == S_OK, "failed to get description %08x\n", hr );
676     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
677     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
678     trace( "description: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
679     VariantClear( &val );
680 
681     type = 0xdeadbeef;
682     VariantInit( &val );
683     hr = IWbemClassObject_Get( obj, lockpresentW, 0, &val, &type, NULL );
684     ok( hr == S_OK, "failed to get lockpresent %08x\n", hr );
685     ok( V_VT( &val ) == VT_BOOL, "unexpected variant type 0x%x\n", V_VT( &val ) );
686     ok( type == CIM_BOOLEAN, "unexpected type 0x%x\n", type );
687     trace( "lockpresent: %u\n", V_BOOL( &val ) );
688     VariantClear( &val );
689 
690     type = 0xdeadbeef;
691     VariantInit( &val );
692     hr = IWbemClassObject_Get( obj, manufacturerW, 0, &val, &type, NULL );
693     ok( hr == S_OK, "failed to get manufacturer %08x\n", hr );
694     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
695     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
696     trace( "manufacturer: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
697     VariantClear( &val );
698 
699     type = 0xdeadbeef;
700     VariantInit( &val );
701     hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
702     ok( hr == S_OK, "failed to get name %08x\n", hr );
703     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
704     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
705     trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
706     VariantClear( &val );
707 
708     type = 0xdeadbeef;
709     VariantInit( &val );
710     hr = IWbemClassObject_Get( obj, tagW, 0, &val, &type, NULL );
711     ok( hr == S_OK, "failed to get tag %08x\n", hr );
712     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
713     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
714     trace( "tag: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
715     VariantClear( &val );
716 
717     IWbemClassObject_Release( obj );
718     IEnumWbemClassObject_Release( result );
719     SysFreeString( query );
720     SysFreeString( wql );
721 }
722 
723 static void test_StdRegProv( IWbemServices *services )
724 {
725     static const WCHAR createkeyW[] = {'C','r','e','a','t','e','K','e','y',0};
726     static const WCHAR enumkeyW[] = {'E','n','u','m','K','e','y',0};
727     static const WCHAR enumvaluesW[] = {'E','n','u','m','V','a','l','u','e','s',0};
728     static const WCHAR getstringvalueW[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
729     static const WCHAR stdregprovW[] = {'S','t','d','R','e','g','P','r','o','v',0};
730     static const WCHAR defkeyW[] = {'h','D','e','f','K','e','y',0};
731     static const WCHAR subkeynameW[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
732     static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
733     static const WCHAR namesW[] = {'s','N','a','m','e','s',0};
734     static const WCHAR typesW[] = {'T','y','p','e','s',0};
735     static const WCHAR valueW[] = {'s','V','a','l','u','e',0};
736     static const WCHAR valuenameW[] = {'s','V','a','l','u','e','N','a','m','e',0};
737     static const WCHAR programfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
738     static const WCHAR windowsW[] =
739         {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
740          'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
741     static const WCHAR regtestW[] =
742         {'S','o','f','t','w','a','r','e','\\','S','t','d','R','e','g','P','r','o','v','T','e','s','t',0};
743     BSTR class = SysAllocString( stdregprovW ), method, name;
744     IWbemClassObject *reg, *sig_in, *sig_out, *in, *out;
745     VARIANT defkey, subkey, retval, names, types, value, valuename;
746     CIMTYPE type;
747     HRESULT hr;
748     LONG res;
749 
750     hr = IWbemServices_GetObject( services, class, 0, NULL, &reg, NULL );
751     if (hr != S_OK)
752     {
753         win_skip( "StdRegProv not available\n" );
754         return;
755     }
756 
757     hr = IWbemClassObject_BeginMethodEnumeration( reg, 0 );
758     ok( hr == S_OK, "got %08x\n", hr );
759 
760     while (IWbemClassObject_NextMethod( reg, 0, &name, &sig_in, &sig_out ) == S_OK)
761     {
762         SysFreeString( name );
763         IWbemClassObject_Release( sig_in );
764         IWbemClassObject_Release( sig_out );
765     }
766 
767     hr = IWbemClassObject_EndMethodEnumeration( reg );
768     ok( hr == S_OK, "got %08x\n", hr );
769 
770     hr = IWbemClassObject_BeginEnumeration( reg, 0 );
771     ok( hr == S_OK, "got %08x\n", hr );
772 
773     while (IWbemClassObject_Next( reg, 0, &name, NULL, NULL, NULL ) == S_OK)
774         SysFreeString( name );
775 
776     hr = IWbemClassObject_EndEnumeration( reg );
777     ok( hr == S_OK, "got %08x\n", hr );
778 
779     hr = IWbemClassObject_GetMethod( reg, createkeyW, 0, &sig_in, NULL );
780     ok( hr == S_OK, "failed to get CreateKey method %08x\n", hr );
781 
782     hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
783     ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
784 
785     V_VT( &defkey ) = VT_I4;
786     V_I4( &defkey ) = 0x80000001;
787     hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
788     ok( hr == S_OK, "failed to set root %08x\n", hr );
789 
790     V_VT( &subkey ) = VT_BSTR;
791     V_BSTR( &subkey ) = SysAllocString( regtestW );
792     hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
793     ok( hr == S_OK, "failed to set subkey %08x\n", hr );
794 
795     out = NULL;
796     method = SysAllocString( createkeyW );
797     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
798     ok( hr == S_OK, "failed to execute method %08x\n", hr );
799     SysFreeString( method );
800 
801     type = 0xdeadbeef;
802     VariantInit( &retval );
803     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
804     ok( hr == S_OK, "failed to get return value %08x\n", hr );
805     ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
806     ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
807     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
808 
809     res = RegDeleteKeyW( HKEY_CURRENT_USER, regtestW );
810     ok( !res, "got %d\n", res );
811 
812     VariantClear( &subkey );
813     IWbemClassObject_Release( in );
814     IWbemClassObject_Release( out );
815     IWbemClassObject_Release( sig_in );
816 
817     hr = IWbemClassObject_GetMethod( reg, enumkeyW, 0, &sig_in, NULL );
818     ok( hr == S_OK, "failed to get EnumKey method %08x\n", hr );
819 
820     hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
821     ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
822 
823     V_VT( &defkey ) = VT_I4;
824     V_I4( &defkey ) = 0x80000002;
825     hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
826     ok( hr == S_OK, "failed to set root %08x\n", hr );
827 
828     V_VT( &subkey ) = VT_BSTR;
829     V_BSTR( &subkey ) = SysAllocString( windowsW );
830     hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
831     ok( hr == S_OK, "failed to set subkey %08x\n", hr );
832 
833     out = NULL;
834     method = SysAllocString( enumkeyW );
835     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
836     ok( hr == S_OK, "failed to execute method %08x\n", hr );
837     SysFreeString( method );
838 
839     type = 0xdeadbeef;
840     VariantInit( &retval );
841     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
842     ok( hr == S_OK, "failed to get return value %08x\n", hr );
843     ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
844     ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
845     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
846 
847     type = 0xdeadbeef;
848     VariantInit( &names );
849     hr = IWbemClassObject_Get( out, namesW, 0, &names, &type, NULL );
850     ok( hr == S_OK, "failed to get names %08x\n", hr );
851     ok( V_VT( &names ) == (VT_BSTR|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &names ) );
852     ok( type == (CIM_STRING|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
853 
854     VariantClear( &names );
855     VariantClear( &subkey );
856     IWbemClassObject_Release( in );
857     IWbemClassObject_Release( out );
858     IWbemClassObject_Release( sig_in );
859 
860     hr = IWbemClassObject_GetMethod( reg, enumvaluesW, 0, &sig_in, NULL );
861     ok( hr == S_OK, "failed to get EnumValues method %08x\n", hr );
862 
863     hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
864     ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
865 
866     V_VT( &defkey ) = VT_I4;
867     V_I4( &defkey ) = 0x80000002;
868     hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
869     ok( hr == S_OK, "failed to set root %08x\n", hr );
870 
871     V_VT( &subkey ) = VT_BSTR;
872     V_BSTR( &subkey ) = SysAllocString( windowsW );
873     hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
874     ok( hr == S_OK, "failed to set subkey %08x\n", hr );
875 
876     out = NULL;
877     method = SysAllocString( enumvaluesW );
878     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
879     ok( hr == S_OK, "failed to execute method %08x\n", hr );
880     SysFreeString( method );
881 
882     type = 0xdeadbeef;
883     VariantInit( &retval );
884     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
885     ok( hr == S_OK, "failed to get return value %08x\n", hr );
886     ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
887     ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
888     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
889 
890     type = 0xdeadbeef;
891     VariantInit( &names );
892     hr = IWbemClassObject_Get( out, namesW, 0, &names, &type, NULL );
893     ok( hr == S_OK, "failed to get names %08x\n", hr );
894     ok( V_VT( &names ) == (VT_BSTR|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &names ) );
895     ok( type == (CIM_STRING|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
896 
897     type = 0xdeadbeef;
898     VariantInit( &types );
899     hr = IWbemClassObject_Get( out, typesW, 0, &types, &type, NULL );
900     ok( hr == S_OK, "failed to get names %08x\n", hr );
901     ok( V_VT( &types ) == (VT_I4|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &types ) );
902     ok( type == (CIM_SINT32|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
903 
904     VariantClear( &types );
905     VariantClear( &names );
906     VariantClear( &subkey );
907     IWbemClassObject_Release( in );
908     IWbemClassObject_Release( out );
909     IWbemClassObject_Release( sig_in );
910 
911     hr = IWbemClassObject_GetMethod( reg, getstringvalueW, 0, &sig_in, NULL );
912     ok( hr == S_OK, "failed to get GetStringValue method %08x\n", hr );
913 
914     hr = IWbemClassObject_SpawnInstance( sig_in, 0, &in );
915     ok( hr == S_OK, "failed to spawn instance %08x\n", hr );
916 
917     V_VT( &defkey ) = VT_I4;
918     V_I4( &defkey ) = 0x80000002;
919     hr = IWbemClassObject_Put( in, defkeyW, 0, &defkey, 0 );
920     ok( hr == S_OK, "failed to set root %08x\n", hr );
921 
922     V_VT( &subkey ) = VT_BSTR;
923     V_BSTR( &subkey ) = SysAllocString( windowsW );
924     hr = IWbemClassObject_Put( in, subkeynameW, 0, &subkey, 0 );
925     ok( hr == S_OK, "failed to set subkey %08x\n", hr );
926 
927     V_VT( &valuename ) = VT_BSTR;
928     V_BSTR( &valuename ) = SysAllocString( programfilesW );
929     hr = IWbemClassObject_Put( in, valuenameW, 0, &valuename, 0 );
930     ok( hr == S_OK, "failed to set value name %08x\n", hr );
931 
932     out = NULL;
933     method = SysAllocString( getstringvalueW );
934     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, in, &out, NULL );
935     ok( hr == S_OK, "failed to execute method %08x\n", hr );
936     SysFreeString( method );
937 
938     type = 0xdeadbeef;
939     VariantInit( &retval );
940     hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
941     ok( hr == S_OK, "failed to get return value %08x\n", hr );
942     ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
943     ok( !V_I4( &retval ), "unexpected error %u\n", V_I4( &retval ) );
944     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
945 
946     type = 0xdeadbeef;
947     VariantInit( &value );
948     hr = IWbemClassObject_Get( out, valueW, 0, &value, &type, NULL );
949     ok( hr == S_OK, "failed to get value %08x\n", hr );
950     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
951     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
952 
953     VariantClear( &value );
954     VariantClear( &valuename );
955     VariantClear( &subkey );
956     IWbemClassObject_Release( in );
957     IWbemClassObject_Release( out );
958     IWbemClassObject_Release( sig_in );
959 
960     IWbemClassObject_Release( reg );
961     SysFreeString( class );
962 }
963 
964 static HRESULT WINAPI sink_QueryInterface(
965     IWbemObjectSink *iface, REFIID riid, void **ppv )
966 {
967     *ppv = NULL;
968     if (IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IWbemObjectSink, riid ))
969     {
970         *ppv = iface;
971         IWbemObjectSink_AddRef( iface );
972         return S_OK;
973     }
974     return E_NOINTERFACE;
975 }
976 
977 static ULONG sink_refs;
978 
979 static ULONG WINAPI sink_AddRef(
980     IWbemObjectSink *iface )
981 {
982     return ++sink_refs;
983 }
984 
985 static ULONG WINAPI sink_Release(
986     IWbemObjectSink *iface )
987 {
988     return --sink_refs;
989 }
990 
991 static HRESULT WINAPI sink_Indicate(
992     IWbemObjectSink *iface, LONG count, IWbemClassObject **objects )
993 {
994     trace("Indicate: %d, %p\n", count, objects);
995     return S_OK;
996 }
997 
998 static HRESULT WINAPI sink_SetStatus(
999     IWbemObjectSink *iface, LONG flags, HRESULT hresult, BSTR str_param, IWbemClassObject *obj_param )
1000 {
1001     trace("SetStatus: %08x, %08x, %s, %p\n", flags, hresult, wine_dbgstr_w(str_param), obj_param);
1002     return S_OK;
1003 }
1004 
1005 static IWbemObjectSinkVtbl sink_vtbl =
1006 {
1007     sink_QueryInterface,
1008     sink_AddRef,
1009     sink_Release,
1010     sink_Indicate,
1011     sink_SetStatus
1012 };
1013 
1014 static IWbemObjectSink sink = { &sink_vtbl };
1015 
1016 static void test_notification_query_async( IWbemServices *services )
1017 {
1018     static const WCHAR queryW[] =
1019         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1020          'D','e','v','i','c','e','C','h','a','n','g','e','E','v','e','n','t',0};
1021     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1022     ULONG prev_sink_refs;
1023     HRESULT hr;
1024 
1025     hr = IWbemServices_ExecNotificationQueryAsync( services, wql, query, 0, NULL, NULL );
1026     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
1027 
1028     prev_sink_refs = sink_refs;
1029     hr = IWbemServices_ExecNotificationQueryAsync( services, wql, query, 0, NULL, &sink );
1030     ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
1031     ok( sink_refs > prev_sink_refs || broken(!sink_refs), "got %u refs\n", sink_refs );
1032 
1033     hr =  IWbemServices_CancelAsyncCall( services, &sink );
1034     ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
1035 
1036     SysFreeString( wql );
1037     SysFreeString( query );
1038 }
1039 
1040 static void test_query_async( IWbemServices *services )
1041 {
1042     static const WCHAR queryW[] =
1043         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1044          'P','r','o','c','e','s','s',0};
1045     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1046     HRESULT hr;
1047 
1048     hr = IWbemServices_ExecQueryAsync( services, wql, query, 0, NULL, NULL );
1049     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
1050 
1051     hr = IWbemServices_ExecQueryAsync( services, wql, query, 0, NULL, &sink );
1052     ok( hr == S_OK || broken(hr == WBEM_E_NOT_FOUND), "got %08x\n", hr );
1053 
1054     hr =  IWbemServices_CancelAsyncCall( services, NULL );
1055     ok( hr == WBEM_E_INVALID_PARAMETER, "got %08x\n", hr );
1056 
1057     hr =  IWbemServices_CancelAsyncCall( services, &sink );
1058     ok( hr == S_OK, "got %08x\n", hr );
1059 
1060     SysFreeString( wql );
1061     SysFreeString( query );
1062 }
1063 
1064 static void test_GetNames( IWbemServices *services )
1065 {
1066     static const WCHAR queryW[] =
1067         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1068          'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
1069     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1070     IEnumWbemClassObject *result;
1071     HRESULT hr;
1072 
1073     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1074     ok( hr == S_OK, "got %08x\n", hr );
1075 
1076     for (;;)
1077     {
1078         IWbemClassObject *obj;
1079         SAFEARRAY *names;
1080         ULONG count;
1081         VARIANT val;
1082 
1083         IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1084         if (!count) break;
1085 
1086         VariantInit( &val );
1087         hr = IWbemClassObject_GetNames( obj, NULL, WBEM_FLAG_NONSYSTEM_ONLY, &val, &names );
1088         ok( hr == S_OK, "got %08x\n", hr );
1089 
1090         SafeArrayDestroy( names );
1091         IWbemClassObject_Release( obj );
1092     }
1093     IEnumWbemClassObject_Release( result );
1094     SysFreeString( query );
1095     SysFreeString( wql );
1096 }
1097 
1098 static void test_SystemSecurity( IWbemServices *services )
1099 {
1100     static const WCHAR systemsecurityW[] = {'_','_','S','y','s','t','e','m','S','e','c','u','r','i','t','y',0};
1101     static const WCHAR getsdW[] = {'G','e','t','S','D',0};
1102     static const WCHAR returnvalueW[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
1103     static const WCHAR sdW[] = {'S','D',0};
1104     BSTR class = SysAllocString( systemsecurityW ), method;
1105     IWbemClassObject *reg, *out;
1106     VARIANT retval, var_sd;
1107     void *data;
1108     SECURITY_DESCRIPTOR_RELATIVE *sd;
1109     CIMTYPE type;
1110     HRESULT hr;
1111     BYTE sid_admin_buffer[SECURITY_MAX_SID_SIZE];
1112     SID *sid_admin = (SID*)sid_admin_buffer;
1113     DWORD sid_size;
1114     BOOL ret;
1115 
1116     hr = IWbemServices_GetObject( services, class, 0, NULL, &reg, NULL );
1117     if (hr != S_OK)
1118     {
1119         win_skip( "__SystemSecurity not available\n" );
1120         return;
1121     }
1122     IWbemClassObject_Release( reg );
1123 
1124     sid_size = sizeof(sid_admin_buffer);
1125     ret = CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, sid_admin, &sid_size );
1126     ok( ret, "CreateWellKnownSid failed\n" );
1127 
1128     out = NULL;
1129     method = SysAllocString( getsdW );
1130     hr = IWbemServices_ExecMethod( services, class, method, 0, NULL, NULL, &out, NULL );
1131     ok( hr == S_OK || hr == WBEM_E_ACCESS_DENIED, "failed to execute method %08x\n", hr );
1132     SysFreeString( method );
1133 
1134     if (SUCCEEDED(hr))
1135     {
1136         type = 0xdeadbeef;
1137         VariantInit( &retval );
1138         hr = IWbemClassObject_Get( out, returnvalueW, 0, &retval, &type, NULL );
1139         ok( hr == S_OK, "failed to get return value %08x\n", hr );
1140         ok( V_VT( &retval ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &retval ) );
1141         ok( !V_I4( &retval ), "unexpected error %u\n", V_UI4( &retval ) );
1142         ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1143 
1144         type = 0xdeadbeef;
1145         VariantInit( &var_sd );
1146         hr = IWbemClassObject_Get( out, sdW, 0, &var_sd, &type, NULL );
1147         ok( hr == S_OK, "failed to get names %08x\n", hr );
1148         ok( V_VT( &var_sd ) == (VT_UI1|VT_ARRAY), "unexpected variant type 0x%x\n", V_VT( &var_sd ) );
1149         ok( type == (CIM_UINT8|CIM_FLAG_ARRAY), "unexpected type 0x%x\n", type );
1150 
1151         hr = SafeArrayAccessData( V_ARRAY( &var_sd ), &data );
1152         ok( hr == S_OK, "SafeArrayAccessData failed %x\n", hr );
1153         if (SUCCEEDED(hr))
1154         {
1155             sd = data;
1156 
1157             ok( (sd->Control & SE_SELF_RELATIVE) == SE_SELF_RELATIVE, "relative flag unset\n" );
1158             ok( sd->Owner != 0, "no owner SID\n");
1159             ok( sd->Group != 0, "no owner SID\n");
1160             ok( EqualSid( (PSID)((LPBYTE)sd + sd->Owner), sid_admin ), "unexpected owner SID\n" );
1161             ok( EqualSid( (PSID)((LPBYTE)sd + sd->Group), sid_admin ), "unexpected group SID\n" );
1162 
1163             hr = SafeArrayUnaccessData( V_ARRAY( &var_sd ) );
1164             ok( hr == S_OK, "SafeArrayUnaccessData failed %x\n", hr );
1165         }
1166 
1167         VariantClear( &var_sd );
1168         IWbemClassObject_Release( out );
1169     }
1170     else if (hr == WBEM_E_ACCESS_DENIED)
1171         win_skip( "insufficient privs to test __SystemSecurity\n" );
1172 
1173     SysFreeString( class );
1174 }
1175 
1176 static void test_Win32_OperatingSystem( IWbemServices *services )
1177 {
1178     static const WCHAR queryW[] =
1179         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1180          'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
1181     static const WCHAR buildnumberW[] = {'B','u','i','l','d','N','u','m','b','e','r',0};
1182     static const WCHAR captionW[] = {'C','a','p','t','i','o','n',0};
1183     static const WCHAR csdversionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
1184     static const WCHAR freephysicalmemoryW[] = {'F','r','e','e','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
1185     static const WCHAR nameW[] = {'N','a','m','e',0};
1186     static const WCHAR osproductsuiteW[] = {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
1187     static const WCHAR ostypeW[] = {'O','S','T','y','p','e',0};
1188     static const WCHAR suitemaskW[] = {'S','u','i','t','e','M','a','s','k',0};
1189     static const WCHAR versionW[] = {'V','e','r','s','i','o','n',0};
1190     static const WCHAR servicepackmajorW[] =
1191         {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
1192     static const WCHAR servicepackminorW[] =
1193         {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
1194     static const WCHAR totalvisiblememorysizeW[] =
1195         {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
1196     static const WCHAR totalvirtualmemorysizeW[] =
1197         {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
1198     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1199     IEnumWbemClassObject *result;
1200     IWbemClassObject *obj;
1201     CIMTYPE type;
1202     ULONG count;
1203     VARIANT val;
1204     HRESULT hr;
1205 
1206     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1207     ok( hr == S_OK, "IWbemServices_ExecQuery failed %08x\n", hr );
1208 
1209     hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1210     ok( hr == S_OK, "IEnumWbemClassObject_Next failed %08x\n", hr );
1211 
1212     hr = IWbemClassObject_BeginEnumeration( obj, 0 );
1213     ok( hr == S_OK, "got %08x\n", hr );
1214 
1215     while (IWbemClassObject_Next( obj, 0, NULL, NULL, NULL, NULL ) == S_OK) {}
1216 
1217     hr = IWbemClassObject_EndEnumeration( obj );
1218     ok( hr == S_OK, "got %08x\n", hr );
1219 
1220     type = 0xdeadbeef;
1221     VariantInit( &val );
1222     hr = IWbemClassObject_Get( obj, buildnumberW, 0, &val, &type, NULL );
1223     ok( hr == S_OK, "failed to get buildnumber %08x\n", hr );
1224     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1225     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1226     trace( "buildnumber: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1227     VariantClear( &val );
1228 
1229     type = 0xdeadbeef;
1230     VariantInit( &val );
1231     hr = IWbemClassObject_Get( obj, captionW, 0, &val, &type, NULL );
1232     ok( hr == S_OK, "failed to get caption %08x\n", hr );
1233     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1234     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1235     trace( "caption: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1236     VariantClear( &val );
1237 
1238     type = 0xdeadbeef;
1239     VariantInit( &val );
1240     hr = IWbemClassObject_Get( obj, csdversionW, 0, &val, &type, NULL );
1241     ok( hr == S_OK, "failed to get csdversion %08x\n", hr );
1242     ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1243     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1244     trace( "csdversion: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1245     VariantClear( &val );
1246 
1247     type = 0xdeadbeef;
1248     VariantInit( &val );
1249     hr = IWbemClassObject_Get( obj, freephysicalmemoryW, 0, &val, &type, NULL );
1250     ok( hr == S_OK, "failed to get free physical memory size %08x\n", hr );
1251     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1252     ok( type == CIM_UINT64, "unexpected type 0x%x\n", type );
1253     trace( "freephysicalmemory %s\n", wine_dbgstr_w(V_BSTR(&val)) );
1254     VariantClear( &val );
1255 
1256     type = 0xdeadbeef;
1257     VariantInit( &val );
1258     hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
1259     ok( hr == S_OK, "failed to get name %08x\n", hr );
1260     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1261     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1262     trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1263     VariantClear( &val );
1264 
1265     type = 0xdeadbeef;
1266     VariantInit( &val );
1267     hr = IWbemClassObject_Get( obj, osproductsuiteW, 0, &val, &type, NULL );
1268     ok( hr == S_OK, "failed to get osproductsuite %08x\n", hr );
1269     ok( V_VT( &val ) == VT_I4 || broken(V_VT( &val ) == VT_NULL) /* winxp */, "unexpected variant type 0x%x\n", V_VT( &val ) );
1270     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1271     trace( "osproductsuite: %d (%08x)\n", V_I4( &val ), V_I4( &val ) );
1272     VariantClear( &val );
1273 
1274     type = 0xdeadbeef;
1275     VariantInit( &val );
1276     hr = IWbemClassObject_Get( obj, ostypeW, 0, &val, &type, NULL );
1277     ok( hr == S_OK, "failed to get ostype %08x\n", hr );
1278     ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1279     ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1280     trace( "ostype: %d\n", V_I4( &val ) );
1281     VariantClear( &val );
1282 
1283     type = 0xdeadbeef;
1284     VariantInit( &val );
1285     hr = IWbemClassObject_Get( obj, servicepackmajorW, 0, &val, &type, NULL );
1286     ok( hr == S_OK, "failed to get servicepackmajor %08x\n", hr );
1287     ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1288     ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1289     trace( "servicepackmajor: %d\n", V_I4( &val ) );
1290     VariantClear( &val );
1291 
1292     type = 0xdeadbeef;
1293     VariantInit( &val );
1294     hr = IWbemClassObject_Get( obj, servicepackminorW, 0, &val, &type, NULL );
1295     ok( hr == S_OK, "failed to get servicepackminor %08x\n", hr );
1296     ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1297     ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1298     trace( "servicepackminor: %d\n", V_I4( &val ) );
1299     VariantClear( &val );
1300 
1301     type = 0xdeadbeef;
1302     VariantInit( &val );
1303     hr = IWbemClassObject_Get( obj, suitemaskW, 0, &val, &type, NULL );
1304     ok( hr == S_OK, "failed to get suitemask %08x\n", hr );
1305     ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1306     ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1307     trace( "suitemask: %d (%08x)\n", V_I4( &val ), V_I4( &val ) );
1308     VariantClear( &val );
1309 
1310     type = 0xdeadbeef;
1311     VariantInit( &val );
1312     hr = IWbemClassObject_Get( obj, versionW, 0, &val, &type, NULL );
1313     ok( hr == S_OK, "failed to get version %08x\n", hr );
1314     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1315     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1316     trace( "version: %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1317     VariantClear( &val );
1318 
1319     type = 0xdeadbeef;
1320     VariantInit( &val );
1321     hr = IWbemClassObject_Get( obj, totalvisiblememorysizeW, 0, &val, &type, NULL );
1322     ok( hr == S_OK, "failed to get visible memory size %08x\n", hr );
1323     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1324     ok( type == CIM_UINT64, "unexpected type 0x%x\n", type );
1325     trace( "totalvisiblememorysize %s\n", wine_dbgstr_w(V_BSTR(&val)) );
1326     VariantClear( &val );
1327 
1328     type = 0xdeadbeef;
1329     VariantInit( &val );
1330     hr = IWbemClassObject_Get( obj, totalvirtualmemorysizeW, 0, &val, &type, NULL );
1331     ok( hr == S_OK, "failed to get virtual memory size %08x\n", hr );
1332     ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1333     ok( type == CIM_UINT64, "unexpected type 0x%x\n", type );
1334     trace( "totalvirtualmemorysize %s\n", wine_dbgstr_w(V_BSTR(&val)) );
1335     VariantClear( &val );
1336 
1337     IWbemClassObject_Release( obj );
1338     IEnumWbemClassObject_Release( result );
1339     SysFreeString( query );
1340     SysFreeString( wql );
1341 }
1342 
1343 static void test_Win32_ComputerSystemProduct( IWbemServices *services )
1344 {
1345     static const WCHAR identifyingnumberW[] =
1346         {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
1347     static const WCHAR nameW[] =
1348         {'N','a','m','e',0};
1349     static const WCHAR skunumberW[] =
1350         {'S','K','U','N','u','m','b','e','r',0};
1351     static const WCHAR uuidW[] =
1352         {'U','U','I','D',0};
1353     static const WCHAR vendorW[] =
1354         {'V','e','n','d','o','r',0};
1355     static const WCHAR versionW[] =
1356         {'V','e','r','s','i','o','n',0};
1357     static const WCHAR queryW[] =
1358         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1359          'C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
1360     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1361     IEnumWbemClassObject *result;
1362     IWbemClassObject *obj;
1363     VARIANT value;
1364     CIMTYPE type;
1365     HRESULT hr;
1366     DWORD count;
1367 
1368     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1369     if (hr != S_OK)
1370     {
1371         win_skip( "Win32_ComputerSystemProduct not available\n" );
1372         return;
1373     }
1374 
1375     hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1376     ok( hr == S_OK, "got %08x\n", hr );
1377 
1378     type = 0xdeadbeef;
1379     VariantInit( &value );
1380     hr = IWbemClassObject_Get( obj, identifyingnumberW, 0, &value, &type, NULL );
1381     ok( hr == S_OK, "got %08x\n", hr );
1382     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
1383     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1384     trace( "identifyingnumber %s\n", wine_dbgstr_w(V_BSTR(&value)) );
1385     VariantClear( &value );
1386 
1387     type = 0xdeadbeef;
1388     VariantInit( &value );
1389     hr = IWbemClassObject_Get( obj, nameW, 0, &value, &type, NULL );
1390     ok( hr == S_OK, "got %08x\n", hr );
1391     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
1392     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1393     trace( "name %s\n", wine_dbgstr_w(V_BSTR(&value)) );
1394     VariantClear( &value );
1395 
1396     type = 0xdeadbeef;
1397     VariantInit( &value );
1398     hr = IWbemClassObject_Get( obj, skunumberW, 0, &value, &type, NULL );
1399     ok( hr == S_OK, "got %08x\n", hr );
1400     ok( V_VT( &value ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &value ) );
1401     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1402     VariantClear( &value );
1403 
1404     type = 0xdeadbeef;
1405     VariantInit( &value );
1406     hr = IWbemClassObject_Get( obj, uuidW, 0, &value, &type, NULL );
1407     ok( hr == S_OK, "got %08x\n", hr );
1408     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
1409     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1410     trace( "uuid %s\n", wine_dbgstr_w(V_BSTR(&value)) );
1411     VariantClear( &value );
1412 
1413     type = 0xdeadbeef;
1414     VariantInit( &value );
1415     hr = IWbemClassObject_Get( obj, vendorW, 0, &value, &type, NULL );
1416     ok( hr == S_OK, "got %08x\n", hr );
1417     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
1418     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1419     trace( "vendor %s\n", wine_dbgstr_w(V_BSTR(&value)) );
1420     VariantClear( &value );
1421 
1422     type = 0xdeadbeef;
1423     VariantInit( &value );
1424     hr = IWbemClassObject_Get( obj, versionW, 0, &value, &type, NULL );
1425     ok( hr == S_OK, "got %08x\n", hr );
1426     ok( V_VT( &value ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &value ) );
1427     ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1428     trace( "version %s\n", wine_dbgstr_w(V_BSTR(&value)) );
1429     VariantClear( &value );
1430 
1431     IWbemClassObject_Release( obj );
1432     IEnumWbemClassObject_Release( result );
1433     SysFreeString( query );
1434     SysFreeString( wql );
1435 }
1436 
1437 static void test_Win32_PhysicalMemory( IWbemServices *services )
1438 {
1439     static const WCHAR capacityW[] = {'C','a','p','a','c','i','t','y',0};
1440     static const WCHAR memorytypeW[] = {'M','e','m','o','r','y','T','y','p','e',0};
1441     static const WCHAR queryW[] =
1442         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1443          'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
1444     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1445     IEnumWbemClassObject *result;
1446     IWbemClassObject *obj;
1447     VARIANT val;
1448     CIMTYPE type;
1449     HRESULT hr;
1450     DWORD count;
1451 
1452     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1453     if (hr != S_OK)
1454     {
1455         win_skip( "Win32_PhysicalMemory not available\n" );
1456         return;
1457     }
1458 
1459     hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1460     ok( hr == S_OK, "got %08x\n", hr );
1461 
1462     if (count > 0)
1463     {
1464         type = 0xdeadbeef;
1465         VariantInit( &val );
1466         hr = IWbemClassObject_Get( obj, capacityW, 0, &val, &type, NULL );
1467         ok( hr == S_OK, "failed to get capacity %08x\n", hr );
1468         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1469         ok( type == CIM_UINT64, "unexpected type 0x%x\n", type );
1470         trace( "capacity %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1471         VariantClear( &val );
1472 
1473         type = 0xdeadbeef;
1474         VariantInit( &val );
1475         hr = IWbemClassObject_Get( obj, memorytypeW, 0, &val, &type, NULL );
1476         ok( hr == S_OK, "failed to get memory type %08x\n", hr );
1477         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1478         ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1479         trace( "memorytype %u\n", V_I4( &val ) );
1480         VariantClear( &val );
1481 
1482         IWbemClassObject_Release( obj );
1483     }
1484     IEnumWbemClassObject_Release( result );
1485     SysFreeString( query );
1486     SysFreeString( wql );
1487 }
1488 
1489 static void test_Win32_IP4RouteTable( IWbemServices *services )
1490 {
1491     static const WCHAR destinationW[] = {'D','e','s','t','i','n','a','t','i','o','n',0};
1492     static const WCHAR interfaceindexW[] = {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
1493     static const WCHAR nexthopW[] = {'N','e','x','t','H','o','p',0};
1494     static const WCHAR queryW[] =
1495         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1496          'I','P','4','R','o','u','t','e','T','a','b','l','e',0};
1497     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1498     IEnumWbemClassObject *result;
1499     IWbemClassObject *obj;
1500     VARIANT val;
1501     CIMTYPE type;
1502     HRESULT hr;
1503     DWORD count;
1504 
1505     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1506     if (hr != S_OK)
1507     {
1508         win_skip( "Win32_IP4RouteTable not available\n" );
1509         return;
1510     }
1511 
1512     for (;;)
1513     {
1514         hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1515         if (hr != S_OK) break;
1516 
1517         type = 0xdeadbeef;
1518         VariantInit( &val );
1519         hr = IWbemClassObject_Get( obj, destinationW, 0, &val, &type, NULL );
1520         ok( hr == S_OK, "failed to get destination %08x\n", hr );
1521         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1522         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1523         trace( "destination %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1524         VariantClear( &val );
1525 
1526         type = 0xdeadbeef;
1527         VariantInit( &val );
1528         hr = IWbemClassObject_Get( obj, interfaceindexW, 0, &val, &type, NULL );
1529         ok( hr == S_OK, "failed to get interface index %08x\n", hr );
1530         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1531         ok( type == CIM_SINT32, "unexpected type 0x%x\n", type );
1532         trace( "interfaceindex %d\n", V_I4( &val ) );
1533         VariantClear( &val );
1534 
1535         type = 0xdeadbeef;
1536         VariantInit( &val );
1537         hr = IWbemClassObject_Get( obj, nexthopW, 0, &val, &type, NULL );
1538         ok( hr == S_OK, "failed to get nexthop %08x\n", hr );
1539         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1540         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1541         trace( "nexthop %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1542         VariantClear( &val );
1543 
1544         IWbemClassObject_Release( obj );
1545     }
1546 
1547     IEnumWbemClassObject_Release( result );
1548     SysFreeString( query );
1549     SysFreeString( wql );
1550 }
1551 
1552 static void test_Win32_Processor( IWbemServices *services )
1553 {
1554     static const WCHAR architectureW[] =
1555         {'A','r','c','h','i','t','e','c','t','u','r','e',0};
1556     static const WCHAR familyW[] =
1557         {'F','a','m','i','l','y',0};
1558     static const WCHAR levelW[] =
1559         {'L','e','v','e','l',0};
1560     static const WCHAR manufacturerW[] =
1561         {'M','a','n','u','f','a','c','t','u','r','e','r',0};
1562     static const WCHAR nameW[] =
1563         {'N','a','m','e',0};
1564     static const WCHAR processoridW[] =
1565         {'P','r','o','c','e','s','s','o','r','I','d',0};
1566     static const WCHAR revisionW[] =
1567         {'R','e','v','i','s','i','o','n',0};
1568     static const WCHAR versionW[] =
1569         {'V','e','r','s','i','o','n',0};
1570     static const WCHAR queryW[] =
1571         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1572          'P','r','o','c','e','s','s','o','r',0};
1573     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1574     IEnumWbemClassObject *result;
1575     IWbemClassObject *obj;
1576     VARIANT val;
1577     CIMTYPE type;
1578     HRESULT hr;
1579     DWORD count;
1580 
1581     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1582     ok( hr == S_OK, "got %08x\n", hr );
1583 
1584     for (;;)
1585     {
1586         hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1587         if (hr != S_OK) break;
1588 
1589         type = 0xdeadbeef;
1590         VariantInit( &val );
1591         hr = IWbemClassObject_Get( obj, architectureW, 0, &val, &type, NULL );
1592         ok( hr == S_OK, "got %08x\n", hr );
1593         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1594         ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1595         trace( "architecture %u\n", V_I4( &val ) );
1596 
1597         type = 0xdeadbeef;
1598         VariantInit( &val );
1599         hr = IWbemClassObject_Get( obj, familyW, 0, &val, &type, NULL );
1600         ok( hr == S_OK, "got %08x\n", hr );
1601         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1602         ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1603         trace( "family %u\n", V_I4( &val ) );
1604 
1605         type = 0xdeadbeef;
1606         VariantInit( &val );
1607         hr = IWbemClassObject_Get( obj, levelW, 0, &val, &type, NULL );
1608         ok( hr == S_OK, "got %08x\n", hr );
1609         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1610         ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1611         trace( "level %u\n", V_I4( &val ) );
1612 
1613         type = 0xdeadbeef;
1614         VariantInit( &val );
1615         hr = IWbemClassObject_Get( obj, manufacturerW, 0, &val, &type, NULL );
1616         ok( hr == S_OK, "got %08x\n", hr );
1617         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1618         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1619         trace( "manufacturer %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1620         VariantClear( &val );
1621 
1622         type = 0xdeadbeef;
1623         VariantInit( &val );
1624         hr = IWbemClassObject_Get( obj, nameW, 0, &val, &type, NULL );
1625         ok( hr == S_OK, "got %08x\n", hr );
1626         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1627         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1628         trace( "name %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1629         VariantClear( &val );
1630 
1631         type = 0xdeadbeef;
1632         VariantInit( &val );
1633         hr = IWbemClassObject_Get( obj, processoridW, 0, &val, &type, NULL );
1634         ok( hr == S_OK, "got %08x\n", hr );
1635         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1636         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1637         trace( "processorid %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1638         VariantClear( &val );
1639 
1640         type = 0xdeadbeef;
1641         VariantInit( &val );
1642         hr = IWbemClassObject_Get( obj, revisionW, 0, &val, &type, NULL );
1643         ok( hr == S_OK, "got %08x\n", hr );
1644         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1645         ok( type == CIM_UINT16, "unexpected type 0x%x\n", type );
1646         trace( "revision %u\n", V_I4( &val ) );
1647 
1648         type = 0xdeadbeef;
1649         VariantInit( &val );
1650         hr = IWbemClassObject_Get( obj, versionW, 0, &val, &type, NULL );
1651         ok( hr == S_OK, "got %08x\n", hr );
1652         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1653         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1654         trace( "version %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1655         VariantClear( &val );
1656 
1657         IWbemClassObject_Release( obj );
1658     }
1659 
1660     IEnumWbemClassObject_Release( result );
1661     SysFreeString( query );
1662     SysFreeString( wql );
1663 }
1664 
1665 static void test_Win32_VideoController( IWbemServices *services )
1666 {
1667     static const WCHAR configmanagererrorcodeW[] =
1668         {'C','o','n','f','i','g','M','a','n','a','g','e','r','E','r','r','o','r','C','o','d','e',0};
1669     static const WCHAR driverdateW[] =
1670         {'D','r','i','v','e','r','D','a','t','e',0};
1671     static const WCHAR installeddisplaydriversW[]=
1672         {'I','n','s','t','a','l','l','e','d','D','i','s','p','l','a','y','D','r','i','v','e','r','s',0};
1673     static const WCHAR statusW[] =
1674         {'S','t','a','t','u','s',0};
1675     static const WCHAR queryW[] =
1676         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1677          'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
1678     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1679     IEnumWbemClassObject *result;
1680     IWbemClassObject *obj;
1681     VARIANT val;
1682     CIMTYPE type;
1683     HRESULT hr;
1684     DWORD count;
1685 
1686     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1687     if (hr != S_OK)
1688     {
1689         win_skip( "Win32_VideoController not available\n" );
1690         return;
1691     }
1692 
1693     for (;;)
1694     {
1695         hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1696         if (hr != S_OK) break;
1697 
1698         type = 0xdeadbeef;
1699         VariantInit( &val );
1700         hr = IWbemClassObject_Get( obj, configmanagererrorcodeW, 0, &val, &type, NULL );
1701         ok( hr == S_OK, "got %08x\n", hr );
1702         ok( V_VT( &val ) == VT_I4, "unexpected variant type 0x%x\n", V_VT( &val ) );
1703         ok( type == CIM_UINT32, "unexpected type 0x%x\n", type );
1704         trace( "configmanagererrorcode %d\n", V_I4( &val ) );
1705 
1706         type = 0xdeadbeef;
1707         VariantInit( &val );
1708         hr = IWbemClassObject_Get( obj, driverdateW, 0, &val, &type, NULL );
1709         ok( hr == S_OK, "got %08x\n", hr );
1710         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1711         ok( type == CIM_DATETIME, "unexpected type 0x%x\n", type );
1712         trace( "driverdate %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1713         VariantClear( &val );
1714 
1715         type = 0xdeadbeef;
1716         VariantInit( &val );
1717         hr = IWbemClassObject_Get( obj, installeddisplaydriversW, 0, &val, &type, NULL );
1718         ok( hr == S_OK, "got %08x\n", hr );
1719         ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1720         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1721         trace( "installeddisplaydrivers %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1722         VariantClear( &val );
1723 
1724         type = 0xdeadbeef;
1725         VariantInit( &val );
1726         hr = IWbemClassObject_Get( obj, statusW, 0, &val, &type, NULL );
1727         ok( hr == S_OK, "got %08x\n", hr );
1728         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1729         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1730         trace( "status %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1731         VariantClear( &val );
1732 
1733         IWbemClassObject_Release( obj );
1734     }
1735 
1736     IEnumWbemClassObject_Release( result );
1737     SysFreeString( query );
1738     SysFreeString( wql );
1739 }
1740 
1741 static void test_Win32_Printer( IWbemServices *services )
1742 {
1743     static const WCHAR deviceidW[] =
1744         {'D','e','v','i','c','e','I','d',0};
1745     static const WCHAR locationW[] =
1746         {'L','o','c','a','t','i','o','n',0};
1747     static const WCHAR portnameW[] =
1748         {'P','o','r','t','N','a','m','e',0};
1749     static const WCHAR queryW[] =
1750         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
1751          'P','r','i','n','t','e','r',0};
1752     BSTR wql = SysAllocString( wqlW ), query = SysAllocString( queryW );
1753     IEnumWbemClassObject *result;
1754     IWbemClassObject *obj;
1755     VARIANT val;
1756     CIMTYPE type;
1757     HRESULT hr;
1758     DWORD count;
1759 
1760     hr = IWbemServices_ExecQuery( services, wql, query, 0, NULL, &result );
1761     if (hr != S_OK)
1762     {
1763         win_skip( "Win32_Printer not available\n" );
1764         return;
1765     }
1766 
1767     for (;;)
1768     {
1769         hr = IEnumWbemClassObject_Next( result, 10000, 1, &obj, &count );
1770         if (hr != S_OK) break;
1771 
1772         type = 0xdeadbeef;
1773         memset( &val, 0, sizeof(val) );
1774         hr = IWbemClassObject_Get( obj, deviceidW, 0, &val, &type, NULL );
1775         ok( hr == S_OK, "got %08x\n", hr );
1776         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1777         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1778         trace( "deviceid %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1779         VariantClear( &val );
1780 
1781         type = 0xdeadbeef;
1782         memset( &val, 0, sizeof(val) );
1783         hr = IWbemClassObject_Get( obj, locationW, 0, &val, &type, NULL );
1784         ok( hr == S_OK, "got %08x\n", hr );
1785         ok( V_VT( &val ) == VT_BSTR || V_VT( &val ) == VT_NULL, "unexpected variant type 0x%x\n", V_VT( &val ) );
1786         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1787         trace( "location %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1788         VariantClear( &val );
1789 
1790         type = 0xdeadbeef;
1791         memset( &val, 0, sizeof(val) );
1792         hr = IWbemClassObject_Get( obj, portnameW, 0, &val, &type, NULL );
1793         ok( hr == S_OK, "got %08x\n", hr );
1794         ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1795         ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1796         trace( "portname %s\n", wine_dbgstr_w(V_BSTR( &val )) );
1797         VariantClear( &val );
1798 
1799         IWbemClassObject_Release( obj );
1800     }
1801 
1802     IEnumWbemClassObject_Release( result );
1803     SysFreeString( query );
1804     SysFreeString( wql );
1805 }
1806 
1807 static void test_Win32_PnPEntity( IWbemServices *services )
1808 {
1809     HRESULT hr;
1810     IEnumWbemClassObject *enm;
1811     IWbemClassObject *obj;
1812     VARIANT val;
1813     CIMTYPE type;
1814     ULONG count, i;
1815     BSTR bstr;
1816 
1817     static WCHAR win32_pnpentityW[] = {'W','i','n','3','2','_','P','n','P','E','n','t','i','t','y',0};
1818     static const WCHAR deviceidW[] = {'D','e','v','i','c','e','I','d',0};
1819 
1820     bstr = SysAllocString( win32_pnpentityW );
1821 
1822     hr = IWbemServices_CreateInstanceEnum( services, bstr, 0, NULL, &enm );
1823     ok( hr == S_OK, "got %08x\n", hr );
1824 
1825     SysFreeString( bstr );
1826     bstr = SysAllocString( deviceidW );
1827 
1828     while (1)
1829     {
1830         hr = IEnumWbemClassObject_Next( enm, 1000, 1, &obj, &count );
1831         ok( (count == 1 && (hr == WBEM_S_FALSE || hr == WBEM_S_NO_ERROR)) ||
1832                 (count == 0 && (hr == WBEM_S_FALSE || hr == WBEM_S_TIMEDOUT)),
1833                 "got %08x with %u objects returned\n", hr, count );
1834 
1835         if (count == 0)
1836             break;
1837 
1838         for (i = 0; i < count; ++i)
1839         {
1840             hr = IWbemClassObject_Get( obj, bstr, 0, &val, &type, NULL );
1841             ok( hr == S_OK, "got %08x\n", hr );
1842 
1843             if (SUCCEEDED( hr ))
1844             {
1845                 ok( V_VT( &val ) == VT_BSTR, "unexpected variant type 0x%x\n", V_VT( &val ) );
1846                 ok( type == CIM_STRING, "unexpected type 0x%x\n", type );
1847                 VariantClear( &val );
1848             }
1849         }
1850     }
1851 
1852     SysFreeString( bstr );
1853 
1854     IEnumWbemClassObject_Release( enm );
1855 }
1856 
1857 START_TEST(query)
1858 {
1859     static const WCHAR cimv2W[] = {'R','O','O','T','\\','C','I','M','V','2',0};
1860     BSTR path = SysAllocString( cimv2W );
1861     IWbemLocator *locator;
1862     IWbemServices *services;
1863     HRESULT hr;
1864 
1865     CoInitialize( NULL );
1866     CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
1867                           RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL );
1868     hr = CoCreateInstance( &CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemLocator,
1869                            (void **)&locator );
1870     if (hr != S_OK)
1871     {
1872         win_skip("can't create instance of WbemLocator\n");
1873         return;
1874     }
1875     hr = IWbemLocator_ConnectServer( locator, path, NULL, NULL, NULL, 0, NULL, NULL, &services );
1876     ok( hr == S_OK, "failed to get IWbemServices interface %08x\n", hr );
1877 
1878     hr = CoSetProxyBlanket( (IUnknown *)services, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
1879                             RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
1880     ok( hr == S_OK, "failed to set proxy blanket %08x\n", hr );
1881 
1882     test_select( services );
1883     test_associators( services );
1884     test_Win32_Bios( services );
1885     test_Win32_Process( services, FALSE );
1886     test_Win32_Process( services, TRUE );
1887     test_Win32_Service( services );
1888     test_Win32_ComputerSystem( services );
1889     test_Win32_SystemEnclosure( services );
1890     test_StdRegProv( services );
1891     test_notification_query_async( services );
1892     test_query_async( services );
1893     test_GetNames( services );
1894     test_SystemSecurity( services );
1895     test_Win32_OperatingSystem( services );
1896     test_Win32_ComputerSystemProduct( services );
1897     test_Win32_PhysicalMemory( services );
1898     test_Win32_IP4RouteTable( services );
1899     test_Win32_Processor( services );
1900     test_Win32_VideoController( services );
1901     test_Win32_Printer( services );
1902     test_Win32_PnPEntity( services );
1903 
1904     SysFreeString( path );
1905     IWbemServices_Release( services );
1906     IWbemLocator_Release( locator );
1907     CoUninitialize();
1908 }
1909