api-ms-win-core-winrt-l1-1-0: Move implementations into combase.
[wine.git] / dlls / wbemprox / builtin.c
blob6337fef927db965dad62efef164b6d22ac1bb62b
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 "winsock2.h"
31 #include "initguid.h"
32 #include "wbemcli.h"
33 #include "wbemprov.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_totalvisiblememorysizeW[] =
275 {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
276 static const WCHAR prop_typeW[] =
277 {'T','y','p','e',0};
278 static const WCHAR prop_uniqueidW[] =
279 {'U','n','i','q','u','e','I','d',0};
280 static const WCHAR prop_varianttypeW[] =
281 {'V','a','r','i','a','n','t','T','y','p','e',0};
282 static const WCHAR prop_versionW[] =
283 {'V','e','r','s','i','o','n',0};
284 static const WCHAR prop_volumeserialnumberW[] =
285 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
287 /* column definitions must be kept in sync with record structures below */
288 static const struct column col_baseboard[] =
290 { prop_manufacturerW, CIM_STRING },
291 { prop_modelW, CIM_STRING },
292 { prop_nameW, CIM_STRING },
293 { prop_serialnumberW, CIM_STRING },
294 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
296 static const struct column col_bios[] =
298 { prop_descriptionW, CIM_STRING },
299 { prop_identificationcodeW, CIM_STRING },
300 { prop_manufacturerW, CIM_STRING },
301 { prop_releasedateW, CIM_DATETIME },
302 { prop_serialnumberW, CIM_STRING },
303 { prop_smbiosbiosversionW, CIM_STRING },
304 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
306 static const struct column col_cdromdrive[] =
308 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
309 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
310 { prop_mediatypeW, CIM_STRING },
311 { prop_nameW, CIM_STRING },
312 { prop_pnpdeviceidW, CIM_STRING }
314 static const struct column col_compsys[] =
316 { prop_descriptionW, CIM_STRING },
317 { prop_domainW, CIM_STRING },
318 { prop_domainroleW, CIM_UINT16, VT_I4 },
319 { prop_manufacturerW, CIM_STRING },
320 { prop_modelW, CIM_STRING },
321 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
322 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
323 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
324 { prop_totalphysicalmemoryW, CIM_UINT64 }
326 static const struct column col_datafile[] =
328 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
329 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
331 static const struct column col_directory[] =
333 { prop_accessmaskW, CIM_UINT32 },
334 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
336 static const struct column col_diskdrive[] =
338 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
339 { prop_indexW, CIM_UINT32, VT_I4 },
340 { prop_interfacetypeW, CIM_STRING },
341 { prop_manufacturerW, CIM_STRING },
342 { prop_mediatypeW, CIM_STRING },
343 { prop_modelW, CIM_STRING },
344 { prop_serialnumberW, CIM_STRING },
345 { prop_sizeW, CIM_UINT64 }
347 static const struct column col_diskpartition[] =
349 { prop_bootableW, CIM_BOOLEAN },
350 { prop_bootpartitionW, CIM_BOOLEAN },
351 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
352 { prop_diskindexW, CIM_UINT32, VT_I4 },
353 { prop_indexW, CIM_UINT32, VT_I4 },
354 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
355 { prop_sizeW, CIM_UINT64 },
356 { prop_startingoffsetW, CIM_UINT64 },
357 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
359 static const struct column col_logicaldisk[] =
361 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
362 { prop_drivetypeW, CIM_UINT32, VT_I4 },
363 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
364 { prop_freespaceW, CIM_UINT64 },
365 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
366 { prop_sizeW, CIM_UINT64 },
367 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
369 static const struct column col_networkadapter[] =
371 { prop_adaptertypeW, CIM_STRING },
372 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
373 { prop_indexW, CIM_UINT32, VT_I4 },
374 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
375 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
376 { prop_manufacturerW, CIM_STRING },
377 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
378 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
379 { prop_physicaladapterW, CIM_BOOLEAN },
380 { prop_pnpdeviceidW, CIM_STRING },
381 { prop_speedW, CIM_UINT64 }
383 static const struct column col_networkadapterconfig[] =
385 { prop_indexW, CIM_UINT32|COL_FLAG_KEY, VT_I4 },
386 { prop_ipconnectionmetricW, CIM_UINT32, VT_I4 },
387 { prop_ipenabledW, CIM_BOOLEAN },
388 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
390 static const struct column col_os[] =
392 { prop_buildnumberW, CIM_STRING },
393 { prop_captionW, CIM_STRING },
394 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
395 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
396 { prop_csdversionW, CIM_STRING },
397 { prop_installdateW, CIM_DATETIME },
398 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
399 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
400 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
401 { prop_nameW, CIM_STRING },
402 { prop_osarchitectureW, CIM_STRING },
403 { prop_oslanguageW, CIM_UINT32, VT_I4 },
404 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
405 { prop_ostypeW, CIM_UINT16, VT_I4 },
406 { prop_serialnumberW, CIM_STRING },
407 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
408 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
409 { prop_suitemaskW, CIM_UINT32, VT_I4 },
410 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
411 { prop_totalvisiblememorysizeW, CIM_UINT64 },
412 { prop_versionW, CIM_STRING }
414 static const struct column col_param[] =
416 { prop_classW, CIM_STRING },
417 { prop_methodW, CIM_STRING },
418 { prop_directionW, CIM_SINT32 },
419 { prop_parameterW, CIM_STRING },
420 { prop_typeW, CIM_UINT32 },
421 { prop_varianttypeW, CIM_UINT32 },
422 { prop_defaultvalueW, CIM_UINT32 }
424 static const struct column col_physicalmedia[] =
426 { prop_serialnumberW, CIM_STRING },
427 { prop_tagW, CIM_STRING }
429 static const struct column col_physicalmemory[] =
431 { prop_capacityW, CIM_UINT64 }
433 static const struct column col_process[] =
435 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
436 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
437 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
438 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
439 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
440 { prop_pprocessidW, CIM_UINT32, VT_I4 },
441 { prop_processidW, CIM_UINT32, VT_I4 },
442 { prop_threadcountW, CIM_UINT32, VT_I4 },
443 /* methods */
444 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
446 static const struct column col_processor[] =
448 { prop_addresswidthW, CIM_UINT16, VT_I4 },
449 { prop_cpustatusW, CIM_UINT16 },
450 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
451 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
452 { prop_familyW, CIM_UINT16, VT_I4 },
453 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
454 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
455 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
456 { prop_numcoresW, CIM_UINT32, VT_I4 },
457 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
458 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
459 { prop_uniqueidW, CIM_STRING }
461 static const struct column col_qualifier[] =
463 { prop_classW, CIM_STRING },
464 { prop_memberW, CIM_STRING },
465 { prop_typeW, CIM_UINT32 },
466 { prop_flavorW, CIM_SINT32 },
467 { prop_nameW, CIM_STRING },
468 { prop_intvalueW, CIM_SINT32 },
469 { prop_strvalueW, CIM_STRING }
471 static const struct column col_service[] =
473 { prop_acceptpauseW, CIM_BOOLEAN },
474 { prop_acceptstopW, CIM_BOOLEAN },
475 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
476 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
477 { prop_processidW, CIM_UINT32 },
478 { prop_servicetypeW, CIM_STRING },
479 { prop_startmodeW, CIM_STRING },
480 { prop_stateW, CIM_STRING },
481 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
482 /* methods */
483 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
484 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
485 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
486 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
488 static const struct column col_sounddevice[] =
490 { prop_nameW, CIM_STRING },
491 { prop_productnameW, CIM_STRING }
493 static const struct column col_stdregprov[] =
495 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
496 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
497 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
499 static const struct column col_systemsecurity[] =
501 { method_getsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
502 { method_setsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
504 static const struct column col_videocontroller[] =
506 { prop_adapterdactypeW, CIM_STRING },
507 { prop_adapterramW, CIM_UINT32, VT_I4 },
508 { prop_availabilityW, CIM_UINT16 },
509 { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 },
510 { prop_currenthorizontalresW, CIM_UINT32, VT_I4 },
511 { prop_currentverticalresW, CIM_UINT32, VT_I4 },
512 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
513 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
514 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
515 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
518 static const WCHAR baseboard_manufacturerW[] =
519 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
520 static const WCHAR baseboard_serialnumberW[] =
521 {'N','o','n','e',0};
522 static const WCHAR baseboard_tagW[] =
523 {'B','a','s','e',' ','B','o','a','r','d',0};
524 static const WCHAR bios_descriptionW[] =
525 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
526 static const WCHAR bios_manufacturerW[] =
527 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
528 static const WCHAR bios_releasedateW[] =
529 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
530 static const WCHAR bios_serialnumberW[] =
531 {'0',0};
532 static const WCHAR bios_smbiosbiosversionW[] =
533 {'W','i','n','e',0};
534 static const WCHAR bios_versionW[] =
535 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
536 static const WCHAR cdromdrive_mediatypeW[] =
537 {'C','D','-','R','O','M',0};
538 static const WCHAR cdromdrive_nameW[] =
539 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
540 static const WCHAR cdromdrive_pnpdeviceidW[]=
541 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
542 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
543 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
544 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
545 static const WCHAR compsys_descriptionW[] =
546 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
547 static const WCHAR compsys_domainW[] =
548 {'W','O','R','K','G','R','O','U','P',0};
549 static const WCHAR compsys_manufacturerW[] =
550 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
551 static const WCHAR compsys_modelW[] =
552 {'W','i','n','e',0};
553 static const WCHAR diskdrive_interfacetypeW[] =
554 {'I','D','E',0};
555 static const WCHAR diskdrive_manufacturerW[] =
556 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
557 static const WCHAR diskdrive_mediatype_fixedW[] =
558 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
559 static const WCHAR diskdrive_mediatype_removableW[] =
560 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
561 static const WCHAR diskdrive_modelW[] =
562 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
563 static const WCHAR diskdrive_serialW[] =
564 {'W','I','N','E','H','D','I','S','K',0};
565 static const WCHAR networkadapter_pnpdeviceidW[]=
566 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
567 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
568 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
569 static const WCHAR os_32bitW[] =
570 {'3','2','-','b','i','t',0};
571 static const WCHAR os_64bitW[] =
572 {'6','4','-','b','i','t',0};
573 static const WCHAR os_buildnumberW[] =
574 {'2','6','0','0',0};
575 static const WCHAR os_captionW[] =
576 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
577 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
578 static const WCHAR os_csdversionW[] =
579 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
580 static const WCHAR os_installdateW[] =
581 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
582 static const WCHAR os_nameW[] =
583 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
584 'P','r','o','f','e','s','s','i','o','n','a','l','|','C',':','\\','W','I','N','D','O','W','S',
585 '|','\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','0',
586 '\\','P','a','r','t','i','t','i','o','n','1',0};
587 static const WCHAR os_serialnumberW[] =
588 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
589 static const WCHAR os_versionW[] =
590 {'5','.','1','.','2','6','0','0',0};
591 static const WCHAR physicalmedia_tagW[] =
592 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
593 static const WCHAR sounddevice_productnameW[] =
594 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
595 static const WCHAR videocontroller_dactypeW[] =
596 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
597 static const WCHAR videocontroller_deviceidW[] =
598 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
600 #include "pshpack1.h"
601 struct record_baseboard
603 const WCHAR *manufacturer;
604 const WCHAR *model;
605 const WCHAR *name;
606 const WCHAR *serialnumber;
607 const WCHAR *tag;
609 struct record_bios
611 const WCHAR *description;
612 const WCHAR *identificationcode;
613 const WCHAR *manufacturer;
614 const WCHAR *releasedate;
615 const WCHAR *serialnumber;
616 const WCHAR *smbiosbiosversion;
617 const WCHAR *version;
619 struct record_cdromdrive
621 const WCHAR *device_id;
622 const WCHAR *drive;
623 const WCHAR *mediatype;
624 const WCHAR *name;
625 const WCHAR *pnpdevice_id;
627 struct record_computersystem
629 const WCHAR *description;
630 const WCHAR *domain;
631 UINT16 domainrole;
632 const WCHAR *manufacturer;
633 const WCHAR *model;
634 const WCHAR *name;
635 UINT32 num_logical_processors;
636 UINT32 num_processors;
637 UINT64 total_physical_memory;
639 struct record_datafile
641 const WCHAR *name;
642 const WCHAR *version;
644 struct record_directory
646 UINT32 accessmask;
647 const WCHAR *name;
649 struct record_diskdrive
651 const WCHAR *device_id;
652 UINT32 index;
653 const WCHAR *interfacetype;
654 const WCHAR *manufacturer;
655 const WCHAR *mediatype;
656 const WCHAR *model;
657 const WCHAR *serialnumber;
658 UINT64 size;
660 struct record_diskpartition
662 int bootable;
663 int bootpartition;
664 const WCHAR *device_id;
665 UINT32 diskindex;
666 UINT32 index;
667 const WCHAR *pnpdevice_id;
668 UINT64 size;
669 UINT64 startingoffset;
670 const WCHAR *type;
672 struct record_logicaldisk
674 const WCHAR *device_id;
675 UINT32 drivetype;
676 const WCHAR *filesystem;
677 UINT64 freespace;
678 const WCHAR *name;
679 UINT64 size;
680 const WCHAR *volumeserialnumber;
682 struct record_networkadapter
684 const WCHAR *adaptertype;
685 const WCHAR *device_id;
686 UINT32 index;
687 UINT32 interface_index;
688 const WCHAR *mac_address;
689 const WCHAR *manufacturer;
690 const WCHAR *name;
691 UINT16 netconnection_status;
692 int physicaladapter;
693 const WCHAR *pnpdevice_id;
694 UINT64 speed;
696 struct record_networkadapterconfig
698 UINT32 index;
699 UINT32 ipconnectionmetric;
700 int ipenabled;
701 const WCHAR *mac_address;
703 struct record_operatingsystem
705 const WCHAR *buildnumber;
706 const WCHAR *caption;
707 const WCHAR *codeset;
708 const WCHAR *countrycode;
709 const WCHAR *csdversion;
710 const WCHAR *installdate;
711 const WCHAR *lastbootuptime;
712 const WCHAR *localdatetime;
713 const WCHAR *locale;
714 const WCHAR *name;
715 const WCHAR *osarchitecture;
716 UINT32 oslanguage;
717 UINT32 osproductsuite;
718 UINT16 ostype;
719 const WCHAR *serialnumber;
720 UINT16 servicepackmajor;
721 UINT16 servicepackminor;
722 UINT32 suitemask;
723 const WCHAR *systemdirectory;
724 UINT64 totalvisiblememorysize;
725 const WCHAR *version;
727 struct record_param
729 const WCHAR *class;
730 const WCHAR *method;
731 INT32 direction;
732 const WCHAR *parameter;
733 UINT32 type;
734 UINT32 varianttype;
735 UINT32 defaultvalue;
737 struct record_physicalmedia
739 const WCHAR *serialnumber;
740 const WCHAR *tag;
742 struct record_physicalmemory
744 UINT64 capacity;
746 struct record_process
748 const WCHAR *caption;
749 const WCHAR *commandline;
750 const WCHAR *description;
751 const WCHAR *handle;
752 const WCHAR *name;
753 UINT32 pprocess_id;
754 UINT32 process_id;
755 UINT32 thread_count;
756 /* methods */
757 class_method *get_owner;
759 struct record_processor
761 UINT16 addresswidth;
762 UINT16 cpu_status;
763 UINT32 currentclockspeed;
764 const WCHAR *device_id;
765 UINT16 family;
766 const WCHAR *manufacturer;
767 UINT32 maxclockspeed;
768 const WCHAR *name;
769 UINT32 num_cores;
770 UINT32 num_logical_processors;
771 const WCHAR *processor_id;
772 const WCHAR *unique_id;
774 struct record_qualifier
776 const WCHAR *class;
777 const WCHAR *member;
778 UINT32 type;
779 INT32 flavor;
780 const WCHAR *name;
781 INT32 intvalue;
782 const WCHAR *strvalue;
784 struct record_service
786 int accept_pause;
787 int accept_stop;
788 const WCHAR *displayname;
789 const WCHAR *name;
790 UINT32 process_id;
791 const WCHAR *servicetype;
792 const WCHAR *startmode;
793 const WCHAR *state;
794 const WCHAR *systemname;
795 /* methods */
796 class_method *pause_service;
797 class_method *resume_service;
798 class_method *start_service;
799 class_method *stop_service;
801 struct record_sounddevice
803 const WCHAR *name;
804 const WCHAR *productname;
806 struct record_stdregprov
808 class_method *enumkey;
809 class_method *enumvalues;
810 class_method *getstringvalue;
812 struct record_systemsecurity
814 class_method *getsd;
815 class_method *setsd;
817 struct record_videocontroller
819 const WCHAR *adapter_dactype;
820 UINT32 adapter_ram;
821 UINT16 availability;
822 UINT32 current_bitsperpixel;
823 UINT32 current_horizontalres;
824 UINT32 current_verticalres;
825 const WCHAR *description;
826 const WCHAR *device_id;
827 const WCHAR *name;
828 const WCHAR *pnpdevice_id;
830 #include "poppack.h"
832 static const struct record_baseboard data_baseboard[] =
834 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
836 static const struct record_bios data_bios[] =
838 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
839 bios_smbiosbiosversionW, bios_versionW }
841 static const struct record_param data_param[] =
843 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
844 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
845 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
846 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
847 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
848 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
849 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
850 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
851 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
852 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
853 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
854 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
855 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
856 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
857 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
858 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
859 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
860 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
861 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
862 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
863 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
864 { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
865 { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
866 { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
867 { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
870 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
871 WBEM_FLAVOR_ORIGIN_PROPAGATED)
873 static const struct record_physicalmedia data_physicalmedia[] =
875 { diskdrive_serialW, physicalmedia_tagW }
877 static const struct record_qualifier data_qualifier[] =
879 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
880 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
882 static const struct record_sounddevice data_sounddevice[] =
884 { sounddevice_productnameW, sounddevice_productnameW }
886 static const struct record_stdregprov data_stdregprov[] =
888 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
890 static const struct record_systemsecurity data_systemsecurity[] =
892 { security_get_sd, security_set_sd }
895 /* check if row matches condition and update status */
896 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
898 LONGLONG val;
899 UINT type;
901 if (!cond)
903 *status = FILL_STATUS_UNFILTERED;
904 return TRUE;
906 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
908 *status = FILL_STATUS_FAILED;
909 return FALSE;
911 *status = FILL_STATUS_FILTERED;
912 return val != 0;
915 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
917 if (!table->num_rows_allocated)
919 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
920 table->num_rows_allocated = row_count;
921 return TRUE;
923 if (row_count >= table->num_rows_allocated)
925 BYTE *data;
926 UINT count = table->num_rows_allocated * 2;
927 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
928 table->data = data;
929 table->num_rows_allocated = count;
931 return TRUE;
934 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
936 static const WCHAR fmtW[] = {'%','c',':',0};
937 WCHAR drive[3], root[] = {'A',':','\\',0};
938 struct record_cdromdrive *rec;
939 UINT i, row = 0, offset = 0;
940 DWORD drives = GetLogicalDrives();
941 enum fill_status status = FILL_STATUS_UNFILTERED;
943 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
945 for (i = 0; i < sizeof(drives); i++)
947 if (drives & (1 << i))
949 root[0] = 'A' + i;
950 if (GetDriveTypeW( root ) != DRIVE_CDROM)
951 continue;
953 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
955 rec = (struct record_cdromdrive *)(table->data + offset);
956 rec->device_id = cdromdrive_pnpdeviceidW;
957 sprintfW( drive, fmtW, 'A' + i );
958 rec->drive = heap_strdupW( drive );
959 rec->mediatype = cdromdrive_mediatypeW;
960 rec->name = cdromdrive_nameW;
961 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
962 if (!match_row( table, row, cond, &status ))
964 free_row_values( table, row );
965 continue;
967 offset += sizeof(*rec);
968 row++;
971 TRACE("created %u rows\n", row);
972 table->num_rows = row;
973 return status;
976 static UINT get_processor_count(void)
978 SYSTEM_BASIC_INFORMATION info;
980 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
981 return info.NumberOfProcessors;
984 static UINT get_logical_processor_count( UINT *num_cores )
986 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
987 UINT i, j, count = 0;
988 NTSTATUS status;
989 ULONG len;
991 if (num_cores) *num_cores = get_processor_count();
992 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
993 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
995 if (!(info = heap_alloc( len ))) return get_processor_count();
996 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
997 if (status != STATUS_SUCCESS)
999 heap_free( info );
1000 return get_processor_count();
1002 if (num_cores) *num_cores = 0;
1003 for (i = 0; i < len / sizeof(*info); i++)
1005 if (info[i].Relationship == RelationProcessorCore)
1007 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
1009 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
1011 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
1014 heap_free( info );
1015 return count;
1018 static UINT64 get_total_physical_memory(void)
1020 MEMORYSTATUSEX status;
1022 status.dwLength = sizeof(status);
1023 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1024 return status.ullTotalPhys;
1027 static WCHAR *get_computername(void)
1029 WCHAR *ret;
1030 DWORD size = MAX_COMPUTERNAME_LENGTH;
1032 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1033 GetComputerNameW( ret, &size );
1034 return ret;
1037 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1039 struct record_computersystem *rec;
1040 enum fill_status status = FILL_STATUS_UNFILTERED;
1041 UINT row = 0;
1043 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1045 rec = (struct record_computersystem *)table->data;
1046 rec->description = compsys_descriptionW;
1047 rec->domain = compsys_domainW;
1048 rec->domainrole = 0; /* standalone workstation */
1049 rec->manufacturer = compsys_manufacturerW;
1050 rec->model = compsys_modelW;
1051 rec->name = get_computername();
1052 rec->num_logical_processors = get_logical_processor_count( NULL );
1053 rec->num_processors = get_processor_count();
1054 rec->total_physical_memory = get_total_physical_memory();
1055 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1056 else row++;
1058 TRACE("created %u rows\n", row);
1059 table->num_rows = row;
1060 return status;
1063 struct dirstack
1065 WCHAR **dirs;
1066 UINT *len_dirs;
1067 UINT num_dirs;
1068 UINT num_allocated;
1071 static struct dirstack *alloc_dirstack( UINT size )
1073 struct dirstack *dirstack;
1075 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1076 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1078 heap_free( dirstack );
1079 return NULL;
1081 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1083 heap_free( dirstack->dirs );
1084 heap_free( dirstack );
1085 return NULL;
1087 dirstack->num_dirs = 0;
1088 dirstack->num_allocated = size;
1089 return dirstack;
1092 static void clear_dirstack( struct dirstack *dirstack )
1094 UINT i;
1095 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1096 dirstack->num_dirs = 0;
1099 static void free_dirstack( struct dirstack *dirstack )
1101 clear_dirstack( dirstack );
1102 heap_free( dirstack->dirs );
1103 heap_free( dirstack->len_dirs );
1104 heap_free( dirstack );
1107 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1109 UINT size, i = dirstack->num_dirs;
1111 if (!dir) return FALSE;
1113 if (i == dirstack->num_allocated)
1115 WCHAR **tmp;
1116 UINT *len_tmp;
1118 size = dirstack->num_allocated * 2;
1119 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1120 dirstack->dirs = tmp;
1121 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1122 dirstack->len_dirs = len_tmp;
1123 dirstack->num_allocated = size;
1125 dirstack->dirs[i] = dir;
1126 dirstack->len_dirs[i] = len;
1127 dirstack->num_dirs++;
1128 return TRUE;
1131 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1133 if (!dirstack->num_dirs)
1135 *len = 0;
1136 return NULL;
1138 dirstack->num_dirs--;
1139 *len = dirstack->len_dirs[dirstack->num_dirs];
1140 return dirstack->dirs[dirstack->num_dirs];
1143 static const WCHAR *peek_dir( struct dirstack *dirstack )
1145 if (!dirstack->num_dirs) return NULL;
1146 return dirstack->dirs[dirstack->num_dirs - 1];
1149 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1151 UINT i = 0;
1152 WCHAR *ret;
1154 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1155 ret[i++] = drive;
1156 ret[i++] = ':';
1157 ret[i++] = '\\';
1158 if (path && len)
1160 memcpy( ret + i, path, len * sizeof(WCHAR) );
1161 i += len;
1162 ret[i++] = '\\';
1164 ret[i++] = '*';
1165 ret[i] = 0;
1166 return ret;
1169 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1171 UINT i = 0, len = 0;
1172 const WCHAR *p;
1173 WCHAR *ret;
1175 for (p = path; *p; p++)
1177 if (*p == '\\') len += 2;
1178 else len++;
1180 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1181 ret[i++] = drive;
1182 ret[i++] = ':';
1183 ret[i++] = '\\';
1184 ret[i++] = '\\';
1185 for (p = path; *p; p++)
1187 if (*p != '\\') ret[i++] = *p;
1188 else
1190 ret[i++] = '\\';
1191 ret[i++] = '\\';
1194 ret[i] = 0;
1195 return ret;
1198 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1200 const WCHAR *p = path, *start;
1201 UINT len, i;
1202 WCHAR *ret;
1204 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1205 start = path + 4;
1206 len = strlenW( start );
1207 p = start + len - 1;
1208 if (*p == '\\') return NULL;
1210 while (p >= start && *p != '\\') { len--; p--; };
1211 while (p >= start && *p == '\\') { len--; p--; };
1213 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1214 for (i = 0, p = start; p < start + len; p++)
1216 if (p[0] == '\\' && p[1] == '\\')
1218 ret[i++] = '\\';
1219 p++;
1221 else ret[i++] = *p;
1223 ret[i] = 0;
1224 *ret_len = i;
1225 return ret;
1228 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1230 UINT i;
1231 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1232 return FALSE;
1235 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1236 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1238 const struct expr *left, *right;
1240 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1242 left = cond->u.expr.left;
1243 right = cond->u.expr.right;
1244 if (cond->u.expr.op == OP_EQ)
1246 UINT len;
1247 WCHAR *path;
1248 const WCHAR *str = NULL;
1250 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1251 !strcmpW( left->u.propval->name, prop_nameW ) &&
1252 toupperW( right->u.sval[0] ) == toupperW( root ))
1254 str = right->u.sval;
1256 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1257 !strcmpW( right->u.propval->name, prop_nameW ) &&
1258 toupperW( left->u.sval[0] ) == toupperW( root ))
1260 str = left->u.sval;
1262 if (str && (path = build_dirname( str, &len )))
1264 if (seen_dir( dirstack, path ))
1266 heap_free( path );
1267 return ++*count;
1269 else if (push_dir( dirstack, path, len )) return ++*count;
1270 heap_free( path );
1271 return *count = 0;
1274 else if (cond->u.expr.op == OP_OR)
1276 UINT left_count = 0, right_count = 0;
1278 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1279 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1280 return *count += left_count + right_count;
1282 return *count = 0;
1285 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1287 UINT len_path = 0, len_segment = strlenW( segment );
1288 WCHAR *ret;
1290 *len = 0;
1291 if (path) len_path = strlenW( path );
1292 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1293 if (path && len_path)
1295 memcpy( ret, path, len_path * sizeof(WCHAR) );
1296 ret[len_path] = '\\';
1297 *len += len_path + 1;
1299 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1300 *len += len_segment;
1301 ret[*len] = 0;
1302 return ret;
1305 static WCHAR *get_file_version( const WCHAR *filename )
1307 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1308 VS_FIXEDFILEINFO *info;
1309 DWORD size;
1310 void *block;
1311 WCHAR *ret;
1313 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1314 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1316 heap_free( ret );
1317 return NULL;
1319 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1320 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1322 heap_free( block );
1323 heap_free( ret );
1324 return NULL;
1326 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1327 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1328 heap_free( block );
1329 return ret;
1332 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1334 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1335 struct record_datafile *rec;
1336 UINT i, len, row = 0, offset = 0, num_expected_rows;
1337 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1338 DWORD drives = GetLogicalDrives();
1339 WIN32_FIND_DATAW data;
1340 HANDLE handle;
1341 struct dirstack *dirstack;
1342 enum fill_status status = FILL_STATUS_UNFILTERED;
1344 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1346 dirstack = alloc_dirstack(2);
1348 for (i = 0; i < sizeof(drives); i++)
1350 if (!(drives & (1 << i))) continue;
1352 root[0] = 'A' + i;
1353 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1355 num_expected_rows = 0;
1356 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1358 for (;;)
1360 path = pop_dir( dirstack, &len );
1361 if (!(glob = build_glob( root[0], path, len )))
1363 status = FILL_STATUS_FAILED;
1364 goto done;
1366 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1370 if (!resize_table( table, row + 1, sizeof(*rec) ))
1372 status = FILL_STATUS_FAILED;
1373 FindClose( handle );
1374 goto done;
1376 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1377 new_path = append_path( path, data.cFileName, &len );
1379 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1381 if (push_dir( dirstack, new_path, len )) continue;
1382 heap_free( new_path );
1383 FindClose( handle );
1384 status = FILL_STATUS_FAILED;
1385 goto done;
1387 rec = (struct record_datafile *)(table->data + offset);
1388 rec->name = build_name( root[0], new_path );
1389 rec->version = get_file_version( rec->name );
1390 if (!match_row( table, row, cond, &status ))
1392 free_row_values( table, row );
1393 continue;
1395 else if (num_expected_rows && row == num_expected_rows - 1)
1397 row++;
1398 FindClose( handle );
1399 status = FILL_STATUS_FILTERED;
1400 goto done;
1402 offset += sizeof(*rec);
1403 row++;
1405 while (FindNextFileW( handle, &data ));
1406 FindClose( handle );
1408 if (!peek_dir( dirstack )) break;
1409 heap_free( glob );
1410 heap_free( path );
1414 done:
1415 free_dirstack( dirstack );
1416 heap_free( glob );
1417 heap_free( path );
1419 TRACE("created %u rows\n", row);
1420 table->num_rows = row;
1421 return status;
1424 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1426 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1427 struct record_directory *rec;
1428 UINT i, len, row = 0, offset = 0, num_expected_rows;
1429 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1430 DWORD drives = GetLogicalDrives();
1431 WIN32_FIND_DATAW data;
1432 HANDLE handle;
1433 struct dirstack *dirstack;
1434 enum fill_status status = FILL_STATUS_UNFILTERED;
1436 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1438 dirstack = alloc_dirstack(2);
1440 for (i = 0; i < sizeof(drives); i++)
1442 if (!(drives & (1 << i))) continue;
1444 root[0] = 'A' + i;
1445 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1447 num_expected_rows = 0;
1448 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1450 for (;;)
1452 path = pop_dir( dirstack, &len );
1453 if (!(glob = build_glob( root[0], path, len )))
1455 status = FILL_STATUS_FAILED;
1456 goto done;
1458 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1462 if (!resize_table( table, row + 1, sizeof(*rec) ))
1464 FindClose( handle );
1465 status = FILL_STATUS_FAILED;
1466 goto done;
1468 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1469 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1470 continue;
1472 new_path = append_path( path, data.cFileName, &len );
1473 if (!(push_dir( dirstack, new_path, len )))
1475 heap_free( new_path );
1476 FindClose( handle );
1477 status = FILL_STATUS_FAILED;
1478 goto done;
1480 rec = (struct record_directory *)(table->data + offset);
1481 rec->accessmask = FILE_ALL_ACCESS;
1482 rec->name = build_name( root[0], new_path );
1483 if (!match_row( table, row, cond, &status ))
1485 free_row_values( table, row );
1486 continue;
1488 else if (num_expected_rows && row == num_expected_rows - 1)
1490 row++;
1491 FindClose( handle );
1492 status = FILL_STATUS_FILTERED;
1493 goto done;
1495 offset += sizeof(*rec);
1496 row++;
1498 while (FindNextFileW( handle, &data ));
1499 FindClose( handle );
1501 if (!peek_dir( dirstack )) break;
1502 heap_free( glob );
1503 heap_free( path );
1507 done:
1508 free_dirstack( dirstack );
1509 heap_free( glob );
1510 heap_free( path );
1512 TRACE("created %u rows\n", row);
1513 table->num_rows = row;
1514 return status;
1517 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1519 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1520 ULARGE_INTEGER free;
1521 DISK_GEOMETRY_EX info;
1522 HANDLE handle;
1523 DWORD bytes_returned;
1525 free.QuadPart = 512 * 1024 * 1024;
1526 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1528 root[4] = dir[0];
1529 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1530 if (handle != INVALID_HANDLE_VALUE)
1532 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
1533 *disksize = info.DiskSize.QuadPart;
1534 CloseHandle( handle );
1536 return free.QuadPart;
1539 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1541 static const WCHAR fmtW[] =
1542 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1543 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1544 struct record_diskdrive *rec;
1545 UINT i, row = 0, offset = 0, index = 0, type;
1546 UINT64 size = 1024 * 1024 * 1024;
1547 DWORD drives = GetLogicalDrives();
1548 enum fill_status status = FILL_STATUS_UNFILTERED;
1550 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1552 for (i = 0; i < sizeof(drives); i++)
1554 if (drives & (1 << i))
1556 root[0] = 'A' + i;
1557 type = GetDriveTypeW( root );
1558 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1559 continue;
1561 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1563 rec = (struct record_diskdrive *)(table->data + offset);
1564 sprintfW( device_id, fmtW, index );
1565 rec->device_id = heap_strdupW( device_id );
1566 rec->index = index;
1567 rec->interfacetype = diskdrive_interfacetypeW;
1568 rec->manufacturer = diskdrive_manufacturerW;
1569 if (type == DRIVE_FIXED)
1570 rec->mediatype = diskdrive_mediatype_fixedW;
1571 else
1572 rec->mediatype = diskdrive_mediatype_removableW;
1573 rec->model = diskdrive_modelW;
1574 rec->serialnumber = diskdrive_serialW;
1575 get_freespace( root, &size );
1576 rec->size = size;
1577 if (!match_row( table, row, cond, &status ))
1579 free_row_values( table, row );
1580 continue;
1582 offset += sizeof(*rec);
1583 index++;
1584 row++;
1587 TRACE("created %u rows\n", row);
1588 table->num_rows = row;
1589 return status;
1592 static WCHAR *get_filesystem( const WCHAR *root )
1594 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1595 WCHAR buffer[MAX_PATH + 1];
1597 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1598 return heap_strdupW( buffer );
1599 return heap_strdupW( ntfsW );
1602 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1604 static const WCHAR fmtW[] =
1605 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1606 WCHAR device_id[32], root[] = {'A',':','\\',0};
1607 struct record_diskpartition *rec;
1608 UINT i, row = 0, offset = 0, type, index = 0;
1609 UINT64 size = 1024 * 1024 * 1024;
1610 DWORD drives = GetLogicalDrives();
1611 enum fill_status status = FILL_STATUS_UNFILTERED;
1613 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1615 for (i = 0; i < sizeof(drives); i++)
1617 if (drives & (1 << i))
1619 root[0] = 'A' + i;
1620 type = GetDriveTypeW( root );
1621 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1622 continue;
1624 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1626 rec = (struct record_diskpartition *)(table->data + offset);
1627 rec->bootable = (i == 2) ? -1 : 0;
1628 rec->bootpartition = (i == 2) ? -1 : 0;
1629 sprintfW( device_id, fmtW, index );
1630 rec->device_id = heap_strdupW( device_id );
1631 rec->diskindex = index;
1632 rec->index = 0;
1633 rec->pnpdevice_id = heap_strdupW( device_id );
1634 get_freespace( root, &size );
1635 rec->size = size;
1636 rec->startingoffset = 0;
1637 rec->type = get_filesystem( root );
1638 if (!match_row( table, row, cond, &status ))
1640 free_row_values( table, row );
1641 continue;
1643 offset += sizeof(*rec);
1644 row++;
1645 index++;
1648 TRACE("created %u rows\n", row);
1649 table->num_rows = row;
1650 return status;
1653 static WCHAR *get_volumeserialnumber( const WCHAR *root )
1655 static const WCHAR fmtW[] = {'%','0','8','X',0};
1656 DWORD serial = 0;
1657 WCHAR buffer[9];
1659 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
1660 sprintfW( buffer, fmtW, serial );
1661 return heap_strdupW( buffer );
1664 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1666 static const WCHAR fmtW[] = {'%','c',':',0};
1667 WCHAR device_id[3], root[] = {'A',':','\\',0};
1668 struct record_logicaldisk *rec;
1669 UINT i, row = 0, offset = 0, type;
1670 UINT64 size = 1024 * 1024 * 1024;
1671 DWORD drives = GetLogicalDrives();
1672 enum fill_status status = FILL_STATUS_UNFILTERED;
1674 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1676 for (i = 0; i < sizeof(drives); i++)
1678 if (drives & (1 << i))
1680 root[0] = 'A' + i;
1681 type = GetDriveTypeW( root );
1682 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1683 continue;
1685 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1687 rec = (struct record_logicaldisk *)(table->data + offset);
1688 sprintfW( device_id, fmtW, 'A' + i );
1689 rec->device_id = heap_strdupW( device_id );
1690 rec->drivetype = type;
1691 rec->filesystem = get_filesystem( root );
1692 rec->freespace = get_freespace( root, &size );
1693 rec->name = heap_strdupW( device_id );
1694 rec->size = size;
1695 rec->volumeserialnumber = get_volumeserialnumber( root );
1696 if (!match_row( table, row, cond, &status ))
1698 free_row_values( table, row );
1699 continue;
1701 offset += sizeof(*rec);
1702 row++;
1705 TRACE("created %u rows\n", row);
1706 table->num_rows = row;
1707 return status;
1710 static UINT16 get_connection_status( IF_OPER_STATUS status )
1712 switch (status)
1714 case IfOperStatusDown:
1715 return 0; /* Disconnected */
1716 case IfOperStatusUp:
1717 return 2; /* Connected */
1718 default:
1719 ERR("unhandled status %u\n", status);
1720 break;
1722 return 0;
1724 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1726 static const WCHAR fmtW[] =
1727 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1728 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1729 WCHAR *ret;
1731 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1732 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1733 return ret;
1735 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1737 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1738 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1739 static const WCHAR firewireW[] = {'1','3','9','4',0};
1740 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1742 switch (type)
1744 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1745 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1746 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1747 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1748 default: *physical = 0; return NULL;
1752 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1754 static const WCHAR fmtW[] = {'%','u',0};
1755 WCHAR device_id[11];
1756 struct record_networkadapter *rec;
1757 IP_ADAPTER_ADDRESSES *aa, *buffer;
1758 UINT row = 0, offset = 0, count = 0;
1759 DWORD size = 0, ret;
1760 int physical;
1761 enum fill_status status = FILL_STATUS_UNFILTERED;
1763 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1764 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1766 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1767 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1769 heap_free( buffer );
1770 return FILL_STATUS_FAILED;
1772 for (aa = buffer; aa; aa = aa->Next)
1774 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1776 if (!resize_table( table, count, sizeof(*rec) ))
1778 heap_free( buffer );
1779 return FILL_STATUS_FAILED;
1781 for (aa = buffer; aa; aa = aa->Next)
1783 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1785 rec = (struct record_networkadapter *)(table->data + offset);
1786 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1787 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1788 rec->device_id = heap_strdupW( device_id );
1789 rec->index = aa->u.s.IfIndex;
1790 rec->interface_index = aa->u.s.IfIndex;
1791 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1792 rec->manufacturer = compsys_manufacturerW;
1793 rec->name = heap_strdupW( aa->FriendlyName );
1794 rec->netconnection_status = get_connection_status( aa->OperStatus );
1795 rec->physicaladapter = physical;
1796 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1797 rec->speed = 1000000;
1798 if (!match_row( table, row, cond, &status ))
1800 free_row_values( table, row );
1801 continue;
1803 offset += sizeof(*rec);
1804 row++;
1806 TRACE("created %u rows\n", row);
1807 table->num_rows = row;
1809 heap_free( buffer );
1810 return status;
1813 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1815 struct record_networkadapterconfig *rec;
1816 IP_ADAPTER_ADDRESSES *aa, *buffer;
1817 UINT row = 0, offset = 0, count = 0;
1818 DWORD size = 0, ret;
1819 enum fill_status status = FILL_STATUS_UNFILTERED;
1821 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1822 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1824 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1825 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1827 heap_free( buffer );
1828 return FILL_STATUS_FAILED;
1830 for (aa = buffer; aa; aa = aa->Next)
1832 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1834 if (!resize_table( table, count, sizeof(*rec) ))
1836 heap_free( buffer );
1837 return FILL_STATUS_FAILED;
1839 for (aa = buffer; aa; aa = aa->Next)
1841 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1843 rec = (struct record_networkadapterconfig *)(table->data + offset);
1844 rec->index = aa->u.s.IfIndex;
1845 rec->ipconnectionmetric = 20;
1846 rec->ipenabled = -1;
1847 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1848 if (!match_row( table, row, cond, &status ))
1850 free_row_values( table, row );
1851 continue;
1853 offset += sizeof(*rec);
1854 row++;
1856 TRACE("created %u rows\n", row);
1857 table->num_rows = row;
1859 heap_free( buffer );
1860 return status;
1863 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
1865 struct record_physicalmemory *rec;
1866 enum fill_status status = FILL_STATUS_UNFILTERED;
1867 UINT row = 0;
1869 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1871 rec = (struct record_physicalmemory *)table->data;
1872 rec->capacity = get_total_physical_memory();
1873 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1874 else row++;
1876 TRACE("created %u rows\n", row);
1877 table->num_rows = row;
1878 return status;
1881 static WCHAR *get_cmdline( DWORD process_id )
1883 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1884 return NULL; /* FIXME handle different process case */
1887 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1889 static const WCHAR fmtW[] = {'%','u',0};
1890 WCHAR handle[11];
1891 struct record_process *rec;
1892 PROCESSENTRY32W entry;
1893 HANDLE snap;
1894 enum fill_status status = FILL_STATUS_FAILED;
1895 UINT row = 0, offset = 0;
1897 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1898 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1900 entry.dwSize = sizeof(entry);
1901 if (!Process32FirstW( snap, &entry )) goto done;
1902 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1906 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1908 rec = (struct record_process *)(table->data + offset);
1909 rec->caption = heap_strdupW( entry.szExeFile );
1910 rec->commandline = get_cmdline( entry.th32ProcessID );
1911 rec->description = heap_strdupW( entry.szExeFile );
1912 sprintfW( handle, fmtW, entry.th32ProcessID );
1913 rec->handle = heap_strdupW( handle );
1914 rec->name = heap_strdupW( entry.szExeFile );
1915 rec->process_id = entry.th32ProcessID;
1916 rec->pprocess_id = entry.th32ParentProcessID;
1917 rec->thread_count = entry.cntThreads;
1918 rec->get_owner = process_get_owner;
1919 if (!match_row( table, row, cond, &status ))
1921 free_row_values( table, row );
1922 continue;
1924 offset += sizeof(*rec);
1925 row++;
1926 } while (Process32NextW( snap, &entry ));
1928 TRACE("created %u rows\n", row);
1929 table->num_rows = row;
1930 status = FILL_STATUS_UNFILTERED;
1932 done:
1933 CloseHandle( snap );
1934 return status;
1937 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1939 #ifdef __i386__
1940 __asm__("pushl %%ebx\n\t"
1941 "cpuid\n\t"
1942 "movl %%ebx, %%esi\n\t"
1943 "popl %%ebx"
1944 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1945 : "0" (ax));
1946 #endif
1949 static void get_processor_id( WCHAR *processor_id )
1951 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1952 unsigned int regs[4] = {0, 0, 0, 0};
1954 do_cpuid( 1, regs );
1955 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1957 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1959 unsigned int i;
1960 unsigned char *p = (unsigned char *)regs;
1962 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1963 buffer[i] = 0;
1965 static void get_processor_manufacturer( WCHAR *manufacturer )
1967 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1969 do_cpuid( 0, regs );
1970 tmp = regs[2]; /* swap edx and ecx */
1971 regs[2] = regs[3];
1972 regs[3] = tmp;
1974 regs_to_str( regs + 1, 12, manufacturer );
1976 static void get_processor_name( WCHAR *name )
1978 unsigned int regs[4] = {0, 0, 0, 0};
1980 do_cpuid( 0x80000000, regs );
1981 if (regs[0] >= 0x80000004)
1983 do_cpuid( 0x80000002, regs );
1984 regs_to_str( regs, 16, name );
1985 do_cpuid( 0x80000003, regs );
1986 regs_to_str( regs, 16, name + 16 );
1987 do_cpuid( 0x80000004, regs );
1988 regs_to_str( regs, 16, name + 32 );
1991 static UINT get_processor_currentclockspeed( UINT index )
1993 PROCESSOR_POWER_INFORMATION *info;
1994 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1995 NTSTATUS status;
1997 if ((info = heap_alloc( size )))
1999 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2000 if (!status) ret = info[index].CurrentMhz;
2001 heap_free( info );
2003 return ret;
2005 static UINT get_processor_maxclockspeed( UINT index )
2007 PROCESSOR_POWER_INFORMATION *info;
2008 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2009 NTSTATUS status;
2011 if ((info = heap_alloc( size )))
2013 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2014 if (!status) ret = info[index].MaxMhz;
2015 heap_free( info );
2017 return ret;
2019 static const WCHAR *get_osarchitecture(void)
2021 SYSTEM_INFO info;
2022 GetNativeSystemInfo( &info );
2023 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2024 return os_32bitW;
2027 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
2029 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
2030 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
2031 struct record_processor *rec;
2032 UINT i, offset = 0, num_cores, num_logical_processors, count = get_processor_count();
2033 enum fill_status status = FILL_STATUS_UNFILTERED;
2035 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
2037 get_processor_id( processor_id );
2038 get_processor_manufacturer( manufacturer );
2039 get_processor_name( name );
2041 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2042 num_cores /= count;
2044 for (i = 0; i < count; i++)
2046 rec = (struct record_processor *)(table->data + offset);
2047 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2048 rec->cpu_status = 1; /* CPU Enabled */
2049 rec->currentclockspeed = get_processor_currentclockspeed( i );
2050 sprintfW( device_id, fmtW, i );
2051 rec->device_id = heap_strdupW( device_id );
2052 rec->family = 2; /* Unknown */
2053 rec->manufacturer = heap_strdupW( manufacturer );
2054 rec->maxclockspeed = get_processor_maxclockspeed( i );
2055 rec->name = heap_strdupW( name );
2056 rec->num_cores = num_cores;
2057 rec->num_logical_processors = num_logical_processors;
2058 rec->processor_id = heap_strdupW( processor_id );
2059 rec->unique_id = NULL;
2060 if (!match_row( table, i, cond, &status ))
2062 free_row_values( table, i );
2063 continue;
2065 offset += sizeof(*rec);
2068 TRACE("created %u rows\n", count);
2069 table->num_rows = count;
2070 return status;
2073 static WCHAR *get_lastbootuptime(void)
2075 static const WCHAR fmtW[] =
2076 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2077 '.','%','0','6','u','+','0','0','0',0};
2078 SYSTEM_TIMEOFDAY_INFORMATION ti;
2079 TIME_FIELDS tf;
2080 WCHAR *ret;
2082 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2084 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2085 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2086 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2087 return ret;
2089 static WCHAR *get_localdatetime(void)
2091 static const WCHAR fmtW[] =
2092 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2093 '.','%','0','6','u','%','+','0','3','d',0};
2094 TIME_ZONE_INFORMATION tzi;
2095 SYSTEMTIME st;
2096 WCHAR *ret;
2097 DWORD Status;
2098 LONG Bias;
2100 Status = GetTimeZoneInformation(&tzi);
2102 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2103 Bias = tzi.Bias;
2104 if(Status == TIME_ZONE_ID_DAYLIGHT)
2105 Bias+= tzi.DaylightBias;
2106 else
2107 Bias+= tzi.StandardBias;
2108 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2110 GetLocalTime(&st);
2111 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2112 return ret;
2114 static WCHAR *get_systemdirectory(void)
2116 void *redir;
2117 WCHAR *ret;
2119 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2120 Wow64DisableWow64FsRedirection( &redir );
2121 GetSystemDirectoryW( ret, MAX_PATH );
2122 Wow64RevertWow64FsRedirection( redir );
2123 return ret;
2125 static WCHAR *get_codeset(void)
2127 static const WCHAR fmtW[] = {'%','u',0};
2128 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2129 if (ret) sprintfW( ret, fmtW, GetACP() );
2130 return ret;
2132 static WCHAR *get_countrycode(void)
2134 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2135 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2136 return ret;
2138 static WCHAR *get_locale(void)
2140 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2141 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2142 return ret;
2145 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2147 struct record_operatingsystem *rec;
2148 enum fill_status status = FILL_STATUS_UNFILTERED;
2149 UINT row = 0;
2151 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2153 rec = (struct record_operatingsystem *)table->data;
2154 rec->buildnumber = os_buildnumberW;
2155 rec->caption = os_captionW;
2156 rec->codeset = get_codeset();
2157 rec->countrycode = get_countrycode();
2158 rec->csdversion = os_csdversionW;
2159 rec->installdate = os_installdateW;
2160 rec->lastbootuptime = get_lastbootuptime();
2161 rec->localdatetime = get_localdatetime();
2162 rec->locale = get_locale();
2163 rec->name = os_nameW;
2164 rec->osarchitecture = get_osarchitecture();
2165 rec->oslanguage = GetSystemDefaultLangID();
2166 rec->osproductsuite = 2461140; /* Windows XP Professional */
2167 rec->ostype = 18; /* WINNT */
2168 rec->serialnumber = os_serialnumberW;
2169 rec->servicepackmajor = 3;
2170 rec->servicepackminor = 0;
2171 rec->suitemask = 272; /* Single User + Terminal */
2172 rec->systemdirectory = get_systemdirectory();
2173 rec->totalvisiblememorysize = get_total_physical_memory() / 1024;
2174 rec->version = os_versionW;
2175 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2176 else row++;
2178 TRACE("created %u rows\n", row);
2179 table->num_rows = row;
2180 return status;
2183 static const WCHAR *get_service_type( DWORD type )
2185 static const WCHAR filesystem_driverW[] =
2186 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2187 static const WCHAR kernel_driverW[] =
2188 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2189 static const WCHAR own_processW[] =
2190 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2191 static const WCHAR share_processW[] =
2192 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2194 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2195 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2196 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2197 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2198 else ERR("unhandled type 0x%08x\n", type);
2199 return NULL;
2201 static const WCHAR *get_service_state( DWORD state )
2203 static const WCHAR runningW[] =
2204 {'R','u','n','n','i','n','g',0};
2205 static const WCHAR start_pendingW[] =
2206 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2207 static const WCHAR stop_pendingW[] =
2208 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2209 static const WCHAR stoppedW[] =
2210 {'S','t','o','p','p','e','d',0};
2211 static const WCHAR unknownW[] =
2212 {'U','n','k','n','o','w','n',0};
2214 switch (state)
2216 case SERVICE_STOPPED: return stoppedW;
2217 case SERVICE_START_PENDING: return start_pendingW;
2218 case SERVICE_STOP_PENDING: return stop_pendingW;
2219 case SERVICE_RUNNING: return runningW;
2220 default:
2221 ERR("unknown state %u\n", state);
2222 return unknownW;
2225 static const WCHAR *get_service_startmode( DWORD mode )
2227 static const WCHAR bootW[] = {'B','o','o','t',0};
2228 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2229 static const WCHAR autoW[] = {'A','u','t','o',0};
2230 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2231 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2232 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2234 switch (mode)
2236 case SERVICE_BOOT_START: return bootW;
2237 case SERVICE_SYSTEM_START: return systemW;
2238 case SERVICE_AUTO_START: return autoW;
2239 case SERVICE_DEMAND_START: return manualW;
2240 case SERVICE_DISABLED: return disabledW;
2241 default:
2242 ERR("unknown mode 0x%x\n", mode);
2243 return unknownW;
2246 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2248 QUERY_SERVICE_CONFIGW *config = NULL;
2249 SC_HANDLE service;
2250 DWORD size;
2252 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2253 QueryServiceConfigW( service, NULL, 0, &size );
2254 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2255 if (!(config = heap_alloc( size ))) goto done;
2256 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2257 heap_free( config );
2258 config = NULL;
2260 done:
2261 CloseServiceHandle( service );
2262 return config;
2265 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2267 struct record_service *rec;
2268 SC_HANDLE manager;
2269 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2270 SERVICE_STATUS_PROCESS *status;
2271 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2272 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2273 UINT i, row = 0, offset = 0, size = 256, needed, count;
2274 enum fill_status fill_status = FILL_STATUS_FAILED;
2275 BOOL ret;
2277 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2278 if (!(services = heap_alloc( size ))) goto done;
2280 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2281 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2282 &count, NULL, NULL );
2283 if (!ret)
2285 if (GetLastError() != ERROR_MORE_DATA) goto done;
2286 size = needed;
2287 if (!(tmp = heap_realloc( services, size ))) goto done;
2288 services = tmp;
2289 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2290 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2291 &count, NULL, NULL );
2292 if (!ret) goto done;
2294 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2296 GetComputerNameW( sysnameW, &len );
2297 fill_status = FILL_STATUS_UNFILTERED;
2299 for (i = 0; i < count; i++)
2301 QUERY_SERVICE_CONFIGW *config;
2303 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2305 status = &services[i].ServiceStatusProcess;
2306 rec = (struct record_service *)(table->data + offset);
2307 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2308 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2309 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2310 rec->name = heap_strdupW( services[i].lpServiceName );
2311 rec->process_id = status->dwProcessId;
2312 rec->servicetype = get_service_type( status->dwServiceType );
2313 rec->startmode = get_service_startmode( config->dwStartType );
2314 rec->state = get_service_state( status->dwCurrentState );
2315 rec->systemname = heap_strdupW( sysnameW );
2316 rec->pause_service = service_pause_service;
2317 rec->resume_service = service_resume_service;
2318 rec->start_service = service_start_service;
2319 rec->stop_service = service_stop_service;
2320 heap_free( config );
2321 if (!match_row( table, row, cond, &fill_status ))
2323 free_row_values( table, row );
2324 continue;
2326 offset += sizeof(*rec);
2327 row++;
2330 TRACE("created %u rows\n", row);
2331 table->num_rows = row;
2333 done:
2334 CloseServiceHandle( manager );
2335 heap_free( services );
2336 return fill_status;
2339 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2341 HDC hdc = GetDC( NULL );
2342 UINT32 ret;
2344 if (!hdc) return 32;
2345 ret = GetDeviceCaps( hdc, BITSPIXEL );
2346 *hres = GetDeviceCaps( hdc, HORZRES );
2347 *vres = GetDeviceCaps( hdc, VERTRES );
2348 ReleaseDC( NULL, hdc );
2349 return ret;
2351 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2353 static const WCHAR fmtW[] =
2354 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2355 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2356 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2357 WCHAR *ret;
2359 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2360 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2361 return ret;
2364 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2367 struct record_videocontroller *rec;
2368 HRESULT hr;
2369 IDXGIFactory *factory = NULL;
2370 IDXGIAdapter *adapter = NULL;
2371 DXGI_ADAPTER_DESC desc;
2372 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2373 const WCHAR *name = videocontroller_deviceidW;
2374 enum fill_status status = FILL_STATUS_UNFILTERED;
2375 UINT row = 0;
2377 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2379 memset (&desc, 0, sizeof(desc));
2380 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2381 if (FAILED(hr)) goto done;
2383 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2384 if (FAILED(hr)) goto done;
2386 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2387 if (SUCCEEDED(hr))
2389 vidmem = desc.DedicatedVideoMemory;
2390 name = desc.Description;
2393 done:
2394 rec = (struct record_videocontroller *)table->data;
2395 rec->adapter_dactype = videocontroller_dactypeW;
2396 rec->adapter_ram = vidmem;
2397 rec->availability = 3; /* Running or Full Power */
2398 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2399 rec->current_horizontalres = hres;
2400 rec->current_verticalres = vres;
2401 rec->description = heap_strdupW( name );
2402 rec->device_id = videocontroller_deviceidW;
2403 rec->name = heap_strdupW( name );
2404 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2405 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2406 else row++;
2408 TRACE("created %u rows\n", row);
2409 table->num_rows = row;
2411 if (adapter) IDXGIAdapter_Release( adapter );
2412 if (factory) IDXGIFactory_Release( factory );
2413 return status;
2416 static struct table builtin_classes[] =
2418 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2419 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2420 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2421 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2422 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2423 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2424 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
2425 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2426 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2427 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2428 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2429 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2430 fill_networkadapterconfig },
2431 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2432 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2433 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2434 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
2435 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2436 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2437 { class_processor2W, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2438 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2439 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2440 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2441 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2442 { class_systemsecurityW, SIZEOF(col_systemsecurity), col_systemsecurity, SIZEOF(data_systemsecurity), 0, (BYTE *)data_systemsecurity },
2443 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2446 void init_table_list( void )
2448 static struct list tables = LIST_INIT( tables );
2449 UINT i;
2451 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2452 table_list = &tables;