2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
28 #include "wine/test.h"
30 static const WCHAR wqlW
[] = {'w','q','l',0};
32 static HRESULT
exec_query( IWbemServices
*services
, const WCHAR
*str
, IEnumWbemClassObject
**result
)
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};
37 IWbemClassObject
*obj
;
38 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( str
);
39 LONG flags
= WBEM_FLAG_RETURN_IMMEDIATELY
| WBEM_FLAG_FORWARD_ONLY
;
42 hr
= IWbemServices_ExecQuery( services
, wql
, query
, flags
, NULL
, result
);
45 trace("%s\n", wine_dbgstr_w(str
));
50 IEnumWbemClassObject_Next( *result
, 10000, 1, &obj
, &count
);
53 if (IWbemClassObject_Get( obj
, captionW
, 0, &var
, NULL
, NULL
) == WBEM_S_NO_ERROR
)
55 trace("caption: %s\n", wine_dbgstr_w(V_BSTR(&var
)));
58 if (IWbemClassObject_Get( obj
, descriptionW
, 0, &var
, NULL
, NULL
) == WBEM_S_NO_ERROR
)
60 trace("description: %s\n", wine_dbgstr_w(V_BSTR(&var
)));
63 IWbemClassObject_Release( obj
);
67 SysFreeString( query
);
71 static void test_select( IWbemServices
*services
)
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
*test
[] = { query1
, query2
, query3
, query4
, query5
, query6
, query7
, query8
, query9
, query10
,
112 IEnumWbemClassObject
*result
;
113 BSTR wql
= SysAllocString( wqlW
);
114 BSTR sql
= SysAllocString( sqlW
);
115 BSTR query
= SysAllocString( query1
);
118 hr
= IWbemServices_ExecQuery( services
, NULL
, NULL
, 0, NULL
, &result
);
119 ok( hr
== WBEM_E_INVALID_PARAMETER
, "query failed %08x\n", hr
);
121 hr
= IWbemServices_ExecQuery( services
, NULL
, query
, 0, NULL
, &result
);
122 ok( hr
== WBEM_E_INVALID_PARAMETER
, "query failed %08x\n", hr
);
124 hr
= IWbemServices_ExecQuery( services
, wql
, NULL
, 0, NULL
, &result
);
125 ok( hr
== WBEM_E_INVALID_PARAMETER
, "query failed %08x\n", hr
);
127 hr
= IWbemServices_ExecQuery( services
, sql
, query
, 0, NULL
, &result
);
128 ok( hr
== WBEM_E_INVALID_QUERY_TYPE
, "query failed %08x\n", hr
);
130 hr
= IWbemServices_ExecQuery( services
, sql
, NULL
, 0, NULL
, &result
);
131 ok( hr
== WBEM_E_INVALID_PARAMETER
, "query failed %08x\n", hr
);
133 SysFreeString( query
);
134 query
= SysAllocString( emptyW
);
135 hr
= IWbemServices_ExecQuery( services
, wql
, query
, 0, NULL
, &result
);
136 ok( hr
== WBEM_E_INVALID_PARAMETER
, "query failed %08x\n", hr
);
138 for (i
= 0; i
< sizeof(test
)/sizeof(test
[0]); i
++)
140 hr
= exec_query( services
, test
[i
], &result
);
141 ok( hr
== S_OK
, "query %u failed: %08x\n", i
, hr
);
142 if (result
) IEnumWbemClassObject_Release( result
);
145 SysFreeString( wql
);
146 SysFreeString( sql
);
147 SysFreeString( query
);
150 static void test_associators( IWbemServices
*services
)
152 static const WCHAR query1
[] =
153 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
154 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',0};
155 static const WCHAR query2
[] =
156 {'A','S','S','O','C','I','A','T','O','R','S',' ','O','F',' ','{','W','i','n','3','2','_',
157 'L','o','g','i','c','a','l','D','i','s','k','.','D','e','v','i','c','e','I','D','=','"','C',':','"','}',' ',
158 'W','H','E','R','E',' ','A','s','s','o','c','C','l','a','s','s',' ','=',' ','W','i','n','3','2','_',
159 'L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
160 static const WCHAR
*test
[] = { query1
, query2
};
162 IEnumWbemClassObject
*result
;
165 for (i
= 0; i
< sizeof(test
)/sizeof(test
[0]); i
++)
167 hr
= exec_query( services
, test
[i
], &result
);
168 todo_wine
ok( hr
== S_OK
, "query %u failed: %08x\n", i
, hr
);
169 if (result
) IEnumWbemClassObject_Release( result
);
173 static void test_Win32_Service( IWbemServices
*services
)
175 static const WCHAR returnvalueW
[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
176 static const WCHAR pauseserviceW
[] = {'P','a','u','s','e','S','e','r','v','i','c','e',0};
177 static const WCHAR resumeserviceW
[] = {'R','e','s','u','m','e','S','e','r','v','i','c','e',0};
178 static const WCHAR startserviceW
[] = {'S','t','a','r','t','S','e','r','v','i','c','e',0};
179 static const WCHAR stopserviceW
[] = {'S','t','o','p','S','e','r','v','i','c','e',0};
180 static const WCHAR stateW
[] = {'S','t','a','t','e',0};
181 static const WCHAR stoppedW
[] = {'S','t','o','p','p','e','d',0};
182 static const WCHAR serviceW
[] = {'W','i','n','3','2','_','S','e','r','v','i','c','e','.',
183 'N','a','m','e','=','"','S','p','o','o','l','e','r','"',0};
184 static const WCHAR emptyW
[] = {0};
185 BSTR
class = SysAllocString( serviceW
), empty
= SysAllocString( emptyW
), method
;
186 IWbemClassObject
*service
, *out
;
187 VARIANT state
, retval
;
191 hr
= IWbemServices_GetObject( services
, class, 0, NULL
, &service
, NULL
);
194 win_skip( "Win32_Service not available\n" );
198 VariantInit( &state
);
199 hr
= IWbemClassObject_Get( service
, stateW
, 0, &state
, &type
, NULL
);
200 ok( hr
== S_OK
, "failed to get service state %08x\n", hr
);
201 ok( V_VT( &state
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &state
) );
202 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
204 if (!lstrcmpW( V_BSTR( &state
), stoppedW
))
207 method
= SysAllocString( startserviceW
);
208 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, NULL
, &out
, NULL
);
209 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
210 SysFreeString( method
);
212 VariantInit( &retval
);
213 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, NULL
, NULL
);
214 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
215 ok( !V_I4( &retval
), "unexpected error %u\n", V_UI4( &retval
) );
216 IWbemClassObject_Release( out
);
219 method
= SysAllocString( pauseserviceW
);
220 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, NULL
, &out
, NULL
);
221 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
222 SysFreeString( method
);
224 VariantInit( &retval
);
225 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, NULL
, NULL
);
226 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
227 ok( V_I4( &retval
), "unexpected success\n" );
228 IWbemClassObject_Release( out
);
231 method
= SysAllocString( resumeserviceW
);
232 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, NULL
, &out
, NULL
);
233 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
234 SysFreeString( method
);
236 VariantInit( &retval
);
237 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, NULL
, NULL
);
238 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
239 ok( V_I4( &retval
), "unexpected success\n" );
240 IWbemClassObject_Release( out
);
242 if (!lstrcmpW( V_BSTR( &state
), stoppedW
))
245 method
= SysAllocString( stopserviceW
);
246 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, NULL
, &out
, NULL
);
247 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
248 SysFreeString( method
);
250 VariantInit( &retval
);
251 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, NULL
, NULL
);
252 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
253 ok( !V_I4( &retval
), "unexpected error %u\n", V_UI4( &retval
) );
254 IWbemClassObject_Release( out
);
256 VariantClear( &state
);
257 IWbemClassObject_Release( service
);
260 hr
= IWbemServices_GetObject( services
, NULL
, 0, NULL
, &service
, NULL
);
261 ok( hr
== S_OK
, "got %08x\n", hr
);
262 if (service
) IWbemClassObject_Release( service
);
265 hr
= IWbemServices_GetObject( services
, empty
, 0, NULL
, &service
, NULL
);
266 ok( hr
== S_OK
, "got %08x\n", hr
);
267 if (service
) IWbemClassObject_Release( service
);
270 SysFreeString( empty
);
271 SysFreeString( class );
274 static void test_Win32_Bios( IWbemServices
*services
)
276 static const WCHAR queryW
[] =
277 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_', 'B','i','o','s',0};
278 static const WCHAR descriptionW
[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
279 static const WCHAR identificationcodeW
[] = {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
280 static const WCHAR manufacturerW
[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
281 static const WCHAR nameW
[] = {'N','a','m','e',0};
282 static const WCHAR releasedateW
[] = {'R','e','l','e','a','s','e','D','a','t','e',0};
283 static const WCHAR serialnumberW
[] = {'S','e','r','i','a','l','N','u','m','b','e','r',0};
284 static const WCHAR smbiosbiosversionW
[] = {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
285 static const WCHAR versionW
[] = {'V','e','r','s','i','o','n',0};
286 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( queryW
);
287 IEnumWbemClassObject
*result
;
288 IWbemClassObject
*obj
;
294 hr
= IWbemServices_ExecQuery( services
, wql
, query
, 0, NULL
, &result
);
295 ok( hr
== S_OK
, "IWbemServices_ExecQuery failed %08x\n", hr
);
297 hr
= IEnumWbemClassObject_Next( result
, 10000, 1, &obj
, &count
);
298 ok( hr
== S_OK
, "IEnumWbemClassObject_Next failed %08x\n", hr
);
302 hr
= IWbemClassObject_Get( obj
, descriptionW
, 0, &val
, &type
, NULL
);
303 ok( hr
== S_OK
, "failed to get description %08x\n", hr
);
304 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
305 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
306 trace( "description: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
307 VariantClear( &val
);
311 hr
= IWbemClassObject_Get( obj
, identificationcodeW
, 0, &val
, &type
, NULL
);
312 ok( hr
== S_OK
, "failed to get identication code %08x\n", hr
);
314 ok( V_VT( &val
) == VT_NULL
, "unexpected variant type 0x%x\n", V_VT( &val
) );
315 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
316 VariantClear( &val
);
320 hr
= IWbemClassObject_Get( obj
, manufacturerW
, 0, &val
, &type
, NULL
);
321 ok( hr
== S_OK
, "failed to get manufacturer %08x\n", hr
);
322 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
323 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
324 trace( "manufacturer: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
325 VariantClear( &val
);
329 hr
= IWbemClassObject_Get( obj
, nameW
, 0, &val
, &type
, NULL
);
330 ok( hr
== S_OK
, "failed to get name %08x\n", hr
);
331 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
332 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
333 trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
334 VariantClear( &val
);
338 hr
= IWbemClassObject_Get( obj
, releasedateW
, 0, &val
, &type
, NULL
);
339 ok( hr
== S_OK
, "failed to get release date %08x\n", hr
);
340 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
341 ok( type
== CIM_DATETIME
, "unexpected type 0x%x\n", type
);
342 trace( "release date: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
343 VariantClear( &val
);
347 hr
= IWbemClassObject_Get( obj
, serialnumberW
, 0, &val
, &type
, NULL
);
348 ok( hr
== S_OK
, "failed to get serial number %08x\n", hr
);
349 ok( V_VT( &val
) == VT_BSTR
|| V_VT( &val
) == VT_NULL
/* Testbot VMs */,
350 "unexpected variant type 0x%x\n", V_VT( &val
) );
351 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
352 VariantClear( &val
);
356 hr
= IWbemClassObject_Get( obj
, smbiosbiosversionW
, 0, &val
, &type
, NULL
);
357 ok( hr
== S_OK
, "failed to get bios version %08x\n", hr
);
358 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
359 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
360 trace( "bios version: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
361 VariantClear( &val
);
365 hr
= IWbemClassObject_Get( obj
, versionW
, 0, &val
, &type
, NULL
);
366 ok( hr
== S_OK
, "failed to get version %08x\n", hr
);
367 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
368 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
369 trace( "version: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
370 VariantClear( &val
);
372 IWbemClassObject_Release( obj
);
373 IEnumWbemClassObject_Release( result
);
374 SysFreeString( query
);
375 SysFreeString( wql
);
378 static void test_Win32_Process( IWbemServices
*services
)
380 static const WCHAR returnvalueW
[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
381 static const WCHAR getownerW
[] = {'G','e','t','O','w','n','e','r',0};
382 static const WCHAR userW
[] = {'U','s','e','r',0};
383 static const WCHAR domainW
[] = {'D','o','m','a','i','n',0};
384 static const WCHAR processW
[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
385 static const WCHAR idW
[] = {'I','D',0};
386 static const WCHAR fmtW
[] = {'W','i','n','3','2','_','P','r','o','c','e','s','s','.',
387 'H','a','n','d','l','e','=','"','%','u','"',0};
388 static const LONG expected_flavor
= WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE
|
389 WBEM_FLAVOR_NOT_OVERRIDABLE
|
390 WBEM_FLAVOR_ORIGIN_PROPAGATED
;
392 IWbemClassObject
*process
, *out
;
393 IWbemQualifierSet
*qualifiers
;
394 VARIANT user
, domain
, retval
, val
;
399 class = SysAllocString( processW
);
400 hr
= IWbemServices_GetObject( services
, class, 0, NULL
, &process
, NULL
);
401 SysFreeString( class );
404 win_skip( "Win32_Process not available\n" );
407 hr
= IWbemClassObject_GetMethod( process
, getownerW
, 0, NULL
, NULL
);
408 ok( hr
== S_OK
, "failed to get GetOwner method %08x\n", hr
);
409 IWbemClassObject_Release( process
);
412 method
= SysAllocString( getownerW
);
413 class = SysAllocStringLen( NULL
, sizeof(fmtW
)/sizeof(fmtW
[0]) + 10 );
414 wsprintfW( class, fmtW
, GetCurrentProcessId() );
415 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, NULL
, &out
, NULL
);
416 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
417 SysFreeString( method
);
418 SysFreeString( class );
421 VariantInit( &retval
);
422 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, &type
, NULL
);
423 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
424 ok( V_VT( &retval
) == VT_I4
, "unexpected variant type 0x%x\n", V_VT( &retval
) );
425 ok( !V_I4( &retval
), "unexpected error %u\n", V_I4( &retval
) );
426 ok( type
== CIM_UINT32
, "unexpected type 0x%x\n", type
);
429 VariantInit( &user
);
430 hr
= IWbemClassObject_Get( out
, userW
, 0, &user
, &type
, NULL
);
431 ok( hr
== S_OK
, "failed to get user %08x\n", hr
);
432 ok( V_VT( &user
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &user
) );
433 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
434 trace("%s\n", wine_dbgstr_w(V_BSTR(&user
)));
437 VariantInit( &domain
);
438 hr
= IWbemClassObject_Get( out
, domainW
, 0, &domain
, &type
, NULL
);
439 ok( hr
== S_OK
, "failed to get domain %08x\n", hr
);
440 ok( V_VT( &domain
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &domain
) );
441 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
442 trace("%s\n", wine_dbgstr_w(V_BSTR(&domain
)));
444 hr
= IWbemClassObject_GetPropertyQualifierSet( out
, userW
, &qualifiers
);
445 ok( hr
== S_OK
, "failed to get qualifier set %08x\n", hr
);
449 V_VT(&val
) = VT_ERROR
;
450 hr
= IWbemQualifierSet_Get( qualifiers
, idW
, 0, &val
, &flavor
);
451 ok( hr
== S_OK
, "got %08x\n", hr
);
452 ok( flavor
== expected_flavor
, "got %d\n", flavor
);
453 ok( V_VT(&val
) == VT_I4
, "got %u\n", V_VT(&val
) );
454 ok( V_I4(&val
) == 0, "got %u\n", V_I4(&val
) );
455 VariantClear( &val
);
457 IWbemQualifierSet_Release( qualifiers
);
458 hr
= IWbemClassObject_GetPropertyQualifierSet( out
, domainW
, &qualifiers
);
459 ok( hr
== S_OK
, "failed to get qualifier set %08x\n", hr
);
463 V_VT(&val
) = VT_ERROR
;
464 hr
= IWbemQualifierSet_Get( qualifiers
, idW
, 0, &val
, &flavor
);
465 ok( hr
== S_OK
, "got %08x\n", hr
);
466 ok( flavor
== expected_flavor
, "got %d\n", flavor
);
467 ok( V_VT(&val
) == VT_I4
, "got %u\n", V_VT(&val
) );
468 ok( V_I4(&val
) == 1, "got %u\n", V_I4(&val
) );
469 VariantClear( &val
);
471 IWbemQualifierSet_Release( qualifiers
);
472 hr
= IWbemClassObject_GetPropertyQualifierSet( out
, returnvalueW
, &qualifiers
);
473 ok( hr
== S_OK
, "failed to get qualifier set %08x\n", hr
);
475 hr
= IWbemQualifierSet_Get( qualifiers
, idW
, 0, &val
, &flavor
);
476 ok( hr
== WBEM_E_NOT_FOUND
, "got %08x\n", hr
);
478 IWbemQualifierSet_Release( qualifiers
);
479 VariantClear( &user
);
480 VariantClear( &domain
);
481 IWbemClassObject_Release( out
);
484 static void test_Win32_ComputerSystem( IWbemServices
*services
)
486 static const WCHAR nameW
[] = {'N','a','m','e',0};
487 static const WCHAR usernameW
[] = {'U','s','e','r','N','a','m','e',0};
488 static const WCHAR backslashW
[] = {'\\',0};
489 static const WCHAR queryW
[] =
490 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
491 'C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
492 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( queryW
);
493 IEnumWbemClassObject
*result
;
494 IWbemClassObject
*service
;
498 WCHAR compname
[MAX_COMPUTERNAME_LENGTH
+ 1];
502 len
= sizeof(compname
) / sizeof(compname
[0]);
503 if (!GetComputerNameW( compname
, &len
))
506 lstrcpyW( username
, compname
);
507 lstrcatW( username
, backslashW
);
508 len
= sizeof(username
) / sizeof(username
[0]) - lstrlenW( username
);
509 if (!GetUserNameW( username
+ lstrlenW( username
), &len
))
512 if (!compname
[0] || !username
[0])
514 skip( "Failed to get user or computer name\n" );
518 hr
= IWbemServices_ExecQuery( services
, wql
, query
, 0, NULL
, &result
);
521 win_skip( "Win32_ComputerSystem not available\n" );
525 hr
= IEnumWbemClassObject_Next( result
, 10000, 1, &service
, &count
);
526 ok( hr
== S_OK
, "got %08x\n", hr
);
529 VariantInit( &value
);
530 hr
= IWbemClassObject_Get( service
, nameW
, 0, &value
, &type
, NULL
);
531 ok( hr
== S_OK
, "failed to get computer name %08x\n", hr
);
532 ok( V_VT( &value
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &value
) );
533 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
534 ok( !lstrcmpiW( V_BSTR( &value
), compname
), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value
)), wine_dbgstr_w(compname
) );
535 VariantClear( &value
);
538 VariantInit( &value
);
539 hr
= IWbemClassObject_Get( service
, usernameW
, 0, &value
, &type
, NULL
);
540 ok( hr
== S_OK
, "failed to get computer name %08x\n", hr
);
541 ok( V_VT( &value
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &value
) );
542 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
543 ok( !lstrcmpiW( V_BSTR( &value
), username
), "got %s, expected %s\n", wine_dbgstr_w(V_BSTR(&value
)), wine_dbgstr_w(username
) );
544 VariantClear( &value
);
546 IWbemClassObject_Release( service
);
547 IEnumWbemClassObject_Release( result
);
549 SysFreeString( query
);
550 SysFreeString( wql
);
553 static void test_Win32_SystemEnclosure( IWbemServices
*services
)
555 static const WCHAR queryW
[] =
556 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
557 'S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
558 static const WCHAR captionW
[] = {'C','a','p','t','i','o','n',0};
559 static const WCHAR chassistypesW
[] = {'C','h','a','s','s','i','s','T','y','p','e','s',0};
560 static const WCHAR descriptionW
[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
561 static const WCHAR lockpresentW
[] = {'L','o','c','k','P','r','e','s','e','n','t',0};
562 static const WCHAR manufacturerW
[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
563 static const WCHAR nameW
[] = {'N','a','m','e',0};
564 static const WCHAR tagW
[] = {'T','a','g',0};
565 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( queryW
);
566 IEnumWbemClassObject
*result
;
567 IWbemClassObject
*obj
;
574 hr
= IWbemServices_ExecQuery( services
, wql
, query
, 0, NULL
, &result
);
575 ok( hr
== S_OK
, "IWbemServices_ExecQuery failed %08x\n", hr
);
577 hr
= IEnumWbemClassObject_Next( result
, 10000, 1, &obj
, &count
);
578 ok( hr
== S_OK
, "IEnumWbemClassObject_Next failed %08x\n", hr
);
582 hr
= IWbemClassObject_Get( obj
, captionW
, 0, &val
, &type
, NULL
);
583 ok( hr
== S_OK
, "failed to get caption %08x\n", hr
);
584 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
585 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
586 trace( "caption: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
587 VariantClear( &val
);
591 hr
= IWbemClassObject_Get( obj
, chassistypesW
, 0, &val
, &type
, NULL
);
592 ok( hr
== S_OK
, "failed to get chassis types %08x\n", hr
);
594 ok( V_VT( &val
) == (VT_I4
|VT_ARRAY
), "unexpected variant type 0x%x\n", V_VT( &val
) );
595 ok( type
== (CIM_UINT16
|CIM_FLAG_ARRAY
), "unexpected type 0x%x\n", type
);
596 hr
= SafeArrayAccessData( V_ARRAY( &val
), (void **)&data
);
597 ok( hr
== S_OK
, "SafeArrayAccessData failed %x\n", hr
);
600 LONG i
, lower
, upper
;
602 hr
= SafeArrayGetLBound( V_ARRAY( &val
), 1, &lower
);
603 ok( hr
== S_OK
, "SafeArrayGetLBound failed %x\n", hr
);
604 hr
= SafeArrayGetUBound( V_ARRAY( &val
), 1, &upper
);
605 ok( hr
== S_OK
, "SafeArrayGetUBound failed %x\n", hr
);
606 if (V_VT( &val
) == (VT_I4
|VT_ARRAY
))
608 for (i
= 0; i
< upper
- lower
+ 1; i
++)
609 trace( "chassis type: %u\n", data
[i
] );
611 hr
= SafeArrayUnaccessData( V_ARRAY( &val
) );
612 ok( hr
== S_OK
, "SafeArrayUnaccessData failed %x\n", hr
);
614 VariantClear( &val
);
618 hr
= IWbemClassObject_Get( obj
, descriptionW
, 0, &val
, &type
, NULL
);
619 ok( hr
== S_OK
, "failed to get description %08x\n", hr
);
620 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
621 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
622 trace( "description: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
623 VariantClear( &val
);
627 hr
= IWbemClassObject_Get( obj
, lockpresentW
, 0, &val
, &type
, NULL
);
628 ok( hr
== S_OK
, "failed to get lockpresent %08x\n", hr
);
629 ok( V_VT( &val
) == VT_BOOL
, "unexpected variant type 0x%x\n", V_VT( &val
) );
630 ok( type
== CIM_BOOLEAN
, "unexpected type 0x%x\n", type
);
631 trace( "lockpresent: %u\n", V_BOOL( &val
) );
632 VariantClear( &val
);
636 hr
= IWbemClassObject_Get( obj
, manufacturerW
, 0, &val
, &type
, NULL
);
637 ok( hr
== S_OK
, "failed to get manufacturer %08x\n", hr
);
638 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
639 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
640 trace( "manufacturer: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
641 VariantClear( &val
);
645 hr
= IWbemClassObject_Get( obj
, nameW
, 0, &val
, &type
, NULL
);
646 ok( hr
== S_OK
, "failed to get name %08x\n", hr
);
647 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
648 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
649 trace( "name: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
650 VariantClear( &val
);
654 hr
= IWbemClassObject_Get( obj
, tagW
, 0, &val
, &type
, NULL
);
655 ok( hr
== S_OK
, "failed to get tag %08x\n", hr
);
656 ok( V_VT( &val
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &val
) );
657 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
658 trace( "tag: %s\n", wine_dbgstr_w(V_BSTR( &val
)) );
659 VariantClear( &val
);
661 IWbemClassObject_Release( obj
);
662 IEnumWbemClassObject_Release( result
);
663 SysFreeString( query
);
664 SysFreeString( wql
);
667 static void test_StdRegProv( IWbemServices
*services
)
669 static const WCHAR enumkeyW
[] = {'E','n','u','m','K','e','y',0};
670 static const WCHAR enumvaluesW
[] = {'E','n','u','m','V','a','l','u','e','s',0};
671 static const WCHAR getstringvalueW
[] = {'G','e','t','S','t','r','i','n','g','V','a','l','u','e',0};
672 static const WCHAR stdregprovW
[] = {'S','t','d','R','e','g','P','r','o','v',0};
673 static const WCHAR defkeyW
[] = {'h','D','e','f','K','e','y',0};
674 static const WCHAR subkeynameW
[] = {'s','S','u','b','K','e','y','N','a','m','e',0};
675 static const WCHAR returnvalueW
[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
676 static const WCHAR namesW
[] = {'s','N','a','m','e','s',0};
677 static const WCHAR typesW
[] = {'T','y','p','e','s',0};
678 static const WCHAR valueW
[] = {'s','V','a','l','u','e',0};
679 static const WCHAR valuenameW
[] = {'s','V','a','l','u','e','N','a','m','e',0};
680 static const WCHAR programfilesW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
681 static const WCHAR windowsW
[] =
682 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
683 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
684 BSTR
class = SysAllocString( stdregprovW
), method
;
685 IWbemClassObject
*reg
, *sig_in
, *in
, *out
;
686 VARIANT defkey
, subkey
, retval
, names
, types
, value
, valuename
;
690 hr
= IWbemServices_GetObject( services
, class, 0, NULL
, ®
, NULL
);
693 win_skip( "StdRegProv not available\n" );
696 hr
= IWbemClassObject_GetMethod( reg
, enumkeyW
, 0, &sig_in
, NULL
);
697 ok( hr
== S_OK
, "failed to get EnumKey method %08x\n", hr
);
699 hr
= IWbemClassObject_SpawnInstance( sig_in
, 0, &in
);
700 ok( hr
== S_OK
, "failed to spawn instance %08x\n", hr
);
702 V_VT( &defkey
) = VT_I4
;
703 V_I4( &defkey
) = 0x80000002;
704 hr
= IWbemClassObject_Put( in
, defkeyW
, 0, &defkey
, 0 );
705 ok( hr
== S_OK
, "failed to set root %08x\n", hr
);
707 V_VT( &subkey
) = VT_BSTR
;
708 V_BSTR( &subkey
) = SysAllocString( windowsW
);
709 hr
= IWbemClassObject_Put( in
, subkeynameW
, 0, &subkey
, 0 );
710 ok( hr
== S_OK
, "failed to set subkey %08x\n", hr
);
713 method
= SysAllocString( enumkeyW
);
714 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, in
, &out
, NULL
);
715 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
716 SysFreeString( method
);
719 VariantInit( &retval
);
720 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, &type
, NULL
);
721 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
722 ok( V_VT( &retval
) == VT_I4
, "unexpected variant type 0x%x\n", V_VT( &retval
) );
723 ok( !V_I4( &retval
), "unexpected error %u\n", V_UI4( &retval
) );
724 ok( type
== CIM_UINT32
, "unexpected type 0x%x\n", type
);
727 VariantInit( &names
);
728 hr
= IWbemClassObject_Get( out
, namesW
, 0, &names
, &type
, NULL
);
729 ok( hr
== S_OK
, "failed to get names %08x\n", hr
);
730 ok( V_VT( &names
) == (VT_BSTR
|VT_ARRAY
), "unexpected variant type 0x%x\n", V_VT( &names
) );
731 ok( type
== (CIM_STRING
|CIM_FLAG_ARRAY
), "unexpected type 0x%x\n", type
);
733 VariantClear( &names
);
734 VariantClear( &subkey
);
735 IWbemClassObject_Release( in
);
736 IWbemClassObject_Release( out
);
737 IWbemClassObject_Release( sig_in
);
739 hr
= IWbemClassObject_GetMethod( reg
, enumvaluesW
, 0, &sig_in
, NULL
);
740 ok( hr
== S_OK
, "failed to get EnumValues method %08x\n", hr
);
742 hr
= IWbemClassObject_SpawnInstance( sig_in
, 0, &in
);
743 ok( hr
== S_OK
, "failed to spawn instance %08x\n", hr
);
745 V_VT( &defkey
) = VT_I4
;
746 V_I4( &defkey
) = 0x80000002;
747 hr
= IWbemClassObject_Put( in
, defkeyW
, 0, &defkey
, 0 );
748 ok( hr
== S_OK
, "failed to set root %08x\n", hr
);
750 V_VT( &subkey
) = VT_BSTR
;
751 V_BSTR( &subkey
) = SysAllocString( windowsW
);
752 hr
= IWbemClassObject_Put( in
, subkeynameW
, 0, &subkey
, 0 );
753 ok( hr
== S_OK
, "failed to set subkey %08x\n", hr
);
756 method
= SysAllocString( enumvaluesW
);
757 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, in
, &out
, NULL
);
758 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
759 SysFreeString( method
);
762 VariantInit( &retval
);
763 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, &type
, NULL
);
764 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
765 ok( V_VT( &retval
) == VT_I4
, "unexpected variant type 0x%x\n", V_VT( &retval
) );
766 ok( !V_I4( &retval
), "unexpected error %u\n", V_I4( &retval
) );
767 ok( type
== CIM_UINT32
, "unexpected type 0x%x\n", type
);
770 VariantInit( &names
);
771 hr
= IWbemClassObject_Get( out
, namesW
, 0, &names
, &type
, NULL
);
772 ok( hr
== S_OK
, "failed to get names %08x\n", hr
);
773 ok( V_VT( &names
) == (VT_BSTR
|VT_ARRAY
), "unexpected variant type 0x%x\n", V_VT( &names
) );
774 ok( type
== (CIM_STRING
|CIM_FLAG_ARRAY
), "unexpected type 0x%x\n", type
);
777 VariantInit( &types
);
778 hr
= IWbemClassObject_Get( out
, typesW
, 0, &types
, &type
, NULL
);
779 ok( hr
== S_OK
, "failed to get names %08x\n", hr
);
780 ok( V_VT( &types
) == (VT_I4
|VT_ARRAY
), "unexpected variant type 0x%x\n", V_VT( &types
) );
781 ok( type
== (CIM_SINT32
|CIM_FLAG_ARRAY
), "unexpected type 0x%x\n", type
);
783 VariantClear( &types
);
784 VariantClear( &names
);
785 VariantClear( &subkey
);
786 IWbemClassObject_Release( in
);
787 IWbemClassObject_Release( out
);
788 IWbemClassObject_Release( sig_in
);
790 hr
= IWbemClassObject_GetMethod( reg
, getstringvalueW
, 0, &sig_in
, NULL
);
791 ok( hr
== S_OK
, "failed to get GetStringValue method %08x\n", hr
);
793 hr
= IWbemClassObject_SpawnInstance( sig_in
, 0, &in
);
794 ok( hr
== S_OK
, "failed to spawn instance %08x\n", hr
);
796 V_VT( &defkey
) = VT_I4
;
797 V_I4( &defkey
) = 0x80000002;
798 hr
= IWbemClassObject_Put( in
, defkeyW
, 0, &defkey
, 0 );
799 ok( hr
== S_OK
, "failed to set root %08x\n", hr
);
801 V_VT( &subkey
) = VT_BSTR
;
802 V_BSTR( &subkey
) = SysAllocString( windowsW
);
803 hr
= IWbemClassObject_Put( in
, subkeynameW
, 0, &subkey
, 0 );
804 ok( hr
== S_OK
, "failed to set subkey %08x\n", hr
);
806 V_VT( &valuename
) = VT_BSTR
;
807 V_BSTR( &valuename
) = SysAllocString( programfilesW
);
808 hr
= IWbemClassObject_Put( in
, valuenameW
, 0, &valuename
, 0 );
809 ok( hr
== S_OK
, "failed to set value name %08x\n", hr
);
812 method
= SysAllocString( getstringvalueW
);
813 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, in
, &out
, NULL
);
814 ok( hr
== S_OK
, "failed to execute method %08x\n", hr
);
815 SysFreeString( method
);
818 VariantInit( &retval
);
819 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, &type
, NULL
);
820 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
821 ok( V_VT( &retval
) == VT_I4
, "unexpected variant type 0x%x\n", V_VT( &retval
) );
822 ok( !V_I4( &retval
), "unexpected error %u\n", V_I4( &retval
) );
823 ok( type
== CIM_UINT32
, "unexpected type 0x%x\n", type
);
826 VariantInit( &value
);
827 hr
= IWbemClassObject_Get( out
, valueW
, 0, &value
, &type
, NULL
);
828 ok( hr
== S_OK
, "failed to get value %08x\n", hr
);
829 ok( V_VT( &value
) == VT_BSTR
, "unexpected variant type 0x%x\n", V_VT( &value
) );
830 ok( type
== CIM_STRING
, "unexpected type 0x%x\n", type
);
832 VariantClear( &value
);
833 VariantClear( &valuename
);
834 VariantClear( &subkey
);
835 IWbemClassObject_Release( in
);
836 IWbemClassObject_Release( out
);
837 IWbemClassObject_Release( sig_in
);
839 IWbemClassObject_Release( reg
);
840 SysFreeString( class );
843 static HRESULT WINAPI
sink_QueryInterface(
844 IWbemObjectSink
*iface
, REFIID riid
, void **ppv
)
847 if (IsEqualGUID( &IID_IUnknown
, riid
) || IsEqualGUID( &IID_IWbemObjectSink
, riid
))
850 IWbemObjectSink_AddRef( iface
);
853 return E_NOINTERFACE
;
856 static ULONG sink_refs
;
858 static ULONG WINAPI
sink_AddRef(
859 IWbemObjectSink
*iface
)
864 static ULONG WINAPI
sink_Release(
865 IWbemObjectSink
*iface
)
870 static HRESULT WINAPI
sink_Indicate(
871 IWbemObjectSink
*iface
, LONG count
, IWbemClassObject
**objects
)
873 trace("Indicate: %d, %p\n", count
, objects
);
877 static HRESULT WINAPI
sink_SetStatus(
878 IWbemObjectSink
*iface
, LONG flags
, HRESULT hresult
, BSTR str_param
, IWbemClassObject
*obj_param
)
880 trace("SetStatus: %08x, %08x, %s, %p\n", flags
, hresult
, wine_dbgstr_w(str_param
), obj_param
);
884 static IWbemObjectSinkVtbl sink_vtbl
=
893 static IWbemObjectSink sink
= { &sink_vtbl
};
895 static void test_notification_query_async( IWbemServices
*services
)
897 static const WCHAR queryW
[] =
898 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
899 'D','e','v','i','c','e','C','h','a','n','g','e','E','v','e','n','t',0};
900 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( queryW
);
901 ULONG prev_sink_refs
;
904 hr
= IWbemServices_ExecNotificationQueryAsync( services
, wql
, query
, 0, NULL
, NULL
);
905 ok( hr
== WBEM_E_INVALID_PARAMETER
, "got %08x\n", hr
);
907 prev_sink_refs
= sink_refs
;
908 hr
= IWbemServices_ExecNotificationQueryAsync( services
, wql
, query
, 0, NULL
, &sink
);
909 ok( hr
== S_OK
|| broken(hr
== WBEM_E_NOT_FOUND
), "got %08x\n", hr
);
910 ok( sink_refs
> prev_sink_refs
|| broken(!sink_refs
), "got %u refs\n", sink_refs
);
912 hr
= IWbemServices_CancelAsyncCall( services
, &sink
);
913 ok( hr
== S_OK
|| broken(hr
== WBEM_E_NOT_FOUND
), "got %08x\n", hr
);
915 SysFreeString( wql
);
916 SysFreeString( query
);
919 static void test_query_async( IWbemServices
*services
)
921 static const WCHAR queryW
[] =
922 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
923 'P','r','o','c','e','s','s',0};
924 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( queryW
);
927 hr
= IWbemServices_ExecQueryAsync( services
, wql
, query
, 0, NULL
, NULL
);
928 ok( hr
== WBEM_E_INVALID_PARAMETER
, "got %08x\n", hr
);
930 hr
= IWbemServices_ExecQueryAsync( services
, wql
, query
, 0, NULL
, &sink
);
931 ok( hr
== S_OK
|| broken(hr
== WBEM_E_NOT_FOUND
), "got %08x\n", hr
);
933 hr
= IWbemServices_CancelAsyncCall( services
, NULL
);
934 ok( hr
== WBEM_E_INVALID_PARAMETER
, "got %08x\n", hr
);
936 hr
= IWbemServices_CancelAsyncCall( services
, &sink
);
937 ok( hr
== S_OK
, "got %08x\n", hr
);
939 SysFreeString( wql
);
940 SysFreeString( query
);
943 static void test_GetNames( IWbemServices
*services
)
945 static const WCHAR queryW
[] =
946 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
947 'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
948 BSTR wql
= SysAllocString( wqlW
), query
= SysAllocString( queryW
);
949 IEnumWbemClassObject
*result
;
952 hr
= IWbemServices_ExecQuery( services
, wql
, query
, 0, NULL
, &result
);
953 ok( hr
== S_OK
, "got %08x\n", hr
);
957 IWbemClassObject
*obj
;
962 IEnumWbemClassObject_Next( result
, 10000, 1, &obj
, &count
);
966 hr
= IWbemClassObject_GetNames( obj
, NULL
, WBEM_FLAG_NONSYSTEM_ONLY
, &val
, &names
);
967 ok( hr
== S_OK
, "got %08x\n", hr
);
969 SafeArrayDestroy( names
);
970 IWbemClassObject_Release( obj
);
972 IEnumWbemClassObject_Release( result
);
973 SysFreeString( query
);
974 SysFreeString( wql
);
977 static void test_SystemSecurity( IWbemServices
*services
)
979 static const WCHAR systemsecurityW
[] = {'_','_','S','y','s','t','e','m','S','e','c','u','r','i','t','y',0};
980 static const WCHAR getsdW
[] = {'G','e','t','S','D',0};
981 static const WCHAR returnvalueW
[] = {'R','e','t','u','r','n','V','a','l','u','e',0};
982 static const WCHAR sdW
[] = {'S','D',0};
983 BSTR
class = SysAllocString( systemsecurityW
), method
;
984 IWbemClassObject
*reg
, *out
;
985 VARIANT retval
, var_sd
;
987 SECURITY_DESCRIPTOR_RELATIVE
*sd
;
990 BYTE sid_admin_buffer
[SECURITY_MAX_SID_SIZE
];
991 SID
*sid_admin
= (SID
*)sid_admin_buffer
;
995 hr
= IWbemServices_GetObject( services
, class, 0, NULL
, ®
, NULL
);
998 win_skip( "__SystemSecurity not available\n" );
1002 sid_size
= sizeof(sid_admin_buffer
);
1003 ret
= CreateWellKnownSid( WinBuiltinAdministratorsSid
, NULL
, sid_admin
, &sid_size
);
1004 ok( ret
, "CreateWellKnownSid failed\n" );
1007 method
= SysAllocString( getsdW
);
1008 hr
= IWbemServices_ExecMethod( services
, class, method
, 0, NULL
, NULL
, &out
, NULL
);
1009 ok( hr
== S_OK
|| hr
== WBEM_E_ACCESS_DENIED
, "failed to execute method %08x\n", hr
);
1010 SysFreeString( method
);
1015 VariantInit( &retval
);
1016 hr
= IWbemClassObject_Get( out
, returnvalueW
, 0, &retval
, &type
, NULL
);
1017 ok( hr
== S_OK
, "failed to get return value %08x\n", hr
);
1018 ok( V_VT( &retval
) == VT_I4
, "unexpected variant type 0x%x\n", V_VT( &retval
) );
1019 ok( !V_I4( &retval
), "unexpected error %u\n", V_UI4( &retval
) );
1020 ok( type
== CIM_UINT32
, "unexpected type 0x%x\n", type
);
1023 VariantInit( &var_sd
);
1024 hr
= IWbemClassObject_Get( out
, sdW
, 0, &var_sd
, &type
, NULL
);
1025 ok( hr
== S_OK
, "failed to get names %08x\n", hr
);
1026 ok( V_VT( &var_sd
) == (VT_UI1
|VT_ARRAY
), "unexpected variant type 0x%x\n", V_VT( &var_sd
) );
1027 ok( type
== (CIM_UINT8
|CIM_FLAG_ARRAY
), "unexpected type 0x%x\n", type
);
1029 hr
= SafeArrayAccessData( V_ARRAY( &var_sd
), &data
);
1030 ok( hr
== S_OK
, "SafeArrayAccessData failed %x\n", hr
);
1035 ok( (sd
->Control
& SE_SELF_RELATIVE
) == SE_SELF_RELATIVE
, "relative flag unset\n" );
1036 ok( sd
->Owner
!= 0, "no owner SID\n");
1037 ok( sd
->Group
!= 0, "no owner SID\n");
1038 ok( EqualSid( (PSID
)((LPBYTE
)sd
+ sd
->Owner
), sid_admin
), "unexpected owner SID\n" );
1039 ok( EqualSid( (PSID
)((LPBYTE
)sd
+ sd
->Group
), sid_admin
), "unexpected group SID\n" );
1041 hr
= SafeArrayUnaccessData( V_ARRAY( &var_sd
) );
1042 ok( hr
== S_OK
, "SafeArrayUnaccessData failed %x\n", hr
);
1045 VariantClear( &var_sd
);
1046 IWbemClassObject_Release( out
);
1048 else if (hr
== WBEM_E_ACCESS_DENIED
)
1049 win_skip( "insufficient privs to test __SystemSecurity\n" );
1051 SysFreeString( class );
1056 static const WCHAR cimv2W
[] = {'R','O','O','T','\\','C','I','M','V','2',0};
1057 BSTR path
= SysAllocString( cimv2W
);
1058 IWbemLocator
*locator
;
1059 IWbemServices
*services
;
1062 CoInitialize( NULL
);
1063 CoInitializeSecurity( NULL
, -1, NULL
, NULL
, RPC_C_AUTHN_LEVEL_DEFAULT
,
1064 RPC_C_IMP_LEVEL_IMPERSONATE
, NULL
, EOAC_NONE
, NULL
);
1065 hr
= CoCreateInstance( &CLSID_WbemLocator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWbemLocator
,
1066 (void **)&locator
);
1069 win_skip("can't create instance of WbemLocator\n");
1072 hr
= IWbemLocator_ConnectServer( locator
, path
, NULL
, NULL
, NULL
, 0, NULL
, NULL
, &services
);
1073 ok( hr
== S_OK
, "failed to get IWbemServices interface %08x\n", hr
);
1075 hr
= CoSetProxyBlanket( (IUnknown
*)services
, RPC_C_AUTHN_WINNT
, RPC_C_AUTHZ_NONE
, NULL
,
1076 RPC_C_AUTHN_LEVEL_CALL
, RPC_C_IMP_LEVEL_IMPERSONATE
, NULL
, EOAC_NONE
);
1077 ok( hr
== S_OK
, "failed to set proxy blanket %08x\n", hr
);
1079 test_select( services
);
1080 test_associators( services
);
1081 test_Win32_Bios( services
);
1082 test_Win32_Process( services
);
1083 test_Win32_Service( services
);
1084 test_Win32_ComputerSystem( services
);
1085 test_Win32_SystemEnclosure( services
);
1086 test_StdRegProv( services
);
1087 test_notification_query_async( services
);
1088 test_query_async( services
);
1089 test_GetNames( services
);
1090 test_SystemSecurity( services
);
1092 SysFreeString( path
);
1093 IWbemServices_Release( services
);
1094 IWbemLocator_Release( locator
);