wbemprox: Add a partial implementation of CIM_Processor.
[wine/wine-gecko.git] / dlls / wbemprox / builtin.c
blobea542139ebf5579d6a18991abc1ea8edbd82c9d5
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_processor2W[] =
88 {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
89 static const WCHAR class_sounddeviceW[] =
90 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
91 static const WCHAR class_videocontrollerW[] =
92 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
94 static const WCHAR prop_acceptpauseW[] =
95 {'A','c','c','e','p','t','P','a','u','s','e',0};
96 static const WCHAR prop_acceptstopW[] =
97 {'A','c','c','e','p','t','S','t','o','p',0};
98 static const WCHAR prop_accessmaskW[] =
99 {'A','c','c','e','s','s','M','a','s','k',0};
100 static const WCHAR prop_adapterdactypeW[] =
101 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
102 static const WCHAR prop_adapterramW[] =
103 {'A','d','a','p','t','e','r','R','A','M',0};
104 static const WCHAR prop_adaptertypeW[] =
105 {'A','d','a','p','t','e','r','T','y','p','e',0};
106 static const WCHAR prop_addresswidthW[] =
107 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
108 static const WCHAR prop_availabilityW[] =
109 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
110 static const WCHAR prop_bootableW[] =
111 {'B','o','o','t','a','b','l','e',0};
112 static const WCHAR prop_bootpartitionW[] =
113 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
114 static const WCHAR prop_buildnumberW[] =
115 {'B','u','i','l','d','N','u','m','b','e','r',0};
116 static const WCHAR prop_capacityW[] =
117 {'C','a','p','a','c','i','t','y',0};
118 static const WCHAR prop_captionW[] =
119 {'C','a','p','t','i','o','n',0};
120 static const WCHAR prop_classW[] =
121 {'C','l','a','s','s',0};
122 static const WCHAR prop_codesetW[] =
123 {'C','o','d','e','S','e','t',0};
124 static const WCHAR prop_commandlineW[] =
125 {'C','o','m','m','a','n','d','L','i','n','e',0};
126 static const WCHAR prop_countrycodeW[] =
127 {'C','o','u','n','t','r','y','C','o','d','e',0};
128 static const WCHAR prop_cpustatusW[] =
129 {'C','p','u','S','t','a','t','u','s',0};
130 static const WCHAR prop_csdversionW[] =
131 {'C','S','D','V','e','r','s','i','o','n',0};
132 static const WCHAR prop_currentbitsperpixelW[] =
133 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
134 static const WCHAR prop_currentclockspeedW[] =
135 {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
136 static const WCHAR prop_currenthorizontalresW[] =
137 {'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};
138 static const WCHAR prop_currentverticalresW[] =
139 {'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};
140 static const WCHAR prop_defaultvalueW[] =
141 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
142 static const WCHAR prop_descriptionW[] =
143 {'D','e','s','c','r','i','p','t','i','o','n',0};
144 static const WCHAR prop_deviceidW[] =
145 {'D','e','v','i','c','e','I','d',0};
146 static const WCHAR prop_directionW[] =
147 {'D','i','r','e','c','t','i','o','n',0};
148 static const WCHAR prop_displaynameW[] =
149 {'D','i','s','p','l','a','y','N','a','m','e',0};
150 static const WCHAR prop_diskindexW[] =
151 {'D','i','s','k','I','n','d','e','x',0};
152 static const WCHAR prop_domainW[] =
153 {'D','o','m','a','i','n',0};
154 static const WCHAR prop_domainroleW[] =
155 {'D','o','m','a','i','n','R','o','l','e',0};
156 static const WCHAR prop_driveW[] =
157 {'D','r','i','v','e',0};
158 static const WCHAR prop_drivetypeW[] =
159 {'D','r','i','v','e','T','y','p','e',0};
160 static const WCHAR prop_familyW[] =
161 {'F','a','m','i','l','y',0};
162 static const WCHAR prop_filesystemW[] =
163 {'F','i','l','e','S','y','s','t','e','m',0};
164 static const WCHAR prop_flavorW[] =
165 {'F','l','a','v','o','r',0};
166 static const WCHAR prop_freespaceW[] =
167 {'F','r','e','e','S','p','a','c','e',0};
168 static const WCHAR prop_handleW[] =
169 {'H','a','n','d','l','e',0};
170 static const WCHAR prop_idW[] =
171 {'I','D',0};
172 static const WCHAR prop_identificationcodeW[] =
173 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
174 static const WCHAR prop_indexW[] =
175 {'I','n','d','e','x',0};
176 static const WCHAR prop_installdateW[] =
177 {'I','n','s','t','a','l','l','D','a','t','e',0};
178 static const WCHAR prop_interfaceindexW[] =
179 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
180 static const WCHAR prop_interfacetypeW[] =
181 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
182 static const WCHAR prop_intvalueW[] =
183 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
184 static const WCHAR prop_ipconnectionmetricW[] =
185 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
186 static const WCHAR prop_ipenabledW[] =
187 {'I','P','E','n','a','b','l','e','d',0};
188 static const WCHAR prop_lastbootuptimeW[] =
189 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
190 static const WCHAR prop_localdatetimeW[] =
191 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
192 static const WCHAR prop_localeW[] =
193 {'L','o','c','a','l','e',0};
194 static const WCHAR prop_macaddressW[] =
195 {'M','A','C','A','d','d','r','e','s','s',0};
196 static const WCHAR prop_manufacturerW[] =
197 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
198 static const WCHAR prop_maxclockspeedW[] =
199 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
200 static const WCHAR prop_mediatypeW[] =
201 {'M','e','d','i','a','T','y','p','e',0};
202 static const WCHAR prop_memberW[] =
203 {'M','e','m','b','e','r',0};
204 static const WCHAR prop_methodW[] =
205 {'M','e','t','h','o','d',0};
206 static const WCHAR prop_modelW[] =
207 {'M','o','d','e','l',0};
208 static const WCHAR prop_netconnectionstatusW[] =
209 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
210 static const WCHAR prop_numcoresW[] =
211 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
212 static const WCHAR prop_numlogicalprocessorsW[] =
213 {'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};
214 static const WCHAR prop_numprocessorsW[] =
215 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
216 static const WCHAR prop_osarchitectureW[] =
217 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
218 static const WCHAR prop_oslanguageW[] =
219 {'O','S','L','a','n','g','u','a','g','e',0};
220 static const WCHAR prop_osproductsuiteW[] =
221 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
222 static const WCHAR prop_ostypeW[] =
223 {'O','S','T','y','p','e',0};
224 static const WCHAR prop_parameterW[] =
225 {'P','a','r','a','m','e','t','e','r',0};
226 static const WCHAR prop_physicaladapterW[] =
227 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
228 static const WCHAR prop_pnpdeviceidW[] =
229 {'P','N','P','D','e','v','i','c','e','I','D',0};
230 static const WCHAR prop_pprocessidW[] =
231 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
232 static const WCHAR prop_processidW[] =
233 {'P','r','o','c','e','s','s','I','D',0};
234 static const WCHAR prop_processoridW[] =
235 {'P','r','o','c','e','s','s','o','r','I','d',0};
236 static const WCHAR prop_productnameW[] =
237 {'P','r','o','d','u','c','t','N','a','m','e',0};
238 static const WCHAR prop_releasedateW[] =
239 {'R','e','l','e','a','s','e','D','a','t','e',0};
240 static const WCHAR prop_serialnumberW[] =
241 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
242 static const WCHAR prop_servicepackmajorW[] =
243 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
244 static const WCHAR prop_servicepackminorW[] =
245 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
246 static const WCHAR prop_servicetypeW[] =
247 {'S','e','r','v','i','c','e','T','y','p','e',0};
248 static const WCHAR prop_smbiosbiosversionW[] =
249 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
250 static const WCHAR prop_startmodeW[] =
251 {'S','t','a','r','t','M','o','d','e',0};
252 static const WCHAR prop_sizeW[] =
253 {'S','i','z','e',0};
254 static const WCHAR prop_speedW[] =
255 {'S','p','e','e','d',0};
256 static const WCHAR prop_startingoffsetW[] =
257 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
258 static const WCHAR prop_stateW[] =
259 {'S','t','a','t','e',0};
260 static const WCHAR prop_strvalueW[] =
261 {'S','t','r','i','n','g','V','a','l','u','e',0};
262 static const WCHAR prop_suitemaskW[] =
263 {'S','u','i','t','e','M','a','s','k',0};
264 static const WCHAR prop_systemdirectoryW[] =
265 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
266 static const WCHAR prop_systemnameW[] =
267 {'S','y','s','t','e','m','N','a','m','e',0};
268 static const WCHAR prop_tagW[] =
269 {'T','a','g',0};
270 static const WCHAR prop_threadcountW[] =
271 {'T','h','r','e','a','d','C','o','u','n','t',0};
272 static const WCHAR prop_totalphysicalmemoryW[] =
273 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
274 static const WCHAR prop_typeW[] =
275 {'T','y','p','e',0};
276 static const WCHAR prop_uniqueidW[] =
277 {'U','n','i','q','u','e','I','d',0};
278 static const WCHAR prop_varianttypeW[] =
279 {'V','a','r','i','a','n','t','T','y','p','e',0};
280 static const WCHAR prop_versionW[] =
281 {'V','e','r','s','i','o','n',0};
282 static const WCHAR prop_volumeserialnumberW[] =
283 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
285 /* column definitions must be kept in sync with record structures below */
286 static const struct column col_baseboard[] =
288 { prop_manufacturerW, CIM_STRING },
289 { prop_modelW, CIM_STRING },
290 { prop_nameW, CIM_STRING },
291 { prop_serialnumberW, CIM_STRING },
292 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
294 static const struct column col_bios[] =
296 { prop_descriptionW, CIM_STRING },
297 { prop_identificationcodeW, CIM_STRING },
298 { prop_manufacturerW, CIM_STRING },
299 { prop_releasedateW, CIM_DATETIME },
300 { prop_serialnumberW, CIM_STRING },
301 { prop_smbiosbiosversionW, CIM_STRING },
302 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
304 static const struct column col_cdromdrive[] =
306 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
307 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
308 { prop_mediatypeW, CIM_STRING },
309 { prop_nameW, CIM_STRING },
310 { prop_pnpdeviceidW, CIM_STRING }
312 static const struct column col_compsys[] =
314 { prop_descriptionW, CIM_STRING },
315 { prop_domainW, CIM_STRING },
316 { prop_domainroleW, CIM_UINT16 },
317 { prop_manufacturerW, CIM_STRING },
318 { prop_modelW, CIM_STRING },
319 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
320 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
321 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
322 { prop_totalphysicalmemoryW, CIM_UINT64 }
324 static const struct column col_datafile[] =
326 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
327 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
329 static const struct column col_directory[] =
331 { prop_accessmaskW, CIM_UINT32 },
332 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
334 static const struct column col_diskdrive[] =
336 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
337 { prop_indexW, CIM_UINT32, VT_I4 },
338 { prop_interfacetypeW, CIM_STRING },
339 { prop_manufacturerW, CIM_STRING },
340 { prop_mediatypeW, CIM_STRING },
341 { prop_modelW, CIM_STRING },
342 { prop_serialnumberW, CIM_STRING },
343 { prop_sizeW, CIM_UINT64 }
345 static const struct column col_diskpartition[] =
347 { prop_bootableW, CIM_BOOLEAN },
348 { prop_bootpartitionW, CIM_BOOLEAN },
349 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
350 { prop_diskindexW, CIM_UINT32, VT_I4 },
351 { prop_indexW, CIM_UINT32, VT_I4 },
352 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
353 { prop_sizeW, CIM_UINT64 },
354 { prop_startingoffsetW, CIM_UINT64 },
355 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
357 static const struct column col_logicaldisk[] =
359 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
360 { prop_drivetypeW, CIM_UINT32, VT_I4 },
361 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
362 { prop_freespaceW, CIM_UINT64 },
363 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
364 { prop_sizeW, CIM_UINT64 },
365 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
367 static const struct column col_networkadapter[] =
369 { prop_adaptertypeW, CIM_STRING },
370 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
371 { prop_indexW, CIM_UINT32, VT_I4 },
372 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
373 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
374 { prop_manufacturerW, CIM_STRING },
375 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
376 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
377 { prop_physicaladapterW, CIM_BOOLEAN },
378 { prop_pnpdeviceidW, CIM_STRING },
379 { prop_speedW, CIM_UINT64 }
381 static const struct column col_networkadapterconfig[] =
383 { prop_indexW, CIM_UINT32|COL_FLAG_KEY },
384 { prop_ipconnectionmetricW, CIM_UINT32 },
385 { prop_ipenabledW, CIM_BOOLEAN },
386 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
388 static const struct column col_os[] =
390 { prop_buildnumberW, CIM_STRING },
391 { prop_captionW, CIM_STRING },
392 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
393 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
394 { prop_csdversionW, CIM_STRING },
395 { prop_installdateW, CIM_DATETIME },
396 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
397 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
398 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
399 { prop_nameW, CIM_STRING },
400 { prop_osarchitectureW, CIM_STRING },
401 { prop_oslanguageW, CIM_UINT32, VT_I4 },
402 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
403 { prop_ostypeW, CIM_UINT16, VT_I4 },
404 { prop_serialnumberW, CIM_STRING },
405 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
406 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
407 { prop_suitemaskW, CIM_UINT32, VT_I4 },
408 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
409 { prop_versionW, CIM_STRING }
411 static const struct column col_param[] =
413 { prop_classW, CIM_STRING },
414 { prop_methodW, CIM_STRING },
415 { prop_directionW, CIM_SINT32 },
416 { prop_parameterW, CIM_STRING },
417 { prop_typeW, CIM_UINT32 },
418 { prop_varianttypeW, CIM_UINT32 },
419 { prop_defaultvalueW, CIM_UINT32 }
421 static const struct column col_physicalmedia[] =
423 { prop_serialnumberW, CIM_STRING },
424 { prop_tagW, CIM_STRING }
426 static const struct column col_physicalmemory[] =
428 { prop_capacityW, CIM_UINT64 }
430 static const struct column col_process[] =
432 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
433 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
434 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
435 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
436 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
437 { prop_pprocessidW, CIM_UINT32, VT_I4 },
438 { prop_processidW, CIM_UINT32, VT_I4 },
439 { prop_threadcountW, CIM_UINT32, VT_I4 },
440 /* methods */
441 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
443 static const struct column col_processor[] =
445 { prop_addresswidthW, CIM_UINT16, VT_I4 },
446 { prop_cpustatusW, CIM_UINT16 },
447 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
448 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
449 { prop_familyW, CIM_UINT16, VT_I4 },
450 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
451 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
452 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
453 { prop_numcoresW, CIM_UINT32, VT_I4 },
454 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
455 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
456 { prop_uniqueidW, CIM_STRING }
458 static const struct column col_qualifier[] =
460 { prop_classW, CIM_STRING },
461 { prop_memberW, CIM_STRING },
462 { prop_typeW, CIM_UINT32 },
463 { prop_flavorW, CIM_SINT32 },
464 { prop_nameW, CIM_STRING },
465 { prop_intvalueW, CIM_SINT32 },
466 { prop_strvalueW, CIM_STRING }
468 static const struct column col_service[] =
470 { prop_acceptpauseW, CIM_BOOLEAN },
471 { prop_acceptstopW, CIM_BOOLEAN },
472 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
473 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
474 { prop_processidW, CIM_UINT32 },
475 { prop_servicetypeW, CIM_STRING },
476 { prop_startmodeW, CIM_STRING },
477 { prop_stateW, CIM_STRING },
478 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
479 /* methods */
480 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
481 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
482 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
483 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
485 static const struct column col_sounddevice[] =
487 { prop_nameW, CIM_STRING },
488 { prop_productnameW, CIM_STRING }
490 static const struct column col_stdregprov[] =
492 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
493 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
494 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
496 static const struct column col_videocontroller[] =
498 { prop_adapterdactypeW, CIM_STRING },
499 { prop_adapterramW, CIM_UINT32, VT_I4 },
500 { prop_availabilityW, CIM_UINT16 },
501 { prop_currentbitsperpixelW, CIM_UINT32 },
502 { prop_currenthorizontalresW, CIM_UINT32 },
503 { prop_currentverticalresW, CIM_UINT32 },
504 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
505 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
506 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
507 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
510 static const WCHAR baseboard_manufacturerW[] =
511 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
512 static const WCHAR baseboard_serialnumberW[] =
513 {'N','o','n','e',0};
514 static const WCHAR baseboard_tagW[] =
515 {'B','a','s','e',' ','B','o','a','r','d',0};
516 static const WCHAR bios_descriptionW[] =
517 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
518 static const WCHAR bios_manufacturerW[] =
519 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
520 static const WCHAR bios_releasedateW[] =
521 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
522 static const WCHAR bios_serialnumberW[] =
523 {'0',0};
524 static const WCHAR bios_smbiosbiosversionW[] =
525 {'W','i','n','e',0};
526 static const WCHAR bios_versionW[] =
527 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
528 static const WCHAR cdromdrive_mediatypeW[] =
529 {'C','D','-','R','O','M',0};
530 static const WCHAR cdromdrive_nameW[] =
531 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
532 static const WCHAR cdromdrive_pnpdeviceidW[]=
533 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
534 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
535 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
536 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
537 static const WCHAR compsys_descriptionW[] =
538 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
539 static const WCHAR compsys_domainW[] =
540 {'W','O','R','K','G','R','O','U','P',0};
541 static const WCHAR compsys_manufacturerW[] =
542 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
543 static const WCHAR compsys_modelW[] =
544 {'W','i','n','e',0};
545 static const WCHAR diskdrive_interfacetypeW[] =
546 {'I','D','E',0};
547 static const WCHAR diskdrive_manufacturerW[] =
548 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
549 static const WCHAR diskdrive_mediatype_fixedW[] =
550 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
551 static const WCHAR diskdrive_mediatype_removableW[] =
552 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
553 static const WCHAR diskdrive_modelW[] =
554 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
555 static const WCHAR diskdrive_serialW[] =
556 {'W','I','N','E','H','D','I','S','K',0};
557 static const WCHAR networkadapter_pnpdeviceidW[]=
558 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
559 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
560 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
561 static const WCHAR os_32bitW[] =
562 {'3','2','-','b','i','t',0};
563 static const WCHAR os_64bitW[] =
564 {'6','4','-','b','i','t',0};
565 static const WCHAR os_buildnumberW[] =
566 {'2','6','0','0',0};
567 static const WCHAR os_captionW[] =
568 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
569 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
570 static const WCHAR os_csdversionW[] =
571 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
572 static const WCHAR os_installdateW[] =
573 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
574 static const WCHAR os_nameW[] =
575 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
576 'P','r','o','f','e','s','s','i','o','n','a','l','|','C',':','\\','W','I','N','D','O','W','S',
577 '|','\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','0',
578 '\\','P','a','r','t','i','t','i','o','n','1',0};
579 static const WCHAR os_serialnumberW[] =
580 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
581 static const WCHAR os_versionW[] =
582 {'5','.','1','.','2','6','0','0',0};
583 static const WCHAR physicalmedia_tagW[] =
584 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
585 static const WCHAR sounddevice_productnameW[] =
586 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
587 static const WCHAR videocontroller_dactypeW[] =
588 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
589 static const WCHAR videocontroller_deviceidW[] =
590 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
592 #include "pshpack1.h"
593 struct record_baseboard
595 const WCHAR *manufacturer;
596 const WCHAR *model;
597 const WCHAR *name;
598 const WCHAR *serialnumber;
599 const WCHAR *tag;
601 struct record_bios
603 const WCHAR *description;
604 const WCHAR *identificationcode;
605 const WCHAR *manufacturer;
606 const WCHAR *releasedate;
607 const WCHAR *serialnumber;
608 const WCHAR *smbiosbiosversion;
609 const WCHAR *version;
611 struct record_cdromdrive
613 const WCHAR *device_id;
614 const WCHAR *drive;
615 const WCHAR *mediatype;
616 const WCHAR *name;
617 const WCHAR *pnpdevice_id;
619 struct record_computersystem
621 const WCHAR *description;
622 const WCHAR *domain;
623 UINT16 domainrole;
624 const WCHAR *manufacturer;
625 const WCHAR *model;
626 const WCHAR *name;
627 UINT32 num_logical_processors;
628 UINT32 num_processors;
629 UINT64 total_physical_memory;
631 struct record_datafile
633 const WCHAR *name;
634 const WCHAR *version;
636 struct record_directory
638 UINT32 accessmask;
639 const WCHAR *name;
641 struct record_diskdrive
643 const WCHAR *device_id;
644 UINT32 index;
645 const WCHAR *interfacetype;
646 const WCHAR *manufacturer;
647 const WCHAR *mediatype;
648 const WCHAR *model;
649 const WCHAR *serialnumber;
650 UINT64 size;
652 struct record_diskpartition
654 int bootable;
655 int bootpartition;
656 const WCHAR *device_id;
657 UINT32 diskindex;
658 UINT32 index;
659 const WCHAR *pnpdevice_id;
660 UINT64 size;
661 UINT64 startingoffset;
662 const WCHAR *type;
664 struct record_logicaldisk
666 const WCHAR *device_id;
667 UINT32 drivetype;
668 const WCHAR *filesystem;
669 UINT64 freespace;
670 const WCHAR *name;
671 UINT64 size;
672 const WCHAR *volumeserialnumber;
674 struct record_networkadapter
676 const WCHAR *adaptertype;
677 const WCHAR *device_id;
678 UINT32 index;
679 UINT32 interface_index;
680 const WCHAR *mac_address;
681 const WCHAR *manufacturer;
682 const WCHAR *name;
683 UINT16 netconnection_status;
684 int physicaladapter;
685 const WCHAR *pnpdevice_id;
686 UINT64 speed;
688 struct record_networkadapterconfig
690 UINT32 index;
691 UINT32 ipconnectionmetric;
692 int ipenabled;
693 const WCHAR *mac_address;
695 struct record_operatingsystem
697 const WCHAR *buildnumber;
698 const WCHAR *caption;
699 const WCHAR *codeset;
700 const WCHAR *countrycode;
701 const WCHAR *csdversion;
702 const WCHAR *installdate;
703 const WCHAR *lastbootuptime;
704 const WCHAR *localdatetime;
705 const WCHAR *locale;
706 const WCHAR *name;
707 const WCHAR *osarchitecture;
708 UINT32 oslanguage;
709 UINT32 osproductsuite;
710 UINT16 ostype;
711 const WCHAR *serialnumber;
712 UINT16 servicepackmajor;
713 UINT16 servicepackminor;
714 UINT32 suitemask;
715 const WCHAR *systemdirectory;
716 const WCHAR *version;
718 struct record_param
720 const WCHAR *class;
721 const WCHAR *method;
722 INT32 direction;
723 const WCHAR *parameter;
724 UINT32 type;
725 UINT32 varianttype;
726 UINT32 defaultvalue;
728 struct record_physicalmedia
730 const WCHAR *serialnumber;
731 const WCHAR *tag;
733 struct record_physicalmemory
735 UINT64 capacity;
737 struct record_process
739 const WCHAR *caption;
740 const WCHAR *commandline;
741 const WCHAR *description;
742 const WCHAR *handle;
743 const WCHAR *name;
744 UINT32 pprocess_id;
745 UINT32 process_id;
746 UINT32 thread_count;
747 /* methods */
748 class_method *get_owner;
750 struct record_processor
752 UINT16 addresswidth;
753 UINT16 cpu_status;
754 UINT32 currentclockspeed;
755 const WCHAR *device_id;
756 UINT16 family;
757 const WCHAR *manufacturer;
758 UINT32 maxclockspeed;
759 const WCHAR *name;
760 UINT32 num_cores;
761 UINT32 num_logical_processors;
762 const WCHAR *processor_id;
763 const WCHAR *unique_id;
765 struct record_qualifier
767 const WCHAR *class;
768 const WCHAR *member;
769 UINT32 type;
770 INT32 flavor;
771 const WCHAR *name;
772 INT32 intvalue;
773 const WCHAR *strvalue;
775 struct record_service
777 int accept_pause;
778 int accept_stop;
779 const WCHAR *displayname;
780 const WCHAR *name;
781 UINT32 process_id;
782 const WCHAR *servicetype;
783 const WCHAR *startmode;
784 const WCHAR *state;
785 const WCHAR *systemname;
786 /* methods */
787 class_method *pause_service;
788 class_method *resume_service;
789 class_method *start_service;
790 class_method *stop_service;
792 struct record_sounddevice
794 const WCHAR *name;
795 const WCHAR *productname;
797 struct record_stdregprov
799 class_method *enumkey;
800 class_method *enumvalues;
801 class_method *getstringvalue;
803 struct record_videocontroller
805 const WCHAR *adapter_dactype;
806 UINT32 adapter_ram;
807 UINT16 availability;
808 UINT32 current_bitsperpixel;
809 UINT32 current_horizontalres;
810 UINT32 current_verticalres;
811 const WCHAR *description;
812 const WCHAR *device_id;
813 const WCHAR *name;
814 const WCHAR *pnpdevice_id;
816 #include "poppack.h"
818 static const struct record_baseboard data_baseboard[] =
820 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
822 static const struct record_bios data_bios[] =
824 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
825 bios_smbiosbiosversionW, bios_versionW }
827 static const struct record_param data_param[] =
829 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
830 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
831 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
832 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
833 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
834 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
835 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
836 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
837 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
838 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
839 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
840 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
841 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
842 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
843 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
844 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
845 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
846 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
847 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
848 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
849 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
852 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
853 WBEM_FLAVOR_ORIGIN_PROPAGATED)
855 static const struct record_physicalmedia data_physicalmedia[] =
857 { diskdrive_serialW, physicalmedia_tagW }
859 static const struct record_qualifier data_qualifier[] =
861 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
862 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
864 static const struct record_sounddevice data_sounddevice[] =
866 { sounddevice_productnameW, sounddevice_productnameW }
868 static const struct record_stdregprov data_stdregprov[] =
870 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
873 /* check if row matches condition and update status */
874 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
876 LONGLONG val;
877 UINT type;
879 if (!cond)
881 *status = FILL_STATUS_UNFILTERED;
882 return TRUE;
884 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
886 *status = FILL_STATUS_FAILED;
887 return FALSE;
889 *status = FILL_STATUS_FILTERED;
890 return val != 0;
893 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
895 if (!table->num_rows_allocated)
897 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
898 table->num_rows_allocated = row_count;
899 return TRUE;
901 if (row_count >= table->num_rows_allocated)
903 BYTE *data;
904 UINT count = table->num_rows_allocated * 2;
905 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
906 table->data = data;
907 table->num_rows_allocated = count;
909 return TRUE;
912 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
914 static const WCHAR fmtW[] = {'%','c',':',0};
915 WCHAR drive[3], root[] = {'A',':','\\',0};
916 struct record_cdromdrive *rec;
917 UINT i, row = 0, offset = 0;
918 DWORD drives = GetLogicalDrives();
919 enum fill_status status = FILL_STATUS_UNFILTERED;
921 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
923 for (i = 0; i < sizeof(drives); i++)
925 if (drives & (1 << i))
927 root[0] = 'A' + i;
928 if (GetDriveTypeW( root ) != DRIVE_CDROM)
929 continue;
931 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
933 rec = (struct record_cdromdrive *)(table->data + offset);
934 rec->device_id = cdromdrive_pnpdeviceidW;
935 sprintfW( drive, fmtW, 'A' + i );
936 rec->drive = heap_strdupW( drive );
937 rec->mediatype = cdromdrive_mediatypeW;
938 rec->name = cdromdrive_nameW;
939 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
940 if (!match_row( table, row, cond, &status ))
942 free_row_values( table, row );
943 continue;
945 offset += sizeof(*rec);
946 row++;
949 TRACE("created %u rows\n", row);
950 table->num_rows = row;
951 return status;
954 static UINT get_processor_count(void)
956 SYSTEM_BASIC_INFORMATION info;
958 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
959 return info.NumberOfProcessors;
962 static UINT get_logical_processor_count( UINT *num_cores )
964 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
965 UINT i, j, count = 0;
966 NTSTATUS status;
967 ULONG len;
969 if (num_cores) *num_cores = get_processor_count();
970 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
971 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
973 if (!(info = heap_alloc( len ))) return get_processor_count();
974 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
975 if (status != STATUS_SUCCESS)
977 heap_free( info );
978 return get_processor_count();
980 if (num_cores) *num_cores = 0;
981 for (i = 0; i < len / sizeof(*info); i++)
983 if (info[i].Relationship == RelationProcessorCore)
985 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
987 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
989 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
992 heap_free( info );
993 return count;
996 static UINT64 get_total_physical_memory(void)
998 MEMORYSTATUSEX status;
1000 status.dwLength = sizeof(status);
1001 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1002 return status.ullTotalPhys;
1005 static WCHAR *get_computername(void)
1007 WCHAR *ret;
1008 DWORD size = MAX_COMPUTERNAME_LENGTH;
1010 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1011 GetComputerNameW( ret, &size );
1012 return ret;
1015 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1017 struct record_computersystem *rec;
1018 enum fill_status status = FILL_STATUS_UNFILTERED;
1019 UINT row = 0;
1021 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1023 rec = (struct record_computersystem *)table->data;
1024 rec->description = compsys_descriptionW;
1025 rec->domain = compsys_domainW;
1026 rec->domainrole = 0; /* standalone workstation */
1027 rec->manufacturer = compsys_manufacturerW;
1028 rec->model = compsys_modelW;
1029 rec->name = get_computername();
1030 rec->num_logical_processors = get_logical_processor_count( NULL );
1031 rec->num_processors = get_processor_count();
1032 rec->total_physical_memory = get_total_physical_memory();
1033 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1034 else row++;
1036 TRACE("created %u rows\n", row);
1037 table->num_rows = row;
1038 return status;
1041 struct dirstack
1043 WCHAR **dirs;
1044 UINT *len_dirs;
1045 UINT num_dirs;
1046 UINT num_allocated;
1049 static struct dirstack *alloc_dirstack( UINT size )
1051 struct dirstack *dirstack;
1053 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1054 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1056 heap_free( dirstack );
1057 return NULL;
1059 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1061 heap_free( dirstack->dirs );
1062 heap_free( dirstack );
1063 return NULL;
1065 dirstack->num_dirs = 0;
1066 dirstack->num_allocated = size;
1067 return dirstack;
1070 static void clear_dirstack( struct dirstack *dirstack )
1072 UINT i;
1073 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1074 dirstack->num_dirs = 0;
1077 static void free_dirstack( struct dirstack *dirstack )
1079 clear_dirstack( dirstack );
1080 heap_free( dirstack->dirs );
1081 heap_free( dirstack->len_dirs );
1082 heap_free( dirstack );
1085 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1087 UINT size, i = dirstack->num_dirs;
1089 if (!dir) return FALSE;
1091 if (i == dirstack->num_allocated)
1093 WCHAR **tmp;
1094 UINT *len_tmp;
1096 size = dirstack->num_allocated * 2;
1097 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1098 dirstack->dirs = tmp;
1099 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1100 dirstack->len_dirs = len_tmp;
1101 dirstack->num_allocated = size;
1103 dirstack->dirs[i] = dir;
1104 dirstack->len_dirs[i] = len;
1105 dirstack->num_dirs++;
1106 return TRUE;
1109 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1111 if (!dirstack->num_dirs)
1113 *len = 0;
1114 return NULL;
1116 dirstack->num_dirs--;
1117 *len = dirstack->len_dirs[dirstack->num_dirs];
1118 return dirstack->dirs[dirstack->num_dirs];
1121 static const WCHAR *peek_dir( struct dirstack *dirstack )
1123 if (!dirstack->num_dirs) return NULL;
1124 return dirstack->dirs[dirstack->num_dirs - 1];
1127 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1129 UINT i = 0;
1130 WCHAR *ret;
1132 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1133 ret[i++] = drive;
1134 ret[i++] = ':';
1135 ret[i++] = '\\';
1136 if (path && len)
1138 memcpy( ret + i, path, len * sizeof(WCHAR) );
1139 i += len;
1140 ret[i++] = '\\';
1142 ret[i++] = '*';
1143 ret[i] = 0;
1144 return ret;
1147 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1149 UINT i = 0, len = 0;
1150 const WCHAR *p;
1151 WCHAR *ret;
1153 for (p = path; *p; p++)
1155 if (*p == '\\') len += 2;
1156 else len++;
1158 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1159 ret[i++] = drive;
1160 ret[i++] = ':';
1161 ret[i++] = '\\';
1162 ret[i++] = '\\';
1163 for (p = path; *p; p++)
1165 if (*p != '\\') ret[i++] = *p;
1166 else
1168 ret[i++] = '\\';
1169 ret[i++] = '\\';
1172 ret[i] = 0;
1173 return ret;
1176 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1178 const WCHAR *p = path, *start;
1179 UINT len, i;
1180 WCHAR *ret;
1182 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1183 start = path + 4;
1184 len = strlenW( start );
1185 p = start + len - 1;
1186 if (*p == '\\') return NULL;
1188 while (p >= start && *p != '\\') { len--; p--; };
1189 while (p >= start && *p == '\\') { len--; p--; };
1191 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1192 for (i = 0, p = start; p < start + len; p++)
1194 if (p[0] == '\\' && p[1] == '\\')
1196 ret[i++] = '\\';
1197 p++;
1199 else ret[i++] = *p;
1201 ret[i] = 0;
1202 *ret_len = i;
1203 return ret;
1206 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1208 UINT i;
1209 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1210 return FALSE;
1213 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1214 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1216 const struct expr *left, *right;
1218 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1220 left = cond->u.expr.left;
1221 right = cond->u.expr.right;
1222 if (cond->u.expr.op == OP_EQ)
1224 UINT len;
1225 WCHAR *path;
1226 const WCHAR *str = NULL;
1228 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1229 !strcmpW( left->u.propval->name, prop_nameW ) &&
1230 toupperW( right->u.sval[0] ) == toupperW( root ))
1232 str = right->u.sval;
1234 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1235 !strcmpW( right->u.propval->name, prop_nameW ) &&
1236 toupperW( left->u.sval[0] ) == toupperW( root ))
1238 str = left->u.sval;
1240 if (str && (path = build_dirname( str, &len )))
1242 if (seen_dir( dirstack, path ))
1244 heap_free( path );
1245 return ++*count;
1247 else if (push_dir( dirstack, path, len )) return ++*count;
1248 heap_free( path );
1249 return *count = 0;
1252 else if (cond->u.expr.op == OP_OR)
1254 UINT left_count = 0, right_count = 0;
1256 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1257 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1258 return *count += left_count + right_count;
1260 return *count = 0;
1263 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1265 UINT len_path = 0, len_segment = strlenW( segment );
1266 WCHAR *ret;
1268 *len = 0;
1269 if (path) len_path = strlenW( path );
1270 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1271 if (path && len_path)
1273 memcpy( ret, path, len_path * sizeof(WCHAR) );
1274 ret[len_path] = '\\';
1275 *len += len_path + 1;
1277 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1278 *len += len_segment;
1279 ret[*len] = 0;
1280 return ret;
1283 static WCHAR *get_file_version( const WCHAR *filename )
1285 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1286 VS_FIXEDFILEINFO *info;
1287 DWORD size;
1288 void *block;
1289 WCHAR *ret;
1291 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1292 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1294 heap_free( ret );
1295 return NULL;
1297 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1298 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1300 heap_free( block );
1301 heap_free( ret );
1302 return NULL;
1304 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1305 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1306 heap_free( block );
1307 return ret;
1310 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1312 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1313 struct record_datafile *rec;
1314 UINT i, len, row = 0, offset = 0, num_expected_rows;
1315 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1316 DWORD drives = GetLogicalDrives();
1317 WIN32_FIND_DATAW data;
1318 HANDLE handle;
1319 struct dirstack *dirstack;
1320 enum fill_status status = FILL_STATUS_UNFILTERED;
1322 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1324 dirstack = alloc_dirstack(2);
1326 for (i = 0; i < sizeof(drives); i++)
1328 if (!(drives & (1 << i))) continue;
1330 root[0] = 'A' + i;
1331 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1333 num_expected_rows = 0;
1334 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1336 for (;;)
1338 path = pop_dir( dirstack, &len );
1339 if (!(glob = build_glob( root[0], path, len )))
1341 status = FILL_STATUS_FAILED;
1342 goto done;
1344 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1348 if (!resize_table( table, row + 1, sizeof(*rec) ))
1350 status = FILL_STATUS_FAILED;
1351 FindClose( handle );
1352 goto done;
1354 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1355 new_path = append_path( path, data.cFileName, &len );
1357 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1359 if (push_dir( dirstack, new_path, len )) continue;
1360 heap_free( new_path );
1361 FindClose( handle );
1362 status = FILL_STATUS_FAILED;
1363 goto done;
1365 rec = (struct record_datafile *)(table->data + offset);
1366 rec->name = build_name( root[0], new_path );
1367 rec->version = get_file_version( rec->name );
1368 if (!match_row( table, row, cond, &status ))
1370 free_row_values( table, row );
1371 continue;
1373 else if (num_expected_rows && row == num_expected_rows - 1)
1375 row++;
1376 FindClose( handle );
1377 status = FILL_STATUS_FILTERED;
1378 goto done;
1380 offset += sizeof(*rec);
1381 row++;
1383 while (FindNextFileW( handle, &data ));
1384 FindClose( handle );
1386 if (!peek_dir( dirstack )) break;
1387 heap_free( glob );
1388 heap_free( path );
1392 done:
1393 free_dirstack( dirstack );
1394 heap_free( glob );
1395 heap_free( path );
1397 TRACE("created %u rows\n", row);
1398 table->num_rows = row;
1399 return status;
1402 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1404 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1405 struct record_directory *rec;
1406 UINT i, len, row = 0, offset = 0, num_expected_rows;
1407 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1408 DWORD drives = GetLogicalDrives();
1409 WIN32_FIND_DATAW data;
1410 HANDLE handle;
1411 struct dirstack *dirstack;
1412 enum fill_status status = FILL_STATUS_UNFILTERED;
1414 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1416 dirstack = alloc_dirstack(2);
1418 for (i = 0; i < sizeof(drives); i++)
1420 if (!(drives & (1 << i))) continue;
1422 root[0] = 'A' + i;
1423 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1425 num_expected_rows = 0;
1426 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1428 for (;;)
1430 path = pop_dir( dirstack, &len );
1431 if (!(glob = build_glob( root[0], path, len )))
1433 status = FILL_STATUS_FAILED;
1434 goto done;
1436 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1440 if (!resize_table( table, row + 1, sizeof(*rec) ))
1442 FindClose( handle );
1443 status = FILL_STATUS_FAILED;
1444 goto done;
1446 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1447 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1448 continue;
1450 new_path = append_path( path, data.cFileName, &len );
1451 if (!(push_dir( dirstack, new_path, len )))
1453 heap_free( new_path );
1454 FindClose( handle );
1455 status = FILL_STATUS_FAILED;
1456 goto done;
1458 rec = (struct record_directory *)(table->data + offset);
1459 rec->accessmask = FILE_ALL_ACCESS;
1460 rec->name = build_name( root[0], new_path );
1461 if (!match_row( table, row, cond, &status ))
1463 free_row_values( table, row );
1464 continue;
1466 else if (num_expected_rows && row == num_expected_rows - 1)
1468 row++;
1469 FindClose( handle );
1470 status = FILL_STATUS_FILTERED;
1471 goto done;
1473 offset += sizeof(*rec);
1474 row++;
1476 while (FindNextFileW( handle, &data ));
1477 FindClose( handle );
1479 if (!peek_dir( dirstack )) break;
1480 heap_free( glob );
1481 heap_free( path );
1485 done:
1486 free_dirstack( dirstack );
1487 heap_free( glob );
1488 heap_free( path );
1490 TRACE("created %u rows\n", row);
1491 table->num_rows = row;
1492 return status;
1495 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1497 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1498 ULARGE_INTEGER free;
1499 DISK_GEOMETRY_EX info;
1500 HANDLE handle;
1502 free.QuadPart = 512 * 1024 * 1024;
1503 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1505 root[4] = dir[0];
1506 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1507 if (handle != INVALID_HANDLE_VALUE)
1509 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1510 *disksize = info.DiskSize.QuadPart;
1511 CloseHandle( handle );
1513 return free.QuadPart;
1516 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1518 static const WCHAR fmtW[] =
1519 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1520 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1521 struct record_diskdrive *rec;
1522 UINT i, row = 0, offset = 0, index = 0, type;
1523 UINT64 size = 1024 * 1024 * 1024;
1524 DWORD drives = GetLogicalDrives();
1525 enum fill_status status = FILL_STATUS_UNFILTERED;
1527 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1529 for (i = 0; i < sizeof(drives); i++)
1531 if (drives & (1 << i))
1533 root[0] = 'A' + i;
1534 type = GetDriveTypeW( root );
1535 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1536 continue;
1538 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1540 rec = (struct record_diskdrive *)(table->data + offset);
1541 sprintfW( device_id, fmtW, index );
1542 rec->device_id = heap_strdupW( device_id );
1543 rec->index = index;
1544 rec->interfacetype = diskdrive_interfacetypeW;
1545 rec->manufacturer = diskdrive_manufacturerW;
1546 if (type == DRIVE_FIXED)
1547 rec->mediatype = diskdrive_mediatype_fixedW;
1548 else
1549 rec->mediatype = diskdrive_mediatype_removableW;
1550 rec->model = diskdrive_modelW;
1551 rec->serialnumber = diskdrive_serialW;
1552 get_freespace( root, &size );
1553 rec->size = size;
1554 if (!match_row( table, row, cond, &status ))
1556 free_row_values( table, row );
1557 continue;
1559 offset += sizeof(*rec);
1560 index++;
1561 row++;
1564 TRACE("created %u rows\n", row);
1565 table->num_rows = row;
1566 return status;
1569 static WCHAR *get_filesystem( const WCHAR *root )
1571 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1572 WCHAR buffer[MAX_PATH + 1];
1574 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1575 return heap_strdupW( buffer );
1576 return heap_strdupW( ntfsW );
1579 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1581 static const WCHAR fmtW[] =
1582 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1583 WCHAR device_id[32], root[] = {'A',':','\\',0};
1584 struct record_diskpartition *rec;
1585 UINT i, row = 0, offset = 0, type, index = 0;
1586 UINT64 size = 1024 * 1024 * 1024;
1587 DWORD drives = GetLogicalDrives();
1588 enum fill_status status = FILL_STATUS_UNFILTERED;
1590 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1592 for (i = 0; i < sizeof(drives); i++)
1594 if (drives & (1 << i))
1596 root[0] = 'A' + i;
1597 type = GetDriveTypeW( root );
1598 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1599 continue;
1601 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1603 rec = (struct record_diskpartition *)(table->data + offset);
1604 rec->bootable = (i == 2) ? -1 : 0;
1605 rec->bootpartition = (i == 2) ? -1 : 0;
1606 sprintfW( device_id, fmtW, index );
1607 rec->device_id = heap_strdupW( device_id );
1608 rec->diskindex = index;
1609 rec->index = 0;
1610 rec->pnpdevice_id = heap_strdupW( device_id );
1611 get_freespace( root, &size );
1612 rec->size = size;
1613 rec->startingoffset = 0;
1614 rec->type = get_filesystem( root );
1615 if (!match_row( table, row, cond, &status ))
1617 free_row_values( table, row );
1618 continue;
1620 offset += sizeof(*rec);
1621 row++;
1622 index++;
1625 TRACE("created %u rows\n", row);
1626 table->num_rows = row;
1627 return status;
1630 static WCHAR *get_volumeserialnumber( const WCHAR *root )
1632 static const WCHAR fmtW[] = {'%','0','8','X',0};
1633 DWORD serial = 0;
1634 WCHAR buffer[9];
1636 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
1637 sprintfW( buffer, fmtW, serial );
1638 return heap_strdupW( buffer );
1641 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1643 static const WCHAR fmtW[] = {'%','c',':',0};
1644 WCHAR device_id[3], root[] = {'A',':','\\',0};
1645 struct record_logicaldisk *rec;
1646 UINT i, row = 0, offset = 0, type;
1647 UINT64 size = 1024 * 1024 * 1024;
1648 DWORD drives = GetLogicalDrives();
1649 enum fill_status status = FILL_STATUS_UNFILTERED;
1651 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1653 for (i = 0; i < sizeof(drives); i++)
1655 if (drives & (1 << i))
1657 root[0] = 'A' + i;
1658 type = GetDriveTypeW( root );
1659 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1660 continue;
1662 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1664 rec = (struct record_logicaldisk *)(table->data + offset);
1665 sprintfW( device_id, fmtW, 'A' + i );
1666 rec->device_id = heap_strdupW( device_id );
1667 rec->drivetype = type;
1668 rec->filesystem = get_filesystem( root );
1669 rec->freespace = get_freespace( root, &size );
1670 rec->name = heap_strdupW( device_id );
1671 rec->size = size;
1672 rec->volumeserialnumber = get_volumeserialnumber( root );
1673 if (!match_row( table, row, cond, &status ))
1675 free_row_values( table, row );
1676 continue;
1678 offset += sizeof(*rec);
1679 row++;
1682 TRACE("created %u rows\n", row);
1683 table->num_rows = row;
1684 return status;
1687 static UINT16 get_connection_status( IF_OPER_STATUS status )
1689 switch (status)
1691 case IfOperStatusDown:
1692 return 0; /* Disconnected */
1693 case IfOperStatusUp:
1694 return 2; /* Connected */
1695 default:
1696 ERR("unhandled status %u\n", status);
1697 break;
1699 return 0;
1701 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1703 static const WCHAR fmtW[] =
1704 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1705 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1706 WCHAR *ret;
1708 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1709 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1710 return ret;
1712 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1714 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1715 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1716 static const WCHAR firewireW[] = {'1','3','9','4',0};
1717 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1719 switch (type)
1721 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1722 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1723 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1724 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1725 default: *physical = 0; return NULL;
1729 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1731 static const WCHAR fmtW[] = {'%','u',0};
1732 WCHAR device_id[11];
1733 struct record_networkadapter *rec;
1734 IP_ADAPTER_ADDRESSES *aa, *buffer;
1735 UINT row = 0, offset = 0, count = 0;
1736 DWORD size = 0, ret;
1737 int physical;
1738 enum fill_status status = FILL_STATUS_UNFILTERED;
1740 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1741 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1743 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1744 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1746 heap_free( buffer );
1747 return FILL_STATUS_FAILED;
1749 for (aa = buffer; aa; aa = aa->Next)
1751 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1753 if (!resize_table( table, count, sizeof(*rec) ))
1755 heap_free( buffer );
1756 return FILL_STATUS_FAILED;
1758 for (aa = buffer; aa; aa = aa->Next)
1760 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1762 rec = (struct record_networkadapter *)(table->data + offset);
1763 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1764 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1765 rec->device_id = heap_strdupW( device_id );
1766 rec->index = aa->u.s.IfIndex;
1767 rec->interface_index = aa->u.s.IfIndex;
1768 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1769 rec->manufacturer = compsys_manufacturerW;
1770 rec->name = heap_strdupW( aa->FriendlyName );
1771 rec->netconnection_status = get_connection_status( aa->OperStatus );
1772 rec->physicaladapter = physical;
1773 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1774 rec->speed = 1000000;
1775 if (!match_row( table, row, cond, &status ))
1777 free_row_values( table, row );
1778 continue;
1780 offset += sizeof(*rec);
1781 row++;
1783 TRACE("created %u rows\n", row);
1784 table->num_rows = row;
1786 heap_free( buffer );
1787 return status;
1790 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1792 struct record_networkadapterconfig *rec;
1793 IP_ADAPTER_ADDRESSES *aa, *buffer;
1794 UINT row = 0, offset = 0, count = 0;
1795 DWORD size = 0, ret;
1796 enum fill_status status = FILL_STATUS_UNFILTERED;
1798 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1799 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1801 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1802 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1804 heap_free( buffer );
1805 return FILL_STATUS_FAILED;
1807 for (aa = buffer; aa; aa = aa->Next)
1809 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1811 if (!resize_table( table, count, sizeof(*rec) ))
1813 heap_free( buffer );
1814 return FILL_STATUS_FAILED;
1816 for (aa = buffer; aa; aa = aa->Next)
1818 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1820 rec = (struct record_networkadapterconfig *)(table->data + offset);
1821 rec->index = aa->u.s.IfIndex;
1822 rec->ipconnectionmetric = 20;
1823 rec->ipenabled = -1;
1824 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1825 if (!match_row( table, row, cond, &status ))
1827 free_row_values( table, row );
1828 continue;
1830 offset += sizeof(*rec);
1831 row++;
1833 TRACE("created %u rows\n", row);
1834 table->num_rows = row;
1836 heap_free( buffer );
1837 return status;
1840 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
1842 struct record_physicalmemory *rec;
1843 enum fill_status status = FILL_STATUS_UNFILTERED;
1844 UINT row = 0;
1846 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1848 rec = (struct record_physicalmemory *)table->data;
1849 rec->capacity = get_total_physical_memory();
1850 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1851 else row++;
1853 TRACE("created %u rows\n", row);
1854 table->num_rows = row;
1855 return status;
1858 static WCHAR *get_cmdline( DWORD process_id )
1860 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1861 return NULL; /* FIXME handle different process case */
1864 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1866 static const WCHAR fmtW[] = {'%','u',0};
1867 WCHAR handle[11];
1868 struct record_process *rec;
1869 PROCESSENTRY32W entry;
1870 HANDLE snap;
1871 enum fill_status status = FILL_STATUS_FAILED;
1872 UINT row = 0, offset = 0;
1874 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1875 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1877 entry.dwSize = sizeof(entry);
1878 if (!Process32FirstW( snap, &entry )) goto done;
1879 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1883 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1885 rec = (struct record_process *)(table->data + offset);
1886 rec->caption = heap_strdupW( entry.szExeFile );
1887 rec->commandline = get_cmdline( entry.th32ProcessID );
1888 rec->description = heap_strdupW( entry.szExeFile );
1889 sprintfW( handle, fmtW, entry.th32ProcessID );
1890 rec->handle = heap_strdupW( handle );
1891 rec->name = heap_strdupW( entry.szExeFile );
1892 rec->process_id = entry.th32ProcessID;
1893 rec->pprocess_id = entry.th32ParentProcessID;
1894 rec->thread_count = entry.cntThreads;
1895 rec->get_owner = process_get_owner;
1896 if (!match_row( table, row, cond, &status ))
1898 free_row_values( table, row );
1899 continue;
1901 offset += sizeof(*rec);
1902 row++;
1903 } while (Process32NextW( snap, &entry ));
1905 TRACE("created %u rows\n", row);
1906 table->num_rows = row;
1907 status = FILL_STATUS_UNFILTERED;
1909 done:
1910 CloseHandle( snap );
1911 return status;
1914 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1916 #ifdef __i386__
1917 __asm__("pushl %%ebx\n\t"
1918 "cpuid\n\t"
1919 "movl %%ebx, %%esi\n\t"
1920 "popl %%ebx"
1921 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1922 : "0" (ax));
1923 #endif
1926 static void get_processor_id( WCHAR *processor_id )
1928 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1929 unsigned int regs[4] = {0, 0, 0, 0};
1931 do_cpuid( 1, regs );
1932 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1934 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1936 unsigned int i;
1937 unsigned char *p = (unsigned char *)regs;
1939 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1940 buffer[i] = 0;
1942 static void get_processor_manufacturer( WCHAR *manufacturer )
1944 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1946 do_cpuid( 0, regs );
1947 tmp = regs[2]; /* swap edx and ecx */
1948 regs[2] = regs[3];
1949 regs[3] = tmp;
1951 regs_to_str( regs + 1, 12, manufacturer );
1953 static void get_processor_name( WCHAR *name )
1955 unsigned int regs[4] = {0, 0, 0, 0};
1957 do_cpuid( 0x80000000, regs );
1958 if (regs[0] >= 0x80000004)
1960 do_cpuid( 0x80000002, regs );
1961 regs_to_str( regs, 16, name );
1962 do_cpuid( 0x80000003, regs );
1963 regs_to_str( regs, 16, name + 16 );
1964 do_cpuid( 0x80000004, regs );
1965 regs_to_str( regs, 16, name + 32 );
1968 static UINT get_processor_currentclockspeed( UINT index )
1970 PROCESSOR_POWER_INFORMATION *info;
1971 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1972 NTSTATUS status;
1974 if ((info = heap_alloc( size )))
1976 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1977 if (!status) ret = info[index].CurrentMhz;
1978 heap_free( info );
1980 return ret;
1982 static UINT get_processor_maxclockspeed( UINT index )
1984 PROCESSOR_POWER_INFORMATION *info;
1985 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1986 NTSTATUS status;
1988 if ((info = heap_alloc( size )))
1990 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1991 if (!status) ret = info[index].MaxMhz;
1992 heap_free( info );
1994 return ret;
1996 static const WCHAR *get_osarchitecture(void)
1998 SYSTEM_INFO info;
1999 GetNativeSystemInfo( &info );
2000 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2001 return os_32bitW;
2004 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2006 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2007 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
2008 struct record_processor *rec;
2009 UINT i, offset = 0, num_cores, num_logical_processors, count = get_processor_count();
2010 enum fill_status status = FILL_STATUS_UNFILTERED;
2012 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2014 get_processor_id( processor_id );
2015 get_processor_manufacturer( manufacturer );
2016 get_processor_name( name );
2018 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2019 num_cores /= count;
2021 for (i = 0; i < count; i++)
2023 rec = (struct record_processor *)(table->data + offset);
2024 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2025 rec->cpu_status = 1; /* CPU Enabled */
2026 rec->currentclockspeed = get_processor_currentclockspeed( i );
2027 sprintfW( device_id, fmtW, i );
2028 rec->device_id = heap_strdupW( device_id );
2029 rec->family = 2; /* Unknown */
2030 rec->manufacturer = heap_strdupW( manufacturer );
2031 rec->maxclockspeed = get_processor_maxclockspeed( i );
2032 rec->name = heap_strdupW( name );
2033 rec->num_cores = num_cores;
2034 rec->num_logical_processors = num_logical_processors;
2035 rec->processor_id = heap_strdupW( processor_id );
2036 rec->unique_id = NULL;
2037 if (!match_row( table, i, cond, &status ))
2039 free_row_values( table, i );
2040 continue;
2042 offset += sizeof(*rec);
2045 TRACE("created %u rows\n", count);
2046 table->num_rows = count;
2047 return status;
2050 static WCHAR *get_lastbootuptime(void)
2052 static const WCHAR fmtW[] =
2053 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2054 '.','%','0','6','u','+','0','0','0',0};
2055 SYSTEM_TIMEOFDAY_INFORMATION ti;
2056 TIME_FIELDS tf;
2057 WCHAR *ret;
2059 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2061 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2062 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2063 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2064 return ret;
2066 static WCHAR *get_localdatetime(void)
2068 static const WCHAR fmtW[] =
2069 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2070 '.','%','0','6','u','%','+','0','3','d',0};
2071 TIME_ZONE_INFORMATION tzi;
2072 SYSTEMTIME st;
2073 WCHAR *ret;
2074 DWORD Status;
2075 LONG Bias;
2077 Status = GetTimeZoneInformation(&tzi);
2079 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2080 Bias = tzi.Bias;
2081 if(Status == TIME_ZONE_ID_DAYLIGHT)
2082 Bias+= tzi.DaylightBias;
2083 else
2084 Bias+= tzi.StandardBias;
2085 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2087 GetLocalTime(&st);
2088 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2089 return ret;
2091 static WCHAR *get_systemdirectory(void)
2093 void *redir;
2094 WCHAR *ret;
2096 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2097 Wow64DisableWow64FsRedirection( &redir );
2098 GetSystemDirectoryW( ret, MAX_PATH );
2099 Wow64RevertWow64FsRedirection( redir );
2100 return ret;
2102 static WCHAR *get_codeset(void)
2104 static const WCHAR fmtW[] = {'%','u',0};
2105 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2106 if (ret) sprintfW( ret, fmtW, GetACP() );
2107 return ret;
2109 static WCHAR *get_countrycode(void)
2111 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2112 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2113 return ret;
2115 static WCHAR *get_locale(void)
2117 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2118 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2119 return ret;
2122 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2124 struct record_operatingsystem *rec;
2125 enum fill_status status = FILL_STATUS_UNFILTERED;
2126 UINT row = 0;
2128 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2130 rec = (struct record_operatingsystem *)table->data;
2131 rec->buildnumber = os_buildnumberW;
2132 rec->caption = os_captionW;
2133 rec->codeset = get_codeset();
2134 rec->countrycode = get_countrycode();
2135 rec->csdversion = os_csdversionW;
2136 rec->installdate = os_installdateW;
2137 rec->lastbootuptime = get_lastbootuptime();
2138 rec->localdatetime = get_localdatetime();
2139 rec->locale = get_locale();
2140 rec->name = os_nameW;
2141 rec->osarchitecture = get_osarchitecture();
2142 rec->oslanguage = GetSystemDefaultLangID();
2143 rec->osproductsuite = 2461140; /* Windows XP Professional */
2144 rec->ostype = 18; /* WINNT */
2145 rec->serialnumber = os_serialnumberW;
2146 rec->servicepackmajor = 3;
2147 rec->servicepackminor = 0;
2148 rec->suitemask = 272; /* Single User + Terminal */
2149 rec->systemdirectory = get_systemdirectory();
2150 rec->version = os_versionW;
2151 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2152 else row++;
2154 TRACE("created %u rows\n", row);
2155 table->num_rows = row;
2156 return status;
2159 static const WCHAR *get_service_type( DWORD type )
2161 static const WCHAR filesystem_driverW[] =
2162 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2163 static const WCHAR kernel_driverW[] =
2164 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2165 static const WCHAR own_processW[] =
2166 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2167 static const WCHAR share_processW[] =
2168 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2170 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2171 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2172 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2173 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2174 else ERR("unhandled type 0x%08x\n", type);
2175 return NULL;
2177 static const WCHAR *get_service_state( DWORD state )
2179 static const WCHAR runningW[] =
2180 {'R','u','n','n','i','n','g',0};
2181 static const WCHAR start_pendingW[] =
2182 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2183 static const WCHAR stop_pendingW[] =
2184 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2185 static const WCHAR stoppedW[] =
2186 {'S','t','o','p','p','e','d',0};
2187 static const WCHAR unknownW[] =
2188 {'U','n','k','n','o','w','n',0};
2190 switch (state)
2192 case SERVICE_STOPPED: return stoppedW;
2193 case SERVICE_START_PENDING: return start_pendingW;
2194 case SERVICE_STOP_PENDING: return stop_pendingW;
2195 case SERVICE_RUNNING: return runningW;
2196 default:
2197 ERR("unknown state %u\n", state);
2198 return unknownW;
2201 static const WCHAR *get_service_startmode( DWORD mode )
2203 static const WCHAR bootW[] = {'B','o','o','t',0};
2204 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2205 static const WCHAR autoW[] = {'A','u','t','o',0};
2206 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2207 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2208 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2210 switch (mode)
2212 case SERVICE_BOOT_START: return bootW;
2213 case SERVICE_SYSTEM_START: return systemW;
2214 case SERVICE_AUTO_START: return autoW;
2215 case SERVICE_DEMAND_START: return manualW;
2216 case SERVICE_DISABLED: return disabledW;
2217 default:
2218 ERR("unknown mode 0x%x\n", mode);
2219 return unknownW;
2222 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2224 QUERY_SERVICE_CONFIGW *config = NULL;
2225 SC_HANDLE service;
2226 DWORD size;
2228 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2229 QueryServiceConfigW( service, NULL, 0, &size );
2230 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2231 if (!(config = heap_alloc( size ))) goto done;
2232 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2233 heap_free( config );
2234 config = NULL;
2236 done:
2237 CloseServiceHandle( service );
2238 return config;
2241 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2243 struct record_service *rec;
2244 SC_HANDLE manager;
2245 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2246 SERVICE_STATUS_PROCESS *status;
2247 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2248 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2249 UINT i, row = 0, offset = 0, size = 256, needed, count;
2250 enum fill_status fill_status = FILL_STATUS_FAILED;
2251 BOOL ret;
2253 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2254 if (!(services = heap_alloc( size ))) goto done;
2256 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2257 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2258 &count, NULL, NULL );
2259 if (!ret)
2261 if (GetLastError() != ERROR_MORE_DATA) goto done;
2262 size = needed;
2263 if (!(tmp = heap_realloc( services, size ))) goto done;
2264 services = tmp;
2265 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2266 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2267 &count, NULL, NULL );
2268 if (!ret) goto done;
2270 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2272 GetComputerNameW( sysnameW, &len );
2273 fill_status = FILL_STATUS_UNFILTERED;
2275 for (i = 0; i < count; i++)
2277 QUERY_SERVICE_CONFIGW *config;
2279 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2281 status = &services[i].ServiceStatusProcess;
2282 rec = (struct record_service *)(table->data + offset);
2283 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2284 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2285 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2286 rec->name = heap_strdupW( services[i].lpServiceName );
2287 rec->process_id = status->dwProcessId;
2288 rec->servicetype = get_service_type( status->dwServiceType );
2289 rec->startmode = get_service_startmode( config->dwStartType );
2290 rec->state = get_service_state( status->dwCurrentState );
2291 rec->systemname = heap_strdupW( sysnameW );
2292 rec->pause_service = service_pause_service;
2293 rec->resume_service = service_resume_service;
2294 rec->start_service = service_start_service;
2295 rec->stop_service = service_stop_service;
2296 heap_free( config );
2297 if (!match_row( table, row, cond, &fill_status ))
2299 free_row_values( table, row );
2300 continue;
2302 offset += sizeof(*rec);
2303 row++;
2306 TRACE("created %u rows\n", row);
2307 table->num_rows = row;
2309 done:
2310 CloseServiceHandle( manager );
2311 heap_free( services );
2312 return fill_status;
2315 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2317 HDC hdc = GetDC( NULL );
2318 UINT32 ret;
2320 if (!hdc) return 32;
2321 ret = GetDeviceCaps( hdc, BITSPIXEL );
2322 *hres = GetDeviceCaps( hdc, HORZRES );
2323 *vres = GetDeviceCaps( hdc, VERTRES );
2324 ReleaseDC( NULL, hdc );
2325 return ret;
2327 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2329 static const WCHAR fmtW[] =
2330 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2331 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2332 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2333 WCHAR *ret;
2335 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2336 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2337 return ret;
2340 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2343 struct record_videocontroller *rec;
2344 HRESULT hr;
2345 IDXGIFactory *factory = NULL;
2346 IDXGIAdapter *adapter = NULL;
2347 DXGI_ADAPTER_DESC desc;
2348 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2349 const WCHAR *name = videocontroller_deviceidW;
2350 enum fill_status status = FILL_STATUS_UNFILTERED;
2351 UINT row = 0;
2353 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2355 memset (&desc, 0, sizeof(desc));
2356 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2357 if (FAILED(hr)) goto done;
2359 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2360 if (FAILED(hr)) goto done;
2362 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2363 if (SUCCEEDED(hr))
2365 vidmem = desc.DedicatedVideoMemory;
2366 name = desc.Description;
2369 done:
2370 rec = (struct record_videocontroller *)table->data;
2371 rec->adapter_dactype = videocontroller_dactypeW;
2372 rec->adapter_ram = vidmem;
2373 rec->availability = 3; /* Running or Full Power */
2374 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2375 rec->current_horizontalres = hres;
2376 rec->current_verticalres = vres;
2377 rec->description = heap_strdupW( name );
2378 rec->device_id = videocontroller_deviceidW;
2379 rec->name = heap_strdupW( name );
2380 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2381 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2382 else row++;
2384 TRACE("created %u rows\n", row);
2385 table->num_rows = row;
2387 if (adapter) IDXGIAdapter_Release( adapter );
2388 if (factory) IDXGIFactory_Release( factory );
2389 return status;
2392 static struct table builtin_classes[] =
2394 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2395 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2396 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2397 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2398 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2399 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2400 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
2401 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2402 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2403 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2404 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2405 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2406 fill_networkadapterconfig },
2407 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2408 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2409 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2410 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
2411 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2412 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2413 { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2414 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2415 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2416 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2417 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2418 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2421 void init_table_list( void )
2423 static struct list tables = LIST_INIT( tables );
2424 UINT i;
2426 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2427 table_list = &tables;