ole32: Use symbolic names for range lock offsets.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob1ca41375dd9c35a4543e3b292715fc5169acb675
1 /*
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
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "initguid.h"
31 #include "wbemcli.h"
32 #include "wbemprov.h"
33 #include "winsock2.h"
34 #include "iphlpapi.h"
35 #include "tlhelp32.h"
36 #include "d3d10.h"
37 #include "winternl.h"
38 #include "winioctl.h"
39 #include "winsvc.h"
40 #include "winver.h"
42 #include "wine/debug.h"
43 #include "wbemprox_private.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
47 static const WCHAR class_baseboardW[] =
48 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
49 static const WCHAR class_biosW[] =
50 {'W','i','n','3','2','_','B','I','O','S',0};
51 static const WCHAR class_cdromdriveW[] =
52 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
53 static const WCHAR class_compsysW[] =
54 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
55 static const WCHAR class_datafileW[] =
56 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
57 static const WCHAR class_directoryW[] =
58 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
59 static const WCHAR class_diskdriveW[] =
60 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
61 static const WCHAR class_diskpartitionW[] =
62 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
63 static const WCHAR class_logicaldiskW[] =
64 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
65 static const WCHAR class_logicaldisk2W[] =
66 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
67 static const WCHAR class_networkadapterW[] =
68 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
69 static const WCHAR class_networkadapterconfigW[] =
70 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
71 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
72 static const WCHAR class_osW[] =
73 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
74 static const WCHAR class_paramsW[] =
75 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
76 static const WCHAR class_physicalmediaW[] =
77 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
78 static const WCHAR class_physicalmemoryW[] =
79 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
80 static const WCHAR class_qualifiersW[] =
81 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
82 static const WCHAR class_process_getowner_outW[] =
83 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
84 'N','E','R','_','O','U','T',0};
85 static const WCHAR class_processorW[] =
86 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
87 static const WCHAR class_sounddeviceW[] =
88 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
89 static const WCHAR class_videocontrollerW[] =
90 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
92 static const WCHAR prop_acceptpauseW[] =
93 {'A','c','c','e','p','t','P','a','u','s','e',0};
94 static const WCHAR prop_acceptstopW[] =
95 {'A','c','c','e','p','t','S','t','o','p',0};
96 static const WCHAR prop_accessmaskW[] =
97 {'A','c','c','e','s','s','M','a','s','k',0};
98 static const WCHAR prop_adapterdactypeW[] =
99 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
100 static const WCHAR prop_adapterramW[] =
101 {'A','d','a','p','t','e','r','R','A','M',0};
102 static const WCHAR prop_adaptertypeW[] =
103 {'A','d','a','p','t','e','r','T','y','p','e',0};
104 static const WCHAR prop_addresswidthW[] =
105 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
106 static const WCHAR prop_availabilityW[] =
107 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
108 static const WCHAR prop_bootableW[] =
109 {'B','o','o','t','a','b','l','e',0};
110 static const WCHAR prop_bootpartitionW[] =
111 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
112 static const WCHAR prop_buildnumberW[] =
113 {'B','u','i','l','d','N','u','m','b','e','r',0};
114 static const WCHAR prop_capacityW[] =
115 {'C','a','p','a','c','i','t','y',0};
116 static const WCHAR prop_captionW[] =
117 {'C','a','p','t','i','o','n',0};
118 static const WCHAR prop_classW[] =
119 {'C','l','a','s','s',0};
120 static const WCHAR prop_codesetW[] =
121 {'C','o','d','e','S','e','t',0};
122 static const WCHAR prop_commandlineW[] =
123 {'C','o','m','m','a','n','d','L','i','n','e',0};
124 static const WCHAR prop_countrycodeW[] =
125 {'C','o','u','n','t','r','y','C','o','d','e',0};
126 static const WCHAR prop_cpustatusW[] =
127 {'C','p','u','S','t','a','t','u','s',0};
128 static const WCHAR prop_csdversionW[] =
129 {'C','S','D','V','e','r','s','i','o','n',0};
130 static const WCHAR prop_currentbitsperpixelW[] =
131 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
132 static const WCHAR prop_currentclockspeedW[] =
133 {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
134 static const WCHAR prop_currenthorizontalresW[] =
135 {'C','u','r','r','e','n','t','H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
136 static const WCHAR prop_currentverticalresW[] =
137 {'C','u','r','r','e','n','t','V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
138 static const WCHAR prop_defaultvalueW[] =
139 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
140 static const WCHAR prop_descriptionW[] =
141 {'D','e','s','c','r','i','p','t','i','o','n',0};
142 static const WCHAR prop_deviceidW[] =
143 {'D','e','v','i','c','e','I','d',0};
144 static const WCHAR prop_directionW[] =
145 {'D','i','r','e','c','t','i','o','n',0};
146 static const WCHAR prop_displaynameW[] =
147 {'D','i','s','p','l','a','y','N','a','m','e',0};
148 static const WCHAR prop_diskindexW[] =
149 {'D','i','s','k','I','n','d','e','x',0};
150 static const WCHAR prop_domainW[] =
151 {'D','o','m','a','i','n',0};
152 static const WCHAR prop_domainroleW[] =
153 {'D','o','m','a','i','n','R','o','l','e',0};
154 static const WCHAR prop_driveW[] =
155 {'D','r','i','v','e',0};
156 static const WCHAR prop_drivetypeW[] =
157 {'D','r','i','v','e','T','y','p','e',0};
158 static const WCHAR prop_familyW[] =
159 {'F','a','m','i','l','y',0};
160 static const WCHAR prop_filesystemW[] =
161 {'F','i','l','e','S','y','s','t','e','m',0};
162 static const WCHAR prop_flavorW[] =
163 {'F','l','a','v','o','r',0};
164 static const WCHAR prop_freespaceW[] =
165 {'F','r','e','e','S','p','a','c','e',0};
166 static const WCHAR prop_handleW[] =
167 {'H','a','n','d','l','e',0};
168 static const WCHAR prop_idW[] =
169 {'I','D',0};
170 static const WCHAR prop_identificationcodeW[] =
171 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
172 static const WCHAR prop_indexW[] =
173 {'I','n','d','e','x',0};
174 static const WCHAR prop_installdateW[] =
175 {'I','n','s','t','a','l','l','D','a','t','e',0};
176 static const WCHAR prop_interfaceindexW[] =
177 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
178 static const WCHAR prop_interfacetypeW[] =
179 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
180 static const WCHAR prop_intvalueW[] =
181 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
182 static const WCHAR prop_ipconnectionmetricW[] =
183 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
184 static const WCHAR prop_ipenabledW[] =
185 {'I','P','E','n','a','b','l','e','d',0};
186 static const WCHAR prop_lastbootuptimeW[] =
187 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
188 static const WCHAR prop_localdatetimeW[] =
189 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
190 static const WCHAR prop_localeW[] =
191 {'L','o','c','a','l','e',0};
192 static const WCHAR prop_macaddressW[] =
193 {'M','A','C','A','d','d','r','e','s','s',0};
194 static const WCHAR prop_manufacturerW[] =
195 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
196 static const WCHAR prop_maxclockspeedW[] =
197 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
198 static const WCHAR prop_mediatypeW[] =
199 {'M','e','d','i','a','T','y','p','e',0};
200 static const WCHAR prop_memberW[] =
201 {'M','e','m','b','e','r',0};
202 static const WCHAR prop_methodW[] =
203 {'M','e','t','h','o','d',0};
204 static const WCHAR prop_modelW[] =
205 {'M','o','d','e','l',0};
206 static const WCHAR prop_netconnectionstatusW[] =
207 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
208 static const WCHAR prop_numcoresW[] =
209 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
210 static const WCHAR prop_numlogicalprocessorsW[] =
211 {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
212 static const WCHAR prop_numprocessorsW[] =
213 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
214 static const WCHAR prop_osarchitectureW[] =
215 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
216 static const WCHAR prop_oslanguageW[] =
217 {'O','S','L','a','n','g','u','a','g','e',0};
218 static const WCHAR prop_osproductsuiteW[] =
219 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
220 static const WCHAR prop_ostypeW[] =
221 {'O','S','T','y','p','e',0};
222 static const WCHAR prop_parameterW[] =
223 {'P','a','r','a','m','e','t','e','r',0};
224 static const WCHAR prop_physicaladapterW[] =
225 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
226 static const WCHAR prop_pnpdeviceidW[] =
227 {'P','N','P','D','e','v','i','c','e','I','D',0};
228 static const WCHAR prop_pprocessidW[] =
229 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
230 static const WCHAR prop_processidW[] =
231 {'P','r','o','c','e','s','s','I','D',0};
232 static const WCHAR prop_processoridW[] =
233 {'P','r','o','c','e','s','s','o','r','I','d',0};
234 static const WCHAR prop_productnameW[] =
235 {'P','r','o','d','u','c','t','N','a','m','e',0};
236 static const WCHAR prop_releasedateW[] =
237 {'R','e','l','e','a','s','e','D','a','t','e',0};
238 static const WCHAR prop_serialnumberW[] =
239 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
240 static const WCHAR prop_servicepackmajorW[] =
241 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
242 static const WCHAR prop_servicepackminorW[] =
243 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
244 static const WCHAR prop_servicetypeW[] =
245 {'S','e','r','v','i','c','e','T','y','p','e',0};
246 static const WCHAR prop_smbiosbiosversionW[] =
247 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
248 static const WCHAR prop_startmodeW[] =
249 {'S','t','a','r','t','M','o','d','e',0};
250 static const WCHAR prop_sizeW[] =
251 {'S','i','z','e',0};
252 static const WCHAR prop_speedW[] =
253 {'S','p','e','e','d',0};
254 static const WCHAR prop_startingoffsetW[] =
255 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
256 static const WCHAR prop_stateW[] =
257 {'S','t','a','t','e',0};
258 static const WCHAR prop_strvalueW[] =
259 {'S','t','r','i','n','g','V','a','l','u','e',0};
260 static const WCHAR prop_suitemaskW[] =
261 {'S','u','i','t','e','M','a','s','k',0};
262 static const WCHAR prop_systemdirectoryW[] =
263 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
264 static const WCHAR prop_systemnameW[] =
265 {'S','y','s','t','e','m','N','a','m','e',0};
266 static const WCHAR prop_tagW[] =
267 {'T','a','g',0};
268 static const WCHAR prop_threadcountW[] =
269 {'T','h','r','e','a','d','C','o','u','n','t',0};
270 static const WCHAR prop_totalphysicalmemoryW[] =
271 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
272 static const WCHAR prop_typeW[] =
273 {'T','y','p','e',0};
274 static const WCHAR prop_uniqueidW[] =
275 {'U','n','i','q','u','e','I','d',0};
276 static const WCHAR prop_varianttypeW[] =
277 {'V','a','r','i','a','n','t','T','y','p','e',0};
278 static const WCHAR prop_versionW[] =
279 {'V','e','r','s','i','o','n',0};
280 static const WCHAR prop_volumeserialnumberW[] =
281 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
283 /* column definitions must be kept in sync with record structures below */
284 static const struct column col_baseboard[] =
286 { prop_manufacturerW, CIM_STRING },
287 { prop_modelW, CIM_STRING },
288 { prop_nameW, CIM_STRING },
289 { prop_serialnumberW, CIM_STRING },
290 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
292 static const struct column col_bios[] =
294 { prop_descriptionW, CIM_STRING },
295 { prop_identificationcodeW, CIM_STRING },
296 { prop_manufacturerW, CIM_STRING },
297 { prop_releasedateW, CIM_DATETIME },
298 { prop_serialnumberW, CIM_STRING },
299 { prop_smbiosbiosversionW, CIM_STRING },
300 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
302 static const struct column col_cdromdrive[] =
304 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
305 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
306 { prop_mediatypeW, CIM_STRING },
307 { prop_nameW, CIM_STRING },
308 { prop_pnpdeviceidW, CIM_STRING }
310 static const struct column col_compsys[] =
312 { prop_descriptionW, CIM_STRING },
313 { prop_domainW, CIM_STRING },
314 { prop_domainroleW, CIM_UINT16 },
315 { prop_manufacturerW, CIM_STRING },
316 { prop_modelW, CIM_STRING },
317 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
318 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
319 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
320 { prop_totalphysicalmemoryW, CIM_UINT64 }
322 static const struct column col_datafile[] =
324 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
325 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
327 static const struct column col_directory[] =
329 { prop_accessmaskW, CIM_UINT32 },
330 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
332 static const struct column col_diskdrive[] =
334 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
335 { prop_indexW, CIM_UINT32, VT_I4 },
336 { prop_interfacetypeW, CIM_STRING },
337 { prop_manufacturerW, CIM_STRING },
338 { prop_mediatypeW, CIM_STRING },
339 { prop_modelW, CIM_STRING },
340 { prop_serialnumberW, CIM_STRING },
341 { prop_sizeW, CIM_UINT64 }
343 static const struct column col_diskpartition[] =
345 { prop_bootableW, CIM_BOOLEAN },
346 { prop_bootpartitionW, CIM_BOOLEAN },
347 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
348 { prop_diskindexW, CIM_UINT32, VT_I4 },
349 { prop_indexW, CIM_UINT32, VT_I4 },
350 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
351 { prop_sizeW, CIM_UINT64 },
352 { prop_startingoffsetW, CIM_UINT64 },
353 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
355 static const struct column col_logicaldisk[] =
357 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
358 { prop_drivetypeW, CIM_UINT32, VT_I4 },
359 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
360 { prop_freespaceW, CIM_UINT64 },
361 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
362 { prop_sizeW, CIM_UINT64 },
363 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
365 static const struct column col_networkadapter[] =
367 { prop_adaptertypeW, CIM_STRING },
368 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
369 { prop_indexW, CIM_UINT32, VT_I4 },
370 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
371 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
372 { prop_manufacturerW, CIM_STRING },
373 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
374 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
375 { prop_physicaladapterW, CIM_BOOLEAN },
376 { prop_pnpdeviceidW, CIM_STRING },
377 { prop_speedW, CIM_UINT64 }
379 static const struct column col_networkadapterconfig[] =
381 { prop_indexW, CIM_UINT32|COL_FLAG_KEY },
382 { prop_ipconnectionmetricW, CIM_UINT32 },
383 { prop_ipenabledW, CIM_BOOLEAN },
384 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
386 static const struct column col_os[] =
388 { prop_buildnumberW, CIM_STRING },
389 { prop_captionW, CIM_STRING },
390 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
391 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
392 { prop_csdversionW, CIM_STRING },
393 { prop_installdateW, CIM_DATETIME },
394 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
395 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
396 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
397 { prop_nameW, CIM_STRING },
398 { prop_osarchitectureW, CIM_STRING },
399 { prop_oslanguageW, CIM_UINT32, VT_I4 },
400 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
401 { prop_ostypeW, CIM_UINT16, VT_I4 },
402 { prop_serialnumberW, CIM_STRING },
403 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
404 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
405 { prop_suitemaskW, CIM_UINT32, VT_I4 },
406 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
407 { prop_versionW, CIM_STRING }
409 static const struct column col_param[] =
411 { prop_classW, CIM_STRING },
412 { prop_methodW, CIM_STRING },
413 { prop_directionW, CIM_SINT32 },
414 { prop_parameterW, CIM_STRING },
415 { prop_typeW, CIM_UINT32 },
416 { prop_varianttypeW, CIM_UINT32 },
417 { prop_defaultvalueW, CIM_UINT32 }
419 static const struct column col_physicalmedia[] =
421 { prop_serialnumberW, CIM_STRING },
422 { prop_tagW, CIM_STRING }
424 static const struct column col_physicalmemory[] =
426 { prop_capacityW, CIM_UINT64 }
428 static const struct column col_process[] =
430 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
431 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
432 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
433 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
434 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
435 { prop_pprocessidW, CIM_UINT32, VT_I4 },
436 { prop_processidW, CIM_UINT32, VT_I4 },
437 { prop_threadcountW, CIM_UINT32, VT_I4 },
438 /* methods */
439 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
441 static const struct column col_processor[] =
443 { prop_addresswidthW, CIM_UINT16, VT_I4 },
444 { prop_cpustatusW, CIM_UINT16 },
445 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
446 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
447 { prop_familyW, CIM_UINT16, VT_I4 },
448 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
449 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
450 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
451 { prop_numcoresW, CIM_UINT32, VT_I4 },
452 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
453 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
454 { prop_uniqueidW, CIM_STRING }
456 static const struct column col_qualifier[] =
458 { prop_classW, CIM_STRING },
459 { prop_memberW, CIM_STRING },
460 { prop_typeW, CIM_UINT32 },
461 { prop_flavorW, CIM_SINT32 },
462 { prop_nameW, CIM_STRING },
463 { prop_intvalueW, CIM_SINT32 },
464 { prop_strvalueW, CIM_STRING }
466 static const struct column col_service[] =
468 { prop_acceptpauseW, CIM_BOOLEAN },
469 { prop_acceptstopW, CIM_BOOLEAN },
470 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
471 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
472 { prop_processidW, CIM_UINT32 },
473 { prop_servicetypeW, CIM_STRING },
474 { prop_startmodeW, CIM_STRING },
475 { prop_stateW, CIM_STRING },
476 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
477 /* methods */
478 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
479 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
480 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
481 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
483 static const struct column col_sounddevice[] =
485 { prop_nameW, CIM_STRING },
486 { prop_productnameW, CIM_STRING }
488 static const struct column col_stdregprov[] =
490 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
491 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
492 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
494 static const struct column col_videocontroller[] =
496 { prop_adapterdactypeW, CIM_STRING },
497 { prop_adapterramW, CIM_UINT32, VT_I4 },
498 { prop_availabilityW, CIM_UINT16 },
499 { prop_currentbitsperpixelW, CIM_UINT32 },
500 { prop_currenthorizontalresW, CIM_UINT32 },
501 { prop_currentverticalresW, CIM_UINT32 },
502 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
503 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
504 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
505 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
508 static const WCHAR baseboard_manufacturerW[] =
509 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
510 static const WCHAR baseboard_serialnumberW[] =
511 {'N','o','n','e',0};
512 static const WCHAR baseboard_tagW[] =
513 {'B','a','s','e',' ','B','o','a','r','d',0};
514 static const WCHAR bios_descriptionW[] =
515 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
516 static const WCHAR bios_manufacturerW[] =
517 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
518 static const WCHAR bios_releasedateW[] =
519 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
520 static const WCHAR bios_serialnumberW[] =
521 {'0',0};
522 static const WCHAR bios_smbiosbiosversionW[] =
523 {'W','i','n','e',0};
524 static const WCHAR bios_versionW[] =
525 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
526 static const WCHAR cdromdrive_mediatypeW[] =
527 {'C','D','-','R','O','M',0};
528 static const WCHAR cdromdrive_nameW[] =
529 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
530 static const WCHAR cdromdrive_pnpdeviceidW[]=
531 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
532 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
533 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
534 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
535 static const WCHAR compsys_descriptionW[] =
536 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
537 static const WCHAR compsys_domainW[] =
538 {'W','O','R','K','G','R','O','U','P',0};
539 static const WCHAR compsys_manufacturerW[] =
540 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
541 static const WCHAR compsys_modelW[] =
542 {'W','i','n','e',0};
543 static const WCHAR diskdrive_interfacetypeW[] =
544 {'I','D','E',0};
545 static const WCHAR diskdrive_manufacturerW[] =
546 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
547 static const WCHAR diskdrive_mediatype_fixedW[] =
548 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
549 static const WCHAR diskdrive_mediatype_removableW[] =
550 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
551 static const WCHAR diskdrive_modelW[] =
552 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
553 static const WCHAR diskdrive_serialW[] =
554 {'W','I','N','E','H','D','I','S','K',0};
555 static const WCHAR networkadapter_pnpdeviceidW[]=
556 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
557 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
558 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
559 static const WCHAR os_32bitW[] =
560 {'3','2','-','b','i','t',0};
561 static const WCHAR os_64bitW[] =
562 {'6','4','-','b','i','t',0};
563 static const WCHAR os_buildnumberW[] =
564 {'2','6','0','0',0};
565 static const WCHAR os_captionW[] =
566 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
567 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
568 static const WCHAR os_csdversionW[] =
569 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
570 static const WCHAR os_installdateW[] =
571 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
572 static const WCHAR os_nameW[] =
573 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
574 'P','r','o','f','e','s','s','i','o','n','a','l','|','C',':','\\','W','I','N','D','O','W','S',
575 '|','\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','0',
576 '\\','P','a','r','t','i','t','i','o','n','1',0};
577 static const WCHAR os_serialnumberW[] =
578 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
579 static const WCHAR os_versionW[] =
580 {'5','.','1','.','2','6','0','0',0};
581 static const WCHAR physicalmedia_tagW[] =
582 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
583 static const WCHAR sounddevice_productnameW[] =
584 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
585 static const WCHAR videocontroller_dactypeW[] =
586 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
587 static const WCHAR videocontroller_deviceidW[] =
588 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
590 #include "pshpack1.h"
591 struct record_baseboard
593 const WCHAR *manufacturer;
594 const WCHAR *model;
595 const WCHAR *name;
596 const WCHAR *serialnumber;
597 const WCHAR *tag;
599 struct record_bios
601 const WCHAR *description;
602 const WCHAR *identificationcode;
603 const WCHAR *manufacturer;
604 const WCHAR *releasedate;
605 const WCHAR *serialnumber;
606 const WCHAR *smbiosbiosversion;
607 const WCHAR *version;
609 struct record_cdromdrive
611 const WCHAR *device_id;
612 const WCHAR *drive;
613 const WCHAR *mediatype;
614 const WCHAR *name;
615 const WCHAR *pnpdevice_id;
617 struct record_computersystem
619 const WCHAR *description;
620 const WCHAR *domain;
621 UINT16 domainrole;
622 const WCHAR *manufacturer;
623 const WCHAR *model;
624 const WCHAR *name;
625 UINT32 num_logical_processors;
626 UINT32 num_processors;
627 UINT64 total_physical_memory;
629 struct record_datafile
631 const WCHAR *name;
632 const WCHAR *version;
634 struct record_directory
636 UINT32 accessmask;
637 const WCHAR *name;
639 struct record_diskdrive
641 const WCHAR *device_id;
642 UINT32 index;
643 const WCHAR *interfacetype;
644 const WCHAR *manufacturer;
645 const WCHAR *mediatype;
646 const WCHAR *model;
647 const WCHAR *serialnumber;
648 UINT64 size;
650 struct record_diskpartition
652 int bootable;
653 int bootpartition;
654 const WCHAR *device_id;
655 UINT32 diskindex;
656 UINT32 index;
657 const WCHAR *pnpdevice_id;
658 UINT64 size;
659 UINT64 startingoffset;
660 const WCHAR *type;
662 struct record_logicaldisk
664 const WCHAR *device_id;
665 UINT32 drivetype;
666 const WCHAR *filesystem;
667 UINT64 freespace;
668 const WCHAR *name;
669 UINT64 size;
670 const WCHAR *volumeserialnumber;
672 struct record_networkadapter
674 const WCHAR *adaptertype;
675 const WCHAR *device_id;
676 UINT32 index;
677 UINT32 interface_index;
678 const WCHAR *mac_address;
679 const WCHAR *manufacturer;
680 const WCHAR *name;
681 UINT16 netconnection_status;
682 int physicaladapter;
683 const WCHAR *pnpdevice_id;
684 UINT64 speed;
686 struct record_networkadapterconfig
688 UINT32 index;
689 UINT32 ipconnectionmetric;
690 int ipenabled;
691 const WCHAR *mac_address;
693 struct record_operatingsystem
695 const WCHAR *buildnumber;
696 const WCHAR *caption;
697 const WCHAR *codeset;
698 const WCHAR *countrycode;
699 const WCHAR *csdversion;
700 const WCHAR *installdate;
701 const WCHAR *lastbootuptime;
702 const WCHAR *localdatetime;
703 const WCHAR *locale;
704 const WCHAR *name;
705 const WCHAR *osarchitecture;
706 UINT32 oslanguage;
707 UINT32 osproductsuite;
708 UINT16 ostype;
709 const WCHAR *serialnumber;
710 UINT16 servicepackmajor;
711 UINT16 servicepackminor;
712 UINT32 suitemask;
713 const WCHAR *systemdirectory;
714 const WCHAR *version;
716 struct record_param
718 const WCHAR *class;
719 const WCHAR *method;
720 INT32 direction;
721 const WCHAR *parameter;
722 UINT32 type;
723 UINT32 varianttype;
724 UINT32 defaultvalue;
726 struct record_physicalmedia
728 const WCHAR *serialnumber;
729 const WCHAR *tag;
731 struct record_physicalmemory
733 UINT64 capacity;
735 struct record_process
737 const WCHAR *caption;
738 const WCHAR *commandline;
739 const WCHAR *description;
740 const WCHAR *handle;
741 const WCHAR *name;
742 UINT32 pprocess_id;
743 UINT32 process_id;
744 UINT32 thread_count;
745 /* methods */
746 class_method *get_owner;
748 struct record_processor
750 UINT16 addresswidth;
751 UINT16 cpu_status;
752 UINT32 currentclockspeed;
753 const WCHAR *device_id;
754 UINT16 family;
755 const WCHAR *manufacturer;
756 UINT32 maxclockspeed;
757 const WCHAR *name;
758 UINT32 num_cores;
759 UINT32 num_logical_processors;
760 const WCHAR *processor_id;
761 const WCHAR *unique_id;
763 struct record_qualifier
765 const WCHAR *class;
766 const WCHAR *member;
767 UINT32 type;
768 INT32 flavor;
769 const WCHAR *name;
770 INT32 intvalue;
771 const WCHAR *strvalue;
773 struct record_service
775 int accept_pause;
776 int accept_stop;
777 const WCHAR *displayname;
778 const WCHAR *name;
779 UINT32 process_id;
780 const WCHAR *servicetype;
781 const WCHAR *startmode;
782 const WCHAR *state;
783 const WCHAR *systemname;
784 /* methods */
785 class_method *pause_service;
786 class_method *resume_service;
787 class_method *start_service;
788 class_method *stop_service;
790 struct record_sounddevice
792 const WCHAR *name;
793 const WCHAR *productname;
795 struct record_stdregprov
797 class_method *enumkey;
798 class_method *enumvalues;
799 class_method *getstringvalue;
801 struct record_videocontroller
803 const WCHAR *adapter_dactype;
804 UINT32 adapter_ram;
805 UINT16 availability;
806 UINT32 current_bitsperpixel;
807 UINT32 current_horizontalres;
808 UINT32 current_verticalres;
809 const WCHAR *description;
810 const WCHAR *device_id;
811 const WCHAR *name;
812 const WCHAR *pnpdevice_id;
814 #include "poppack.h"
816 static const struct record_baseboard data_baseboard[] =
818 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
820 static const struct record_bios data_bios[] =
822 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
823 bios_smbiosbiosversionW, bios_versionW }
825 static const struct record_param data_param[] =
827 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
828 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
829 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
830 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
831 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
832 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
833 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
834 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
835 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
836 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
837 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
838 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
839 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
840 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
841 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
842 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
843 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
844 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
845 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
846 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
847 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
850 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
851 WBEM_FLAVOR_ORIGIN_PROPAGATED)
853 static const struct record_physicalmedia data_physicalmedia[] =
855 { diskdrive_serialW, physicalmedia_tagW }
857 static const struct record_qualifier data_qualifier[] =
859 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
860 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
862 static const struct record_sounddevice data_sounddevice[] =
864 { sounddevice_productnameW, sounddevice_productnameW }
866 static const struct record_stdregprov data_stdregprov[] =
868 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
871 /* check if row matches condition and update status */
872 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
874 LONGLONG val;
875 UINT type;
877 if (!cond)
879 *status = FILL_STATUS_UNFILTERED;
880 return TRUE;
882 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
884 *status = FILL_STATUS_FAILED;
885 return FALSE;
887 *status = FILL_STATUS_FILTERED;
888 return val != 0;
891 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
893 if (!table->num_rows_allocated)
895 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
896 table->num_rows_allocated = row_count;
897 return TRUE;
899 if (row_count >= table->num_rows_allocated)
901 BYTE *data;
902 UINT count = table->num_rows_allocated * 2;
903 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
904 table->data = data;
905 table->num_rows_allocated = count;
907 return TRUE;
910 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
912 static const WCHAR fmtW[] = {'%','c',':',0};
913 WCHAR drive[3], root[] = {'A',':','\\',0};
914 struct record_cdromdrive *rec;
915 UINT i, row = 0, offset = 0;
916 DWORD drives = GetLogicalDrives();
917 enum fill_status status = FILL_STATUS_UNFILTERED;
919 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
921 for (i = 0; i < sizeof(drives); i++)
923 if (drives & (1 << i))
925 root[0] = 'A' + i;
926 if (GetDriveTypeW( root ) != DRIVE_CDROM)
927 continue;
929 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
931 rec = (struct record_cdromdrive *)(table->data + offset);
932 rec->device_id = cdromdrive_pnpdeviceidW;
933 sprintfW( drive, fmtW, 'A' + i );
934 rec->drive = heap_strdupW( drive );
935 rec->mediatype = cdromdrive_mediatypeW;
936 rec->name = cdromdrive_nameW;
937 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
938 if (!match_row( table, row, cond, &status ))
940 free_row_values( table, row );
941 continue;
943 offset += sizeof(*rec);
944 row++;
947 TRACE("created %u rows\n", row);
948 table->num_rows = row;
949 return status;
952 static UINT get_processor_count(void)
954 SYSTEM_BASIC_INFORMATION info;
956 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
957 return info.NumberOfProcessors;
960 static UINT get_logical_processor_count( UINT *num_cores )
962 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
963 UINT i, j, count = 0;
964 NTSTATUS status;
965 ULONG len;
967 if (num_cores) *num_cores = get_processor_count();
968 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
969 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
971 if (!(info = heap_alloc( len ))) return get_processor_count();
972 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
973 if (status != STATUS_SUCCESS)
975 heap_free( info );
976 return get_processor_count();
978 if (num_cores) *num_cores = 0;
979 for (i = 0; i < len / sizeof(*info); i++)
981 if (info[i].Relationship == RelationProcessorCore)
983 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
985 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
987 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
990 heap_free( info );
991 return count;
994 static UINT64 get_total_physical_memory(void)
996 MEMORYSTATUSEX status;
998 status.dwLength = sizeof(status);
999 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1000 return status.ullTotalPhys;
1003 static WCHAR *get_computername(void)
1005 WCHAR *ret;
1006 DWORD size = MAX_COMPUTERNAME_LENGTH;
1008 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1009 GetComputerNameW( ret, &size );
1010 return ret;
1013 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1015 struct record_computersystem *rec;
1016 enum fill_status status = FILL_STATUS_UNFILTERED;
1017 UINT row = 0;
1019 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1021 rec = (struct record_computersystem *)table->data;
1022 rec->description = compsys_descriptionW;
1023 rec->domain = compsys_domainW;
1024 rec->domainrole = 0; /* standalone workstation */
1025 rec->manufacturer = compsys_manufacturerW;
1026 rec->model = compsys_modelW;
1027 rec->name = get_computername();
1028 rec->num_logical_processors = get_logical_processor_count( NULL );
1029 rec->num_processors = get_processor_count();
1030 rec->total_physical_memory = get_total_physical_memory();
1031 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1032 else row++;
1034 TRACE("created %u rows\n", row);
1035 table->num_rows = row;
1036 return status;
1039 struct dirstack
1041 WCHAR **dirs;
1042 UINT *len_dirs;
1043 UINT num_dirs;
1044 UINT num_allocated;
1047 static struct dirstack *alloc_dirstack( UINT size )
1049 struct dirstack *dirstack;
1051 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1052 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1054 heap_free( dirstack );
1055 return NULL;
1057 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1059 heap_free( dirstack->dirs );
1060 heap_free( dirstack );
1061 return NULL;
1063 dirstack->num_dirs = 0;
1064 dirstack->num_allocated = size;
1065 return dirstack;
1068 static void clear_dirstack( struct dirstack *dirstack )
1070 UINT i;
1071 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1072 dirstack->num_dirs = 0;
1075 static void free_dirstack( struct dirstack *dirstack )
1077 clear_dirstack( dirstack );
1078 heap_free( dirstack->dirs );
1079 heap_free( dirstack->len_dirs );
1080 heap_free( dirstack );
1083 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1085 UINT size, i = dirstack->num_dirs;
1087 if (!dir) return FALSE;
1089 if (i == dirstack->num_allocated)
1091 WCHAR **tmp;
1092 UINT *len_tmp;
1094 size = dirstack->num_allocated * 2;
1095 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1096 dirstack->dirs = tmp;
1097 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1098 dirstack->len_dirs = len_tmp;
1099 dirstack->num_allocated = size;
1101 dirstack->dirs[i] = dir;
1102 dirstack->len_dirs[i] = len;
1103 dirstack->num_dirs++;
1104 return TRUE;
1107 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1109 if (!dirstack->num_dirs)
1111 *len = 0;
1112 return NULL;
1114 dirstack->num_dirs--;
1115 *len = dirstack->len_dirs[dirstack->num_dirs];
1116 return dirstack->dirs[dirstack->num_dirs];
1119 static const WCHAR *peek_dir( struct dirstack *dirstack )
1121 if (!dirstack->num_dirs) return NULL;
1122 return dirstack->dirs[dirstack->num_dirs - 1];
1125 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1127 UINT i = 0;
1128 WCHAR *ret;
1130 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1131 ret[i++] = drive;
1132 ret[i++] = ':';
1133 ret[i++] = '\\';
1134 if (path && len)
1136 memcpy( ret + i, path, len * sizeof(WCHAR) );
1137 i += len;
1138 ret[i++] = '\\';
1140 ret[i++] = '*';
1141 ret[i] = 0;
1142 return ret;
1145 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1147 UINT i = 0, len = 0;
1148 const WCHAR *p;
1149 WCHAR *ret;
1151 for (p = path; *p; p++)
1153 if (*p == '\\') len += 2;
1154 else len++;
1156 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1157 ret[i++] = drive;
1158 ret[i++] = ':';
1159 ret[i++] = '\\';
1160 ret[i++] = '\\';
1161 for (p = path; *p; p++)
1163 if (*p != '\\') ret[i++] = *p;
1164 else
1166 ret[i++] = '\\';
1167 ret[i++] = '\\';
1170 ret[i] = 0;
1171 return ret;
1174 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1176 const WCHAR *p = path, *start;
1177 UINT len, i;
1178 WCHAR *ret;
1180 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1181 start = path + 4;
1182 len = strlenW( start );
1183 p = start + len - 1;
1184 if (*p == '\\') return NULL;
1186 while (p >= start && *p != '\\') { len--; p--; };
1187 while (p >= start && *p == '\\') { len--; p--; };
1189 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1190 for (i = 0, p = start; p < start + len; p++)
1192 if (p[0] == '\\' && p[1] == '\\')
1194 ret[i++] = '\\';
1195 p++;
1197 else ret[i++] = *p;
1199 ret[i] = 0;
1200 *ret_len = i;
1201 return ret;
1204 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1206 UINT i;
1207 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1208 return FALSE;
1211 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1212 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1214 const struct expr *left, *right;
1216 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1218 left = cond->u.expr.left;
1219 right = cond->u.expr.right;
1220 if (cond->u.expr.op == OP_EQ)
1222 UINT len;
1223 WCHAR *path;
1224 const WCHAR *str = NULL;
1226 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1227 !strcmpW( left->u.propval->name, prop_nameW ) &&
1228 toupperW( right->u.sval[0] ) == toupperW( root ))
1230 str = right->u.sval;
1232 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1233 !strcmpW( right->u.propval->name, prop_nameW ) &&
1234 toupperW( left->u.sval[0] ) == toupperW( root ))
1236 str = left->u.sval;
1238 if (str && (path = build_dirname( str, &len )))
1240 if (seen_dir( dirstack, path ))
1242 heap_free( path );
1243 return ++*count;
1245 else if (push_dir( dirstack, path, len )) return ++*count;
1246 heap_free( path );
1247 return *count = 0;
1250 else if (cond->u.expr.op == OP_OR)
1252 UINT left_count = 0, right_count = 0;
1254 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1255 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1256 return *count += left_count + right_count;
1258 return *count = 0;
1261 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1263 UINT len_path = 0, len_segment = strlenW( segment );
1264 WCHAR *ret;
1266 *len = 0;
1267 if (path) len_path = strlenW( path );
1268 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1269 if (path && len_path)
1271 memcpy( ret, path, len_path * sizeof(WCHAR) );
1272 ret[len_path] = '\\';
1273 *len += len_path + 1;
1275 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1276 *len += len_segment;
1277 ret[*len] = 0;
1278 return ret;
1281 static WCHAR *get_file_version( const WCHAR *filename )
1283 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1284 VS_FIXEDFILEINFO *info;
1285 DWORD size;
1286 void *block;
1287 WCHAR *ret;
1289 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1290 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1292 heap_free( ret );
1293 return NULL;
1295 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1296 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1298 heap_free( block );
1299 heap_free( ret );
1300 return NULL;
1302 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1303 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1304 heap_free( block );
1305 return ret;
1308 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1310 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1311 struct record_datafile *rec;
1312 UINT i, len, row = 0, offset = 0, num_expected_rows;
1313 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1314 DWORD drives = GetLogicalDrives();
1315 WIN32_FIND_DATAW data;
1316 HANDLE handle;
1317 struct dirstack *dirstack;
1318 enum fill_status status = FILL_STATUS_UNFILTERED;
1320 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1322 dirstack = alloc_dirstack(2);
1324 for (i = 0; i < sizeof(drives); i++)
1326 if (!(drives & (1 << i))) continue;
1328 root[0] = 'A' + i;
1329 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1331 num_expected_rows = 0;
1332 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1334 for (;;)
1336 path = pop_dir( dirstack, &len );
1337 if (!(glob = build_glob( root[0], path, len )))
1339 status = FILL_STATUS_FAILED;
1340 goto done;
1342 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1346 if (!resize_table( table, row + 1, sizeof(*rec) ))
1348 status = FILL_STATUS_FAILED;
1349 FindClose( handle );
1350 goto done;
1352 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1353 new_path = append_path( path, data.cFileName, &len );
1355 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1357 if (push_dir( dirstack, new_path, len )) continue;
1358 heap_free( new_path );
1359 FindClose( handle );
1360 status = FILL_STATUS_FAILED;
1361 goto done;
1363 rec = (struct record_datafile *)(table->data + offset);
1364 rec->name = build_name( root[0], new_path );
1365 rec->version = get_file_version( rec->name );
1366 if (!match_row( table, row, cond, &status ))
1368 free_row_values( table, row );
1369 continue;
1371 else if (num_expected_rows && row == num_expected_rows - 1)
1373 row++;
1374 FindClose( handle );
1375 status = FILL_STATUS_FILTERED;
1376 goto done;
1378 offset += sizeof(*rec);
1379 row++;
1381 while (FindNextFileW( handle, &data ));
1382 FindClose( handle );
1384 if (!peek_dir( dirstack )) break;
1385 heap_free( glob );
1386 heap_free( path );
1390 done:
1391 free_dirstack( dirstack );
1392 heap_free( glob );
1393 heap_free( path );
1395 TRACE("created %u rows\n", row);
1396 table->num_rows = row;
1397 return status;
1400 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1402 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1403 struct record_directory *rec;
1404 UINT i, len, row = 0, offset = 0, num_expected_rows;
1405 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1406 DWORD drives = GetLogicalDrives();
1407 WIN32_FIND_DATAW data;
1408 HANDLE handle;
1409 struct dirstack *dirstack;
1410 enum fill_status status = FILL_STATUS_UNFILTERED;
1412 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1414 dirstack = alloc_dirstack(2);
1416 for (i = 0; i < sizeof(drives); i++)
1418 if (!(drives & (1 << i))) continue;
1420 root[0] = 'A' + i;
1421 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1423 num_expected_rows = 0;
1424 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1426 for (;;)
1428 path = pop_dir( dirstack, &len );
1429 if (!(glob = build_glob( root[0], path, len )))
1431 status = FILL_STATUS_FAILED;
1432 goto done;
1434 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1438 if (!resize_table( table, row + 1, sizeof(*rec) ))
1440 FindClose( handle );
1441 status = FILL_STATUS_FAILED;
1442 goto done;
1444 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1445 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1446 continue;
1448 new_path = append_path( path, data.cFileName, &len );
1449 if (!(push_dir( dirstack, new_path, len )))
1451 heap_free( new_path );
1452 FindClose( handle );
1453 status = FILL_STATUS_FAILED;
1454 goto done;
1456 rec = (struct record_directory *)(table->data + offset);
1457 rec->accessmask = FILE_ALL_ACCESS;
1458 rec->name = build_name( root[0], new_path );
1459 if (!match_row( table, row, cond, &status ))
1461 free_row_values( table, row );
1462 continue;
1464 else if (num_expected_rows && row == num_expected_rows - 1)
1466 row++;
1467 FindClose( handle );
1468 status = FILL_STATUS_FILTERED;
1469 goto done;
1471 offset += sizeof(*rec);
1472 row++;
1474 while (FindNextFileW( handle, &data ));
1475 FindClose( handle );
1477 if (!peek_dir( dirstack )) break;
1478 heap_free( glob );
1479 heap_free( path );
1483 done:
1484 free_dirstack( dirstack );
1485 heap_free( glob );
1486 heap_free( path );
1488 TRACE("created %u rows\n", row);
1489 table->num_rows = row;
1490 return status;
1493 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1495 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1496 ULARGE_INTEGER free;
1497 DISK_GEOMETRY_EX info;
1498 HANDLE handle;
1500 free.QuadPart = 512 * 1024 * 1024;
1501 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1503 root[4] = dir[0];
1504 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1505 if (handle != INVALID_HANDLE_VALUE)
1507 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1508 *disksize = info.DiskSize.QuadPart;
1509 CloseHandle( handle );
1511 return free.QuadPart;
1514 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1516 static const WCHAR fmtW[] =
1517 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1518 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1519 struct record_diskdrive *rec;
1520 UINT i, row = 0, offset = 0, index = 0, type;
1521 UINT64 size = 1024 * 1024 * 1024;
1522 DWORD drives = GetLogicalDrives();
1523 enum fill_status status = FILL_STATUS_UNFILTERED;
1525 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1527 for (i = 0; i < sizeof(drives); i++)
1529 if (drives & (1 << i))
1531 root[0] = 'A' + i;
1532 type = GetDriveTypeW( root );
1533 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1534 continue;
1536 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1538 rec = (struct record_diskdrive *)(table->data + offset);
1539 sprintfW( device_id, fmtW, index );
1540 rec->device_id = heap_strdupW( device_id );
1541 rec->index = index;
1542 rec->interfacetype = diskdrive_interfacetypeW;
1543 rec->manufacturer = diskdrive_manufacturerW;
1544 if (type == DRIVE_FIXED)
1545 rec->mediatype = diskdrive_mediatype_fixedW;
1546 else
1547 rec->mediatype = diskdrive_mediatype_removableW;
1548 rec->model = diskdrive_modelW;
1549 rec->serialnumber = diskdrive_serialW;
1550 get_freespace( root, &size );
1551 rec->size = size;
1552 if (!match_row( table, row, cond, &status ))
1554 free_row_values( table, row );
1555 continue;
1557 offset += sizeof(*rec);
1558 index++;
1559 row++;
1562 TRACE("created %u rows\n", row);
1563 table->num_rows = row;
1564 return status;
1567 static WCHAR *get_filesystem( const WCHAR *root )
1569 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1570 WCHAR buffer[MAX_PATH + 1];
1572 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1573 return heap_strdupW( buffer );
1574 return heap_strdupW( ntfsW );
1577 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1579 static const WCHAR fmtW[] =
1580 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1581 WCHAR device_id[32], root[] = {'A',':','\\',0};
1582 struct record_diskpartition *rec;
1583 UINT i, row = 0, offset = 0, type, index = 0;
1584 UINT64 size = 1024 * 1024 * 1024;
1585 DWORD drives = GetLogicalDrives();
1586 enum fill_status status = FILL_STATUS_UNFILTERED;
1588 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1590 for (i = 0; i < sizeof(drives); i++)
1592 if (drives & (1 << i))
1594 root[0] = 'A' + i;
1595 type = GetDriveTypeW( root );
1596 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1597 continue;
1599 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1601 rec = (struct record_diskpartition *)(table->data + offset);
1602 rec->bootable = (i == 2) ? -1 : 0;
1603 rec->bootpartition = (i == 2) ? -1 : 0;
1604 sprintfW( device_id, fmtW, index );
1605 rec->device_id = heap_strdupW( device_id );
1606 rec->diskindex = index;
1607 rec->index = 0;
1608 rec->pnpdevice_id = heap_strdupW( device_id );
1609 get_freespace( root, &size );
1610 rec->size = size;
1611 rec->startingoffset = 0;
1612 rec->type = get_filesystem( root );
1613 if (!match_row( table, row, cond, &status ))
1615 free_row_values( table, row );
1616 continue;
1618 offset += sizeof(*rec);
1619 row++;
1620 index++;
1623 TRACE("created %u rows\n", row);
1624 table->num_rows = row;
1625 return status;
1628 static WCHAR *get_volumeserialnumber( const WCHAR *root )
1630 static const WCHAR fmtW[] = {'%','0','8','X',0};
1631 DWORD serial = 0;
1632 WCHAR buffer[9];
1634 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
1635 sprintfW( buffer, fmtW, serial );
1636 return heap_strdupW( buffer );
1639 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1641 static const WCHAR fmtW[] = {'%','c',':',0};
1642 WCHAR device_id[3], root[] = {'A',':','\\',0};
1643 struct record_logicaldisk *rec;
1644 UINT i, row = 0, offset = 0, type;
1645 UINT64 size = 1024 * 1024 * 1024;
1646 DWORD drives = GetLogicalDrives();
1647 enum fill_status status = FILL_STATUS_UNFILTERED;
1649 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1651 for (i = 0; i < sizeof(drives); i++)
1653 if (drives & (1 << i))
1655 root[0] = 'A' + i;
1656 type = GetDriveTypeW( root );
1657 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1658 continue;
1660 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1662 rec = (struct record_logicaldisk *)(table->data + offset);
1663 sprintfW( device_id, fmtW, 'A' + i );
1664 rec->device_id = heap_strdupW( device_id );
1665 rec->drivetype = type;
1666 rec->filesystem = get_filesystem( root );
1667 rec->freespace = get_freespace( root, &size );
1668 rec->name = heap_strdupW( device_id );
1669 rec->size = size;
1670 rec->volumeserialnumber = get_volumeserialnumber( root );
1671 if (!match_row( table, row, cond, &status ))
1673 free_row_values( table, row );
1674 continue;
1676 offset += sizeof(*rec);
1677 row++;
1680 TRACE("created %u rows\n", row);
1681 table->num_rows = row;
1682 return status;
1685 static UINT16 get_connection_status( IF_OPER_STATUS status )
1687 switch (status)
1689 case IfOperStatusDown:
1690 return 0; /* Disconnected */
1691 case IfOperStatusUp:
1692 return 2; /* Connected */
1693 default:
1694 ERR("unhandled status %u\n", status);
1695 break;
1697 return 0;
1699 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1701 static const WCHAR fmtW[] =
1702 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1703 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1704 WCHAR *ret;
1706 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1707 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1708 return ret;
1710 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1712 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1713 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1714 static const WCHAR firewireW[] = {'1','3','9','4',0};
1715 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1717 switch (type)
1719 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1720 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1721 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1722 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1723 default: *physical = 0; return NULL;
1727 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1729 static const WCHAR fmtW[] = {'%','u',0};
1730 WCHAR device_id[11];
1731 struct record_networkadapter *rec;
1732 IP_ADAPTER_ADDRESSES *aa, *buffer;
1733 UINT row = 0, offset = 0, count = 0;
1734 DWORD size = 0, ret;
1735 int physical;
1736 enum fill_status status = FILL_STATUS_UNFILTERED;
1738 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1739 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1741 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1742 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1744 heap_free( buffer );
1745 return FILL_STATUS_FAILED;
1747 for (aa = buffer; aa; aa = aa->Next)
1749 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1751 if (!resize_table( table, count, sizeof(*rec) ))
1753 heap_free( buffer );
1754 return FILL_STATUS_FAILED;
1756 for (aa = buffer; aa; aa = aa->Next)
1758 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1760 rec = (struct record_networkadapter *)(table->data + offset);
1761 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1762 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1763 rec->device_id = heap_strdupW( device_id );
1764 rec->index = aa->u.s.IfIndex;
1765 rec->interface_index = aa->u.s.IfIndex;
1766 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1767 rec->manufacturer = compsys_manufacturerW;
1768 rec->name = heap_strdupW( aa->FriendlyName );
1769 rec->netconnection_status = get_connection_status( aa->OperStatus );
1770 rec->physicaladapter = physical;
1771 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1772 rec->speed = 1000000;
1773 if (!match_row( table, row, cond, &status ))
1775 free_row_values( table, row );
1776 continue;
1778 offset += sizeof(*rec);
1779 row++;
1781 TRACE("created %u rows\n", row);
1782 table->num_rows = row;
1784 heap_free( buffer );
1785 return status;
1788 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1790 struct record_networkadapterconfig *rec;
1791 IP_ADAPTER_ADDRESSES *aa, *buffer;
1792 UINT row = 0, offset = 0, count = 0;
1793 DWORD size = 0, ret;
1794 enum fill_status status = FILL_STATUS_UNFILTERED;
1796 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1797 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1799 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1800 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1802 heap_free( buffer );
1803 return FILL_STATUS_FAILED;
1805 for (aa = buffer; aa; aa = aa->Next)
1807 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1809 if (!resize_table( table, count, sizeof(*rec) ))
1811 heap_free( buffer );
1812 return FILL_STATUS_FAILED;
1814 for (aa = buffer; aa; aa = aa->Next)
1816 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1818 rec = (struct record_networkadapterconfig *)(table->data + offset);
1819 rec->index = aa->u.s.IfIndex;
1820 rec->ipconnectionmetric = 20;
1821 rec->ipenabled = -1;
1822 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1823 if (!match_row( table, row, cond, &status ))
1825 free_row_values( table, row );
1826 continue;
1828 offset += sizeof(*rec);
1829 row++;
1831 TRACE("created %u rows\n", row);
1832 table->num_rows = row;
1834 heap_free( buffer );
1835 return status;
1838 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
1840 struct record_physicalmemory *rec;
1841 enum fill_status status = FILL_STATUS_UNFILTERED;
1842 UINT row = 0;
1844 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1846 rec = (struct record_physicalmemory *)table->data;
1847 rec->capacity = get_total_physical_memory();
1848 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1849 else row++;
1851 TRACE("created %u rows\n", row);
1852 table->num_rows = row;
1853 return status;
1856 static WCHAR *get_cmdline( DWORD process_id )
1858 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1859 return NULL; /* FIXME handle different process case */
1862 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1864 static const WCHAR fmtW[] = {'%','u',0};
1865 WCHAR handle[11];
1866 struct record_process *rec;
1867 PROCESSENTRY32W entry;
1868 HANDLE snap;
1869 enum fill_status status = FILL_STATUS_FAILED;
1870 UINT row = 0, offset = 0;
1872 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1873 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1875 entry.dwSize = sizeof(entry);
1876 if (!Process32FirstW( snap, &entry )) goto done;
1877 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1881 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1883 rec = (struct record_process *)(table->data + offset);
1884 rec->caption = heap_strdupW( entry.szExeFile );
1885 rec->commandline = get_cmdline( entry.th32ProcessID );
1886 rec->description = heap_strdupW( entry.szExeFile );
1887 sprintfW( handle, fmtW, entry.th32ProcessID );
1888 rec->handle = heap_strdupW( handle );
1889 rec->name = heap_strdupW( entry.szExeFile );
1890 rec->process_id = entry.th32ProcessID;
1891 rec->pprocess_id = entry.th32ParentProcessID;
1892 rec->thread_count = entry.cntThreads;
1893 rec->get_owner = process_get_owner;
1894 if (!match_row( table, row, cond, &status ))
1896 free_row_values( table, row );
1897 continue;
1899 offset += sizeof(*rec);
1900 row++;
1901 } while (Process32NextW( snap, &entry ));
1903 TRACE("created %u rows\n", row);
1904 table->num_rows = row;
1905 status = FILL_STATUS_UNFILTERED;
1907 done:
1908 CloseHandle( snap );
1909 return status;
1912 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1914 #ifdef __i386__
1915 __asm__("pushl %%ebx\n\t"
1916 "cpuid\n\t"
1917 "movl %%ebx, %%esi\n\t"
1918 "popl %%ebx"
1919 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1920 : "0" (ax));
1921 #endif
1924 static void get_processor_id( WCHAR *processor_id )
1926 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1927 unsigned int regs[4] = {0, 0, 0, 0};
1929 do_cpuid( 1, regs );
1930 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1932 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1934 unsigned int i;
1935 unsigned char *p = (unsigned char *)regs;
1937 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1938 buffer[i] = 0;
1940 static void get_processor_manufacturer( WCHAR *manufacturer )
1942 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1944 do_cpuid( 0, regs );
1945 tmp = regs[2]; /* swap edx and ecx */
1946 regs[2] = regs[3];
1947 regs[3] = tmp;
1949 regs_to_str( regs + 1, 12, manufacturer );
1951 static void get_processor_name( WCHAR *name )
1953 unsigned int regs[4] = {0, 0, 0, 0};
1955 do_cpuid( 0x80000000, regs );
1956 if (regs[0] >= 0x80000004)
1958 do_cpuid( 0x80000002, regs );
1959 regs_to_str( regs, 16, name );
1960 do_cpuid( 0x80000003, regs );
1961 regs_to_str( regs, 16, name + 16 );
1962 do_cpuid( 0x80000004, regs );
1963 regs_to_str( regs, 16, name + 32 );
1966 static UINT get_processor_currentclockspeed( UINT index )
1968 PROCESSOR_POWER_INFORMATION *info;
1969 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1970 NTSTATUS status;
1972 if ((info = heap_alloc( size )))
1974 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1975 if (!status) ret = info[index].CurrentMhz;
1976 heap_free( info );
1978 return ret;
1980 static UINT get_processor_maxclockspeed( UINT index )
1982 PROCESSOR_POWER_INFORMATION *info;
1983 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1984 NTSTATUS status;
1986 if ((info = heap_alloc( size )))
1988 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1989 if (!status) ret = info[index].MaxMhz;
1990 heap_free( info );
1992 return ret;
1994 static const WCHAR *get_osarchitecture(void)
1996 SYSTEM_INFO info;
1997 GetNativeSystemInfo( &info );
1998 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1999 return os_32bitW;
2002 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2004 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2005 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
2006 struct record_processor *rec;
2007 UINT i, offset = 0, num_cores, num_logical_processors, count = get_processor_count();
2008 enum fill_status status = FILL_STATUS_UNFILTERED;
2010 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2012 get_processor_id( processor_id );
2013 get_processor_manufacturer( manufacturer );
2014 get_processor_name( name );
2016 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2017 num_cores /= count;
2019 for (i = 0; i < count; i++)
2021 rec = (struct record_processor *)(table->data + offset);
2022 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2023 rec->cpu_status = 1; /* CPU Enabled */
2024 rec->currentclockspeed = get_processor_currentclockspeed( i );
2025 sprintfW( device_id, fmtW, i );
2026 rec->device_id = heap_strdupW( device_id );
2027 rec->family = 2; /* Unknown */
2028 rec->manufacturer = heap_strdupW( manufacturer );
2029 rec->maxclockspeed = get_processor_maxclockspeed( i );
2030 rec->name = heap_strdupW( name );
2031 rec->num_cores = num_cores;
2032 rec->num_logical_processors = num_logical_processors;
2033 rec->processor_id = heap_strdupW( processor_id );
2034 rec->unique_id = NULL;
2035 if (!match_row( table, i, cond, &status ))
2037 free_row_values( table, i );
2038 continue;
2040 offset += sizeof(*rec);
2043 TRACE("created %u rows\n", count);
2044 table->num_rows = count;
2045 return status;
2048 static WCHAR *get_lastbootuptime(void)
2050 static const WCHAR fmtW[] =
2051 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2052 '.','%','0','6','u','+','0','0','0',0};
2053 SYSTEM_TIMEOFDAY_INFORMATION ti;
2054 TIME_FIELDS tf;
2055 WCHAR *ret;
2057 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2059 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2060 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2061 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2062 return ret;
2064 static WCHAR *get_localdatetime(void)
2066 static const WCHAR fmtW[] =
2067 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2068 '.','%','0','6','u','%','+','0','3','d',0};
2069 TIME_ZONE_INFORMATION tzi;
2070 SYSTEMTIME st;
2071 WCHAR *ret;
2072 DWORD Status;
2073 LONG Bias;
2075 Status = GetTimeZoneInformation(&tzi);
2077 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2078 Bias = tzi.Bias;
2079 if(Status == TIME_ZONE_ID_DAYLIGHT)
2080 Bias+= tzi.DaylightBias;
2081 else
2082 Bias+= tzi.StandardBias;
2083 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2085 GetLocalTime(&st);
2086 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2087 return ret;
2089 static WCHAR *get_systemdirectory(void)
2091 void *redir;
2092 WCHAR *ret;
2094 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2095 Wow64DisableWow64FsRedirection( &redir );
2096 GetSystemDirectoryW( ret, MAX_PATH );
2097 Wow64RevertWow64FsRedirection( redir );
2098 return ret;
2100 static WCHAR *get_codeset(void)
2102 static const WCHAR fmtW[] = {'%','u',0};
2103 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2104 if (ret) sprintfW( ret, fmtW, GetACP() );
2105 return ret;
2107 static WCHAR *get_countrycode(void)
2109 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2110 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2111 return ret;
2113 static WCHAR *get_locale(void)
2115 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2116 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2117 return ret;
2120 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2122 struct record_operatingsystem *rec;
2123 enum fill_status status = FILL_STATUS_UNFILTERED;
2124 UINT row = 0;
2126 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2128 rec = (struct record_operatingsystem *)table->data;
2129 rec->buildnumber = os_buildnumberW;
2130 rec->caption = os_captionW;
2131 rec->codeset = get_codeset();
2132 rec->countrycode = get_countrycode();
2133 rec->csdversion = os_csdversionW;
2134 rec->installdate = os_installdateW;
2135 rec->lastbootuptime = get_lastbootuptime();
2136 rec->localdatetime = get_localdatetime();
2137 rec->locale = get_locale();
2138 rec->name = os_nameW;
2139 rec->osarchitecture = get_osarchitecture();
2140 rec->oslanguage = GetSystemDefaultLangID();
2141 rec->osproductsuite = 2461140; /* Windows XP Professional */
2142 rec->ostype = 18; /* WINNT */
2143 rec->serialnumber = os_serialnumberW;
2144 rec->servicepackmajor = 3;
2145 rec->servicepackminor = 0;
2146 rec->suitemask = 272; /* Single User + Terminal */
2147 rec->systemdirectory = get_systemdirectory();
2148 rec->version = os_versionW;
2149 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2150 else row++;
2152 TRACE("created %u rows\n", row);
2153 table->num_rows = row;
2154 return status;
2157 static const WCHAR *get_service_type( DWORD type )
2159 static const WCHAR filesystem_driverW[] =
2160 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2161 static const WCHAR kernel_driverW[] =
2162 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2163 static const WCHAR own_processW[] =
2164 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2165 static const WCHAR share_processW[] =
2166 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2168 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2169 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2170 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2171 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2172 else ERR("unhandled type 0x%08x\n", type);
2173 return NULL;
2175 static const WCHAR *get_service_state( DWORD state )
2177 static const WCHAR runningW[] =
2178 {'R','u','n','n','i','n','g',0};
2179 static const WCHAR start_pendingW[] =
2180 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2181 static const WCHAR stop_pendingW[] =
2182 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2183 static const WCHAR stoppedW[] =
2184 {'S','t','o','p','p','e','d',0};
2185 static const WCHAR unknownW[] =
2186 {'U','n','k','n','o','w','n',0};
2188 switch (state)
2190 case SERVICE_STOPPED: return stoppedW;
2191 case SERVICE_START_PENDING: return start_pendingW;
2192 case SERVICE_STOP_PENDING: return stop_pendingW;
2193 case SERVICE_RUNNING: return runningW;
2194 default:
2195 ERR("unknown state %u\n", state);
2196 return unknownW;
2199 static const WCHAR *get_service_startmode( DWORD mode )
2201 static const WCHAR bootW[] = {'B','o','o','t',0};
2202 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2203 static const WCHAR autoW[] = {'A','u','t','o',0};
2204 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2205 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2206 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2208 switch (mode)
2210 case SERVICE_BOOT_START: return bootW;
2211 case SERVICE_SYSTEM_START: return systemW;
2212 case SERVICE_AUTO_START: return autoW;
2213 case SERVICE_DEMAND_START: return manualW;
2214 case SERVICE_DISABLED: return disabledW;
2215 default:
2216 ERR("unknown mode 0x%x\n", mode);
2217 return unknownW;
2220 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2222 QUERY_SERVICE_CONFIGW *config = NULL;
2223 SC_HANDLE service;
2224 DWORD size;
2226 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2227 QueryServiceConfigW( service, NULL, 0, &size );
2228 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2229 if (!(config = heap_alloc( size ))) goto done;
2230 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2231 heap_free( config );
2232 config = NULL;
2234 done:
2235 CloseServiceHandle( service );
2236 return config;
2239 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2241 struct record_service *rec;
2242 SC_HANDLE manager;
2243 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2244 SERVICE_STATUS_PROCESS *status;
2245 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2246 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2247 UINT i, row = 0, offset = 0, size = 256, needed, count;
2248 enum fill_status fill_status = FILL_STATUS_FAILED;
2249 BOOL ret;
2251 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2252 if (!(services = heap_alloc( size ))) goto done;
2254 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2255 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2256 &count, NULL, NULL );
2257 if (!ret)
2259 if (GetLastError() != ERROR_MORE_DATA) goto done;
2260 size = needed;
2261 if (!(tmp = heap_realloc( services, size ))) goto done;
2262 services = tmp;
2263 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2264 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2265 &count, NULL, NULL );
2266 if (!ret) goto done;
2268 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2270 GetComputerNameW( sysnameW, &len );
2271 fill_status = FILL_STATUS_UNFILTERED;
2273 for (i = 0; i < count; i++)
2275 QUERY_SERVICE_CONFIGW *config;
2277 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2279 status = &services[i].ServiceStatusProcess;
2280 rec = (struct record_service *)(table->data + offset);
2281 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2282 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2283 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2284 rec->name = heap_strdupW( services[i].lpServiceName );
2285 rec->process_id = status->dwProcessId;
2286 rec->servicetype = get_service_type( status->dwServiceType );
2287 rec->startmode = get_service_startmode( config->dwStartType );
2288 rec->state = get_service_state( status->dwCurrentState );
2289 rec->systemname = heap_strdupW( sysnameW );
2290 rec->pause_service = service_pause_service;
2291 rec->resume_service = service_resume_service;
2292 rec->start_service = service_start_service;
2293 rec->stop_service = service_stop_service;
2294 heap_free( config );
2295 if (!match_row( table, row, cond, &fill_status ))
2297 free_row_values( table, row );
2298 continue;
2300 offset += sizeof(*rec);
2301 row++;
2304 TRACE("created %u rows\n", row);
2305 table->num_rows = row;
2307 done:
2308 CloseServiceHandle( manager );
2309 heap_free( services );
2310 return fill_status;
2313 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2315 HDC hdc = GetDC( NULL );
2316 UINT32 ret;
2318 if (!hdc) return 32;
2319 ret = GetDeviceCaps( hdc, BITSPIXEL );
2320 *hres = GetDeviceCaps( hdc, HORZRES );
2321 *vres = GetDeviceCaps( hdc, VERTRES );
2322 ReleaseDC( NULL, hdc );
2323 return ret;
2325 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2327 static const WCHAR fmtW[] =
2328 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2329 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2330 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2331 WCHAR *ret;
2333 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2334 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2335 return ret;
2338 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2341 struct record_videocontroller *rec;
2342 HRESULT hr;
2343 IDXGIFactory *factory = NULL;
2344 IDXGIAdapter *adapter = NULL;
2345 DXGI_ADAPTER_DESC desc;
2346 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2347 const WCHAR *name = videocontroller_deviceidW;
2348 enum fill_status status = FILL_STATUS_UNFILTERED;
2349 UINT row = 0;
2351 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2353 memset (&desc, 0, sizeof(desc));
2354 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2355 if (FAILED(hr)) goto done;
2357 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2358 if (FAILED(hr)) goto done;
2360 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2361 if (SUCCEEDED(hr))
2363 vidmem = desc.DedicatedVideoMemory;
2364 name = desc.Description;
2367 done:
2368 rec = (struct record_videocontroller *)table->data;
2369 rec->adapter_dactype = videocontroller_dactypeW;
2370 rec->adapter_ram = vidmem;
2371 rec->availability = 3; /* Running or Full Power */
2372 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2373 rec->current_horizontalres = hres;
2374 rec->current_verticalres = vres;
2375 rec->description = heap_strdupW( name );
2376 rec->device_id = videocontroller_deviceidW;
2377 rec->name = heap_strdupW( name );
2378 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2379 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2380 else row++;
2382 TRACE("created %u rows\n", row);
2383 table->num_rows = row;
2385 if (adapter) IDXGIAdapter_Release( adapter );
2386 if (factory) IDXGIFactory_Release( factory );
2387 return status;
2390 static struct table builtin_classes[] =
2392 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2393 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2394 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2395 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2396 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2397 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2398 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
2399 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2400 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2401 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2402 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2403 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2404 fill_networkadapterconfig },
2405 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2406 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2407 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2408 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
2409 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2410 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2411 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2412 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2413 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2414 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2415 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2418 void init_table_list( void )
2420 static struct list tables = LIST_INIT( tables );
2421 UINT i;
2423 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2424 table_list = &tables;