dxgi: Implement dxgi_surface_GetDesc().
[wine.git] / dlls / wbemprox / builtin.c
blob169227ef9f71e562ceee0a2d0caeed6896eab8e9
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;
1501 DWORD bytes_returned;
1503 free.QuadPart = 512 * 1024 * 1024;
1504 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1506 root[4] = dir[0];
1507 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1508 if (handle != INVALID_HANDLE_VALUE)
1510 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
1511 *disksize = info.DiskSize.QuadPart;
1512 CloseHandle( handle );
1514 return free.QuadPart;
1517 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1519 static const WCHAR fmtW[] =
1520 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1521 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1522 struct record_diskdrive *rec;
1523 UINT i, row = 0, offset = 0, index = 0, type;
1524 UINT64 size = 1024 * 1024 * 1024;
1525 DWORD drives = GetLogicalDrives();
1526 enum fill_status status = FILL_STATUS_UNFILTERED;
1528 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1530 for (i = 0; i < sizeof(drives); i++)
1532 if (drives & (1 << i))
1534 root[0] = 'A' + i;
1535 type = GetDriveTypeW( root );
1536 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1537 continue;
1539 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1541 rec = (struct record_diskdrive *)(table->data + offset);
1542 sprintfW( device_id, fmtW, index );
1543 rec->device_id = heap_strdupW( device_id );
1544 rec->index = index;
1545 rec->interfacetype = diskdrive_interfacetypeW;
1546 rec->manufacturer = diskdrive_manufacturerW;
1547 if (type == DRIVE_FIXED)
1548 rec->mediatype = diskdrive_mediatype_fixedW;
1549 else
1550 rec->mediatype = diskdrive_mediatype_removableW;
1551 rec->model = diskdrive_modelW;
1552 rec->serialnumber = diskdrive_serialW;
1553 get_freespace( root, &size );
1554 rec->size = size;
1555 if (!match_row( table, row, cond, &status ))
1557 free_row_values( table, row );
1558 continue;
1560 offset += sizeof(*rec);
1561 index++;
1562 row++;
1565 TRACE("created %u rows\n", row);
1566 table->num_rows = row;
1567 return status;
1570 static WCHAR *get_filesystem( const WCHAR *root )
1572 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1573 WCHAR buffer[MAX_PATH + 1];
1575 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1576 return heap_strdupW( buffer );
1577 return heap_strdupW( ntfsW );
1580 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1582 static const WCHAR fmtW[] =
1583 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1584 WCHAR device_id[32], root[] = {'A',':','\\',0};
1585 struct record_diskpartition *rec;
1586 UINT i, row = 0, offset = 0, type, index = 0;
1587 UINT64 size = 1024 * 1024 * 1024;
1588 DWORD drives = GetLogicalDrives();
1589 enum fill_status status = FILL_STATUS_UNFILTERED;
1591 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1593 for (i = 0; i < sizeof(drives); i++)
1595 if (drives & (1 << i))
1597 root[0] = 'A' + i;
1598 type = GetDriveTypeW( root );
1599 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1600 continue;
1602 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1604 rec = (struct record_diskpartition *)(table->data + offset);
1605 rec->bootable = (i == 2) ? -1 : 0;
1606 rec->bootpartition = (i == 2) ? -1 : 0;
1607 sprintfW( device_id, fmtW, index );
1608 rec->device_id = heap_strdupW( device_id );
1609 rec->diskindex = index;
1610 rec->index = 0;
1611 rec->pnpdevice_id = heap_strdupW( device_id );
1612 get_freespace( root, &size );
1613 rec->size = size;
1614 rec->startingoffset = 0;
1615 rec->type = get_filesystem( root );
1616 if (!match_row( table, row, cond, &status ))
1618 free_row_values( table, row );
1619 continue;
1621 offset += sizeof(*rec);
1622 row++;
1623 index++;
1626 TRACE("created %u rows\n", row);
1627 table->num_rows = row;
1628 return status;
1631 static WCHAR *get_volumeserialnumber( const WCHAR *root )
1633 static const WCHAR fmtW[] = {'%','0','8','X',0};
1634 DWORD serial = 0;
1635 WCHAR buffer[9];
1637 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
1638 sprintfW( buffer, fmtW, serial );
1639 return heap_strdupW( buffer );
1642 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1644 static const WCHAR fmtW[] = {'%','c',':',0};
1645 WCHAR device_id[3], root[] = {'A',':','\\',0};
1646 struct record_logicaldisk *rec;
1647 UINT i, row = 0, offset = 0, type;
1648 UINT64 size = 1024 * 1024 * 1024;
1649 DWORD drives = GetLogicalDrives();
1650 enum fill_status status = FILL_STATUS_UNFILTERED;
1652 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1654 for (i = 0; i < sizeof(drives); i++)
1656 if (drives & (1 << i))
1658 root[0] = 'A' + i;
1659 type = GetDriveTypeW( root );
1660 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1661 continue;
1663 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1665 rec = (struct record_logicaldisk *)(table->data + offset);
1666 sprintfW( device_id, fmtW, 'A' + i );
1667 rec->device_id = heap_strdupW( device_id );
1668 rec->drivetype = type;
1669 rec->filesystem = get_filesystem( root );
1670 rec->freespace = get_freespace( root, &size );
1671 rec->name = heap_strdupW( device_id );
1672 rec->size = size;
1673 rec->volumeserialnumber = get_volumeserialnumber( root );
1674 if (!match_row( table, row, cond, &status ))
1676 free_row_values( table, row );
1677 continue;
1679 offset += sizeof(*rec);
1680 row++;
1683 TRACE("created %u rows\n", row);
1684 table->num_rows = row;
1685 return status;
1688 static UINT16 get_connection_status( IF_OPER_STATUS status )
1690 switch (status)
1692 case IfOperStatusDown:
1693 return 0; /* Disconnected */
1694 case IfOperStatusUp:
1695 return 2; /* Connected */
1696 default:
1697 ERR("unhandled status %u\n", status);
1698 break;
1700 return 0;
1702 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1704 static const WCHAR fmtW[] =
1705 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1706 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1707 WCHAR *ret;
1709 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1710 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1711 return ret;
1713 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1715 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1716 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1717 static const WCHAR firewireW[] = {'1','3','9','4',0};
1718 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1720 switch (type)
1722 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1723 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1724 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1725 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1726 default: *physical = 0; return NULL;
1730 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1732 static const WCHAR fmtW[] = {'%','u',0};
1733 WCHAR device_id[11];
1734 struct record_networkadapter *rec;
1735 IP_ADAPTER_ADDRESSES *aa, *buffer;
1736 UINT row = 0, offset = 0, count = 0;
1737 DWORD size = 0, ret;
1738 int physical;
1739 enum fill_status status = FILL_STATUS_UNFILTERED;
1741 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1742 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1744 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1745 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1747 heap_free( buffer );
1748 return FILL_STATUS_FAILED;
1750 for (aa = buffer; aa; aa = aa->Next)
1752 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1754 if (!resize_table( table, count, sizeof(*rec) ))
1756 heap_free( buffer );
1757 return FILL_STATUS_FAILED;
1759 for (aa = buffer; aa; aa = aa->Next)
1761 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1763 rec = (struct record_networkadapter *)(table->data + offset);
1764 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1765 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1766 rec->device_id = heap_strdupW( device_id );
1767 rec->index = aa->u.s.IfIndex;
1768 rec->interface_index = aa->u.s.IfIndex;
1769 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1770 rec->manufacturer = compsys_manufacturerW;
1771 rec->name = heap_strdupW( aa->FriendlyName );
1772 rec->netconnection_status = get_connection_status( aa->OperStatus );
1773 rec->physicaladapter = physical;
1774 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1775 rec->speed = 1000000;
1776 if (!match_row( table, row, cond, &status ))
1778 free_row_values( table, row );
1779 continue;
1781 offset += sizeof(*rec);
1782 row++;
1784 TRACE("created %u rows\n", row);
1785 table->num_rows = row;
1787 heap_free( buffer );
1788 return status;
1791 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1793 struct record_networkadapterconfig *rec;
1794 IP_ADAPTER_ADDRESSES *aa, *buffer;
1795 UINT row = 0, offset = 0, count = 0;
1796 DWORD size = 0, ret;
1797 enum fill_status status = FILL_STATUS_UNFILTERED;
1799 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1800 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1802 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1803 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1805 heap_free( buffer );
1806 return FILL_STATUS_FAILED;
1808 for (aa = buffer; aa; aa = aa->Next)
1810 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1812 if (!resize_table( table, count, sizeof(*rec) ))
1814 heap_free( buffer );
1815 return FILL_STATUS_FAILED;
1817 for (aa = buffer; aa; aa = aa->Next)
1819 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1821 rec = (struct record_networkadapterconfig *)(table->data + offset);
1822 rec->index = aa->u.s.IfIndex;
1823 rec->ipconnectionmetric = 20;
1824 rec->ipenabled = -1;
1825 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1826 if (!match_row( table, row, cond, &status ))
1828 free_row_values( table, row );
1829 continue;
1831 offset += sizeof(*rec);
1832 row++;
1834 TRACE("created %u rows\n", row);
1835 table->num_rows = row;
1837 heap_free( buffer );
1838 return status;
1841 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
1843 struct record_physicalmemory *rec;
1844 enum fill_status status = FILL_STATUS_UNFILTERED;
1845 UINT row = 0;
1847 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1849 rec = (struct record_physicalmemory *)table->data;
1850 rec->capacity = get_total_physical_memory();
1851 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1852 else row++;
1854 TRACE("created %u rows\n", row);
1855 table->num_rows = row;
1856 return status;
1859 static WCHAR *get_cmdline( DWORD process_id )
1861 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1862 return NULL; /* FIXME handle different process case */
1865 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1867 static const WCHAR fmtW[] = {'%','u',0};
1868 WCHAR handle[11];
1869 struct record_process *rec;
1870 PROCESSENTRY32W entry;
1871 HANDLE snap;
1872 enum fill_status status = FILL_STATUS_FAILED;
1873 UINT row = 0, offset = 0;
1875 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1876 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1878 entry.dwSize = sizeof(entry);
1879 if (!Process32FirstW( snap, &entry )) goto done;
1880 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1884 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1886 rec = (struct record_process *)(table->data + offset);
1887 rec->caption = heap_strdupW( entry.szExeFile );
1888 rec->commandline = get_cmdline( entry.th32ProcessID );
1889 rec->description = heap_strdupW( entry.szExeFile );
1890 sprintfW( handle, fmtW, entry.th32ProcessID );
1891 rec->handle = heap_strdupW( handle );
1892 rec->name = heap_strdupW( entry.szExeFile );
1893 rec->process_id = entry.th32ProcessID;
1894 rec->pprocess_id = entry.th32ParentProcessID;
1895 rec->thread_count = entry.cntThreads;
1896 rec->get_owner = process_get_owner;
1897 if (!match_row( table, row, cond, &status ))
1899 free_row_values( table, row );
1900 continue;
1902 offset += sizeof(*rec);
1903 row++;
1904 } while (Process32NextW( snap, &entry ));
1906 TRACE("created %u rows\n", row);
1907 table->num_rows = row;
1908 status = FILL_STATUS_UNFILTERED;
1910 done:
1911 CloseHandle( snap );
1912 return status;
1915 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1917 #ifdef __i386__
1918 __asm__("pushl %%ebx\n\t"
1919 "cpuid\n\t"
1920 "movl %%ebx, %%esi\n\t"
1921 "popl %%ebx"
1922 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1923 : "0" (ax));
1924 #endif
1927 static void get_processor_id( WCHAR *processor_id )
1929 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1930 unsigned int regs[4] = {0, 0, 0, 0};
1932 do_cpuid( 1, regs );
1933 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1935 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1937 unsigned int i;
1938 unsigned char *p = (unsigned char *)regs;
1940 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1941 buffer[i] = 0;
1943 static void get_processor_manufacturer( WCHAR *manufacturer )
1945 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1947 do_cpuid( 0, regs );
1948 tmp = regs[2]; /* swap edx and ecx */
1949 regs[2] = regs[3];
1950 regs[3] = tmp;
1952 regs_to_str( regs + 1, 12, manufacturer );
1954 static void get_processor_name( WCHAR *name )
1956 unsigned int regs[4] = {0, 0, 0, 0};
1958 do_cpuid( 0x80000000, regs );
1959 if (regs[0] >= 0x80000004)
1961 do_cpuid( 0x80000002, regs );
1962 regs_to_str( regs, 16, name );
1963 do_cpuid( 0x80000003, regs );
1964 regs_to_str( regs, 16, name + 16 );
1965 do_cpuid( 0x80000004, regs );
1966 regs_to_str( regs, 16, name + 32 );
1969 static UINT get_processor_currentclockspeed( UINT index )
1971 PROCESSOR_POWER_INFORMATION *info;
1972 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1973 NTSTATUS status;
1975 if ((info = heap_alloc( size )))
1977 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1978 if (!status) ret = info[index].CurrentMhz;
1979 heap_free( info );
1981 return ret;
1983 static UINT get_processor_maxclockspeed( UINT index )
1985 PROCESSOR_POWER_INFORMATION *info;
1986 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1987 NTSTATUS status;
1989 if ((info = heap_alloc( size )))
1991 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1992 if (!status) ret = info[index].MaxMhz;
1993 heap_free( info );
1995 return ret;
1997 static const WCHAR *get_osarchitecture(void)
1999 SYSTEM_INFO info;
2000 GetNativeSystemInfo( &info );
2001 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2002 return os_32bitW;
2005 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2007 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2008 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
2009 struct record_processor *rec;
2010 UINT i, offset = 0, num_cores, num_logical_processors, count = get_processor_count();
2011 enum fill_status status = FILL_STATUS_UNFILTERED;
2013 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2015 get_processor_id( processor_id );
2016 get_processor_manufacturer( manufacturer );
2017 get_processor_name( name );
2019 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2020 num_cores /= count;
2022 for (i = 0; i < count; i++)
2024 rec = (struct record_processor *)(table->data + offset);
2025 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2026 rec->cpu_status = 1; /* CPU Enabled */
2027 rec->currentclockspeed = get_processor_currentclockspeed( i );
2028 sprintfW( device_id, fmtW, i );
2029 rec->device_id = heap_strdupW( device_id );
2030 rec->family = 2; /* Unknown */
2031 rec->manufacturer = heap_strdupW( manufacturer );
2032 rec->maxclockspeed = get_processor_maxclockspeed( i );
2033 rec->name = heap_strdupW( name );
2034 rec->num_cores = num_cores;
2035 rec->num_logical_processors = num_logical_processors;
2036 rec->processor_id = heap_strdupW( processor_id );
2037 rec->unique_id = NULL;
2038 if (!match_row( table, i, cond, &status ))
2040 free_row_values( table, i );
2041 continue;
2043 offset += sizeof(*rec);
2046 TRACE("created %u rows\n", count);
2047 table->num_rows = count;
2048 return status;
2051 static WCHAR *get_lastbootuptime(void)
2053 static const WCHAR fmtW[] =
2054 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2055 '.','%','0','6','u','+','0','0','0',0};
2056 SYSTEM_TIMEOFDAY_INFORMATION ti;
2057 TIME_FIELDS tf;
2058 WCHAR *ret;
2060 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2062 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2063 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2064 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2065 return ret;
2067 static WCHAR *get_localdatetime(void)
2069 static const WCHAR fmtW[] =
2070 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2071 '.','%','0','6','u','%','+','0','3','d',0};
2072 TIME_ZONE_INFORMATION tzi;
2073 SYSTEMTIME st;
2074 WCHAR *ret;
2075 DWORD Status;
2076 LONG Bias;
2078 Status = GetTimeZoneInformation(&tzi);
2080 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2081 Bias = tzi.Bias;
2082 if(Status == TIME_ZONE_ID_DAYLIGHT)
2083 Bias+= tzi.DaylightBias;
2084 else
2085 Bias+= tzi.StandardBias;
2086 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2088 GetLocalTime(&st);
2089 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2090 return ret;
2092 static WCHAR *get_systemdirectory(void)
2094 void *redir;
2095 WCHAR *ret;
2097 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2098 Wow64DisableWow64FsRedirection( &redir );
2099 GetSystemDirectoryW( ret, MAX_PATH );
2100 Wow64RevertWow64FsRedirection( redir );
2101 return ret;
2103 static WCHAR *get_codeset(void)
2105 static const WCHAR fmtW[] = {'%','u',0};
2106 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2107 if (ret) sprintfW( ret, fmtW, GetACP() );
2108 return ret;
2110 static WCHAR *get_countrycode(void)
2112 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2113 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2114 return ret;
2116 static WCHAR *get_locale(void)
2118 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2119 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2120 return ret;
2123 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2125 struct record_operatingsystem *rec;
2126 enum fill_status status = FILL_STATUS_UNFILTERED;
2127 UINT row = 0;
2129 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2131 rec = (struct record_operatingsystem *)table->data;
2132 rec->buildnumber = os_buildnumberW;
2133 rec->caption = os_captionW;
2134 rec->codeset = get_codeset();
2135 rec->countrycode = get_countrycode();
2136 rec->csdversion = os_csdversionW;
2137 rec->installdate = os_installdateW;
2138 rec->lastbootuptime = get_lastbootuptime();
2139 rec->localdatetime = get_localdatetime();
2140 rec->locale = get_locale();
2141 rec->name = os_nameW;
2142 rec->osarchitecture = get_osarchitecture();
2143 rec->oslanguage = GetSystemDefaultLangID();
2144 rec->osproductsuite = 2461140; /* Windows XP Professional */
2145 rec->ostype = 18; /* WINNT */
2146 rec->serialnumber = os_serialnumberW;
2147 rec->servicepackmajor = 3;
2148 rec->servicepackminor = 0;
2149 rec->suitemask = 272; /* Single User + Terminal */
2150 rec->systemdirectory = get_systemdirectory();
2151 rec->version = os_versionW;
2152 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2153 else row++;
2155 TRACE("created %u rows\n", row);
2156 table->num_rows = row;
2157 return status;
2160 static const WCHAR *get_service_type( DWORD type )
2162 static const WCHAR filesystem_driverW[] =
2163 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2164 static const WCHAR kernel_driverW[] =
2165 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2166 static const WCHAR own_processW[] =
2167 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2168 static const WCHAR share_processW[] =
2169 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2171 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2172 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2173 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2174 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2175 else ERR("unhandled type 0x%08x\n", type);
2176 return NULL;
2178 static const WCHAR *get_service_state( DWORD state )
2180 static const WCHAR runningW[] =
2181 {'R','u','n','n','i','n','g',0};
2182 static const WCHAR start_pendingW[] =
2183 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2184 static const WCHAR stop_pendingW[] =
2185 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2186 static const WCHAR stoppedW[] =
2187 {'S','t','o','p','p','e','d',0};
2188 static const WCHAR unknownW[] =
2189 {'U','n','k','n','o','w','n',0};
2191 switch (state)
2193 case SERVICE_STOPPED: return stoppedW;
2194 case SERVICE_START_PENDING: return start_pendingW;
2195 case SERVICE_STOP_PENDING: return stop_pendingW;
2196 case SERVICE_RUNNING: return runningW;
2197 default:
2198 ERR("unknown state %u\n", state);
2199 return unknownW;
2202 static const WCHAR *get_service_startmode( DWORD mode )
2204 static const WCHAR bootW[] = {'B','o','o','t',0};
2205 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2206 static const WCHAR autoW[] = {'A','u','t','o',0};
2207 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2208 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2209 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2211 switch (mode)
2213 case SERVICE_BOOT_START: return bootW;
2214 case SERVICE_SYSTEM_START: return systemW;
2215 case SERVICE_AUTO_START: return autoW;
2216 case SERVICE_DEMAND_START: return manualW;
2217 case SERVICE_DISABLED: return disabledW;
2218 default:
2219 ERR("unknown mode 0x%x\n", mode);
2220 return unknownW;
2223 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2225 QUERY_SERVICE_CONFIGW *config = NULL;
2226 SC_HANDLE service;
2227 DWORD size;
2229 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2230 QueryServiceConfigW( service, NULL, 0, &size );
2231 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2232 if (!(config = heap_alloc( size ))) goto done;
2233 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2234 heap_free( config );
2235 config = NULL;
2237 done:
2238 CloseServiceHandle( service );
2239 return config;
2242 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2244 struct record_service *rec;
2245 SC_HANDLE manager;
2246 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2247 SERVICE_STATUS_PROCESS *status;
2248 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2249 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2250 UINT i, row = 0, offset = 0, size = 256, needed, count;
2251 enum fill_status fill_status = FILL_STATUS_FAILED;
2252 BOOL ret;
2254 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2255 if (!(services = heap_alloc( size ))) goto done;
2257 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2258 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2259 &count, NULL, NULL );
2260 if (!ret)
2262 if (GetLastError() != ERROR_MORE_DATA) goto done;
2263 size = needed;
2264 if (!(tmp = heap_realloc( services, size ))) goto done;
2265 services = tmp;
2266 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2267 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2268 &count, NULL, NULL );
2269 if (!ret) goto done;
2271 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2273 GetComputerNameW( sysnameW, &len );
2274 fill_status = FILL_STATUS_UNFILTERED;
2276 for (i = 0; i < count; i++)
2278 QUERY_SERVICE_CONFIGW *config;
2280 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2282 status = &services[i].ServiceStatusProcess;
2283 rec = (struct record_service *)(table->data + offset);
2284 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2285 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2286 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2287 rec->name = heap_strdupW( services[i].lpServiceName );
2288 rec->process_id = status->dwProcessId;
2289 rec->servicetype = get_service_type( status->dwServiceType );
2290 rec->startmode = get_service_startmode( config->dwStartType );
2291 rec->state = get_service_state( status->dwCurrentState );
2292 rec->systemname = heap_strdupW( sysnameW );
2293 rec->pause_service = service_pause_service;
2294 rec->resume_service = service_resume_service;
2295 rec->start_service = service_start_service;
2296 rec->stop_service = service_stop_service;
2297 heap_free( config );
2298 if (!match_row( table, row, cond, &fill_status ))
2300 free_row_values( table, row );
2301 continue;
2303 offset += sizeof(*rec);
2304 row++;
2307 TRACE("created %u rows\n", row);
2308 table->num_rows = row;
2310 done:
2311 CloseServiceHandle( manager );
2312 heap_free( services );
2313 return fill_status;
2316 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2318 HDC hdc = GetDC( NULL );
2319 UINT32 ret;
2321 if (!hdc) return 32;
2322 ret = GetDeviceCaps( hdc, BITSPIXEL );
2323 *hres = GetDeviceCaps( hdc, HORZRES );
2324 *vres = GetDeviceCaps( hdc, VERTRES );
2325 ReleaseDC( NULL, hdc );
2326 return ret;
2328 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2330 static const WCHAR fmtW[] =
2331 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2332 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2333 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2334 WCHAR *ret;
2336 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2337 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2338 return ret;
2341 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2344 struct record_videocontroller *rec;
2345 HRESULT hr;
2346 IDXGIFactory *factory = NULL;
2347 IDXGIAdapter *adapter = NULL;
2348 DXGI_ADAPTER_DESC desc;
2349 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2350 const WCHAR *name = videocontroller_deviceidW;
2351 enum fill_status status = FILL_STATUS_UNFILTERED;
2352 UINT row = 0;
2354 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2356 memset (&desc, 0, sizeof(desc));
2357 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2358 if (FAILED(hr)) goto done;
2360 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2361 if (FAILED(hr)) goto done;
2363 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2364 if (SUCCEEDED(hr))
2366 vidmem = desc.DedicatedVideoMemory;
2367 name = desc.Description;
2370 done:
2371 rec = (struct record_videocontroller *)table->data;
2372 rec->adapter_dactype = videocontroller_dactypeW;
2373 rec->adapter_ram = vidmem;
2374 rec->availability = 3; /* Running or Full Power */
2375 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2376 rec->current_horizontalres = hres;
2377 rec->current_verticalres = vres;
2378 rec->description = heap_strdupW( name );
2379 rec->device_id = videocontroller_deviceidW;
2380 rec->name = heap_strdupW( name );
2381 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2382 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2383 else row++;
2385 TRACE("created %u rows\n", row);
2386 table->num_rows = row;
2388 if (adapter) IDXGIAdapter_Release( adapter );
2389 if (factory) IDXGIFactory_Release( factory );
2390 return status;
2393 static struct table builtin_classes[] =
2395 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2396 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2397 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2398 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2399 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2400 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2401 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
2402 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2403 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2404 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2405 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2406 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2407 fill_networkadapterconfig },
2408 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2409 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2410 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2411 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
2412 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2413 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2414 { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2415 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2416 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2417 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2418 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2419 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2422 void init_table_list( void )
2424 static struct list tables = LIST_INIT( tables );
2425 UINT i;
2427 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2428 table_list = &tables;