jscript: Get rid of BSTR in date.c.
[wine] / dlls / wbemprox / builtin.c
1 /*
2  * Copyright 2012 Hans Leidekker for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22
23 #include "config.h"
24 #include <stdarg.h>
25
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
41 #include "wine/debug.h"
42 #include "wbemprox_private.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
45
46 static const WCHAR class_baseboardW[] =
47     {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
48 static const WCHAR class_biosW[] =
49     {'W','i','n','3','2','_','B','I','O','S',0};
50 static const WCHAR class_cdromdriveW[] =
51     {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
52 static const WCHAR class_compsysW[] =
53     {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
54 static const WCHAR class_diskdriveW[] =
55     {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
56 static const WCHAR class_logicaldiskW[] =
57     {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
58 static const WCHAR class_networkadapterW[] =
59     {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
60 static const WCHAR class_osW[] =
61     {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
62 static const WCHAR class_paramsW[] =
63     {'_','_','P','A','R','A','M','E','T','E','R','S',0};
64 static const WCHAR class_processW[] =
65     {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
66 static const WCHAR class_processorW[] =
67     {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
68 static const WCHAR class_serviceW[] =
69     {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
70 static const WCHAR class_sounddeviceW[] =
71     {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
72 static const WCHAR class_stdregprovW[] =
73     {'S','t','d','R','e','g','P','r','o','v',0};
74 static const WCHAR class_videocontrollerW[] =
75     {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
76
77 static const WCHAR prop_adaptertypeW[] =
78     {'A','d','a','p','t','e','r','T','y','p','e',0};
79 static const WCHAR prop_acceptpauseW[] =
80     {'A','c','c','e','p','t','P','a','u','s','e',0};
81 static const WCHAR prop_acceptstopW[] =
82     {'A','c','c','e','p','t','S','t','o','p',0};
83 static const WCHAR prop_adapterramW[] =
84     {'A','d','a','p','t','e','r','R','A','M',0};
85 static const WCHAR prop_captionW[] =
86     {'C','a','p','t','i','o','n',0};
87 static const WCHAR prop_classW[] =
88     {'C','l','a','s','s',0};
89 static const WCHAR prop_commandlineW[] =
90     {'C','o','m','m','a','n','d','L','i','n','e',0};
91 static const WCHAR prop_cpustatusW[] =
92     {'C','p','u','S','t','a','t','u','s',0};
93 static const WCHAR prop_csdversionW[] =
94     {'C','S','D','V','e','r','s','i','o','n',0};
95 static const WCHAR prop_currentbitsperpixelW[] =
96     {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
97 static const WCHAR prop_currenthorizontalresW[] =
98     {'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};
99 static const WCHAR prop_currentverticalresW[] =
100     {'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};
101 static const WCHAR prop_defaultvalueW[] =
102     {'D','e','f','a','u','l','t','V','a','l','u','e',0};
103 static const WCHAR prop_descriptionW[] =
104     {'D','e','s','c','r','i','p','t','i','o','n',0};
105 static const WCHAR prop_deviceidW[] =
106     {'D','e','v','i','c','e','I','d',0};
107 static const WCHAR prop_directionW[] =
108     {'D','i','r','e','c','t','i','o','n',0};
109 static const WCHAR prop_displaynameW[] =
110     {'D','i','s','p','l','a','y','N','a','m','e',0};
111 static const WCHAR prop_domainW[] =
112     {'D','o','m','a','i','n',0};
113 static const WCHAR prop_domainroleW[] =
114     {'D','o','m','a','i','n','R','o','l','e',0};
115 static const WCHAR prop_drivetypeW[] =
116     {'D','r','i','v','e','T','y','p','e',0};
117 static const WCHAR prop_filesystemW[] =
118     {'F','i','l','e','S','y','s','t','e','m',0};
119 static const WCHAR prop_freespaceW[] =
120     {'F','r','e','e','S','p','a','c','e',0};
121 static const WCHAR prop_handleW[] =
122     {'H','a','n','d','l','e',0};
123 static const WCHAR prop_interfaceindexW[] =
124     {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
125 static const WCHAR prop_lastbootuptimeW[] =
126     {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
127 static const WCHAR prop_macaddressW[] =
128     {'M','A','C','A','d','d','r','e','s','s',0};
129 static const WCHAR prop_manufacturerW[] =
130     {'M','a','n','u','f','a','c','t','u','r','e','r',0};
131 static const WCHAR prop_maxclockspeedW[] =
132     {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
133 static const WCHAR prop_methodW[] =
134     {'M','e','t','h','o','d',0};
135 static const WCHAR prop_modelW[] =
136     {'M','o','d','e','l',0};
137 static const WCHAR prop_nameW[] =
138     {'N','a','m','e',0};
139 static const WCHAR prop_netconnectionstatusW[] =
140     {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
141 static const WCHAR prop_numlogicalprocessorsW[] =
142     {'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};
143 static const WCHAR prop_numprocessorsW[] =
144     {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
145 static const WCHAR prop_osarchitectureW[] =
146     {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
147 static const WCHAR prop_oslanguageW[] =
148     {'O','S','L','a','n','g','u','a','g','e',0};
149 static const WCHAR prop_parameterW[] =
150     {'P','a','r','a','m','e','t','e','r',0};
151 static const WCHAR prop_pnpdeviceidW[] =
152     {'P','N','P','D','e','v','i','c','e','I','D',0};
153 static const WCHAR prop_pprocessidW[] =
154     {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
155 static const WCHAR prop_processidW[] =
156     {'P','r','o','c','e','s','s','I','D',0};
157 static const WCHAR prop_processoridW[] =
158     {'P','r','o','c','e','s','s','o','r','I','d',0};
159 static const WCHAR prop_productnameW[] =
160     {'P','r','o','d','u','c','t','N','a','m','e',0};
161 static const WCHAR prop_releasedateW[] =
162     {'R','e','l','e','a','s','e','D','a','t','e',0};
163 static const WCHAR prop_serialnumberW[] =
164     {'S','e','r','i','a','l','N','u','m','b','e','r',0};
165 static const WCHAR prop_servicetypeW[] =
166     {'S','e','r','v','i','c','e','T','y','p','e',0};
167 static const WCHAR prop_startmodeW[] =
168     {'S','t','a','r','t','M','o','d','e',0};
169 static const WCHAR prop_sizeW[] =
170     {'S','i','z','e',0};
171 static const WCHAR prop_speedW[] =
172     {'S','p','e','e','d',0};
173 static const WCHAR prop_stateW[] =
174     {'S','t','a','t','e',0};
175 static const WCHAR prop_systemdirectoryW[] =
176     {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
177 static const WCHAR prop_systemnameW[] =
178     {'S','y','s','t','e','m','N','a','m','e',0};
179 static const WCHAR prop_tagW[] =
180     {'T','a','g',0};
181 static const WCHAR prop_threadcountW[] =
182     {'T','h','r','e','a','d','C','o','u','n','t',0};
183 static const WCHAR prop_totalphysicalmemoryW[] =
184     {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
185 static const WCHAR prop_typeW[] =
186     {'T','y','p','e',0};
187 static const WCHAR prop_uniqueidW[] =
188     {'U','n','i','q','u','e','I','d',0};
189 static const WCHAR prop_versionW[] =
190     {'V','e','r','s','i','o','n',0};
191
192 static const WCHAR method_enumkeyW[] =
193     {'E','n','u','m','K','e','y',0};
194 static const WCHAR method_enumvaluesW[] =
195     {'E','n','u','m','V','a','l','u','e','s',0};
196
197 static const WCHAR param_defkeyW[] =
198     {'h','D','e','f','K','e','y',0};
199 static const WCHAR param_namesW[] =
200     {'N','a','m','e','s',0};
201 static const WCHAR param_returnvalueW[] =
202     {'R','e','t','u','r','n','V','a','l','u','e',0};
203 static const WCHAR param_subkeynameW[] =
204     {'s','S','u','b','K','e','y','N','a','m','e',0};
205 static const WCHAR param_typesW[] =
206     {'T','y','p','e','s',0};
207
208 /* column definitions must be kept in sync with record structures below */
209 static const struct column col_baseboard[] =
210 {
211     { prop_manufacturerW,  CIM_STRING },
212     { prop_serialnumberW,  CIM_STRING },
213     { prop_tagW,           CIM_STRING|COL_FLAG_KEY }
214 };
215 static const struct column col_bios[] =
216 {
217     { prop_descriptionW,  CIM_STRING },
218     { prop_manufacturerW, CIM_STRING },
219     { prop_releasedateW,  CIM_DATETIME },
220     { prop_serialnumberW, CIM_STRING },
221     { prop_versionW,      CIM_STRING|COL_FLAG_KEY }
222 };
223 static const struct column col_cdromdrive[] =
224 {
225     { prop_nameW, CIM_STRING }
226 };
227 static const struct column col_compsys[] =
228 {
229     { prop_descriptionW,          CIM_STRING },
230     { prop_domainW,               CIM_STRING },
231     { prop_domainroleW,           CIM_UINT16 },
232     { prop_manufacturerW,         CIM_STRING },
233     { prop_modelW,                CIM_STRING },
234     { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
235     { prop_numprocessorsW,        CIM_UINT32, VT_I4 },
236     { prop_totalphysicalmemoryW,  CIM_UINT64 }
237 };
238 static const struct column col_diskdrive[] =
239 {
240     { prop_manufacturerW, CIM_STRING },
241     { prop_modelW,        CIM_STRING },
242     { prop_serialnumberW, CIM_STRING }
243 };
244 static const struct column col_logicaldisk[] =
245 {
246     { prop_deviceidW,   CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
247     { prop_drivetypeW,  CIM_UINT32, VT_I4 },
248     { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
249     { prop_freespaceW,  CIM_UINT64 },
250     { prop_sizeW,       CIM_UINT64 }
251 };
252 static const struct column col_networkadapter[] =
253 {
254     { prop_adaptertypeW,         CIM_STRING },
255     { prop_deviceidW,            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
256     { prop_interfaceindexW,      CIM_UINT32, VT_I4 },
257     { prop_macaddressW,          CIM_STRING|COL_FLAG_DYNAMIC },
258     { prop_manufacturerW,        CIM_STRING },
259     { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
260     { prop_pnpdeviceidW,         CIM_STRING },
261     { prop_speedW,               CIM_UINT64 }
262 };
263 static const struct column col_os[] =
264 {
265     { prop_captionW,         CIM_STRING },
266     { prop_csdversionW,      CIM_STRING },
267     { prop_lastbootuptimeW,  CIM_DATETIME|COL_FLAG_DYNAMIC },
268     { prop_osarchitectureW,  CIM_STRING },
269     { prop_oslanguageW,      CIM_UINT32, VT_I4 },
270     { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC }
271 };
272 static const struct column col_params[] =
273 {
274     { prop_classW,        CIM_STRING },
275     { prop_methodW,       CIM_STRING },
276     { prop_directionW,    CIM_SINT32 },
277     { prop_parameterW,    CIM_STRING },
278     { prop_typeW,         CIM_UINT32 },
279     { prop_defaultvalueW, CIM_UINT32 }
280 };
281 static const struct column col_process[] =
282 {
283     { prop_captionW,     CIM_STRING|COL_FLAG_DYNAMIC },
284     { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
285     { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
286     { prop_handleW,      CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
287     { prop_pprocessidW,  CIM_UINT32, VT_I4 },
288     { prop_processidW,   CIM_UINT32, VT_I4 },
289     { prop_threadcountW, CIM_UINT32, VT_I4 }
290 };
291 static const struct column col_processor[] =
292 {
293     { prop_cpustatusW,            CIM_UINT16 },
294     { prop_deviceidW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
295     { prop_manufacturerW,         CIM_STRING|COL_FLAG_DYNAMIC },
296     { prop_maxclockspeedW,        CIM_UINT32, VT_I4 },
297     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
298     { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
299     { prop_processoridW,          CIM_STRING|COL_FLAG_DYNAMIC },
300     { prop_uniqueidW,             CIM_STRING }
301 };
302 static const struct column col_service[] =
303 {
304     { prop_acceptpauseW,      CIM_BOOLEAN },
305     { prop_acceptstopW,       CIM_BOOLEAN },
306     { prop_displaynameW,      CIM_STRING|COL_FLAG_DYNAMIC },
307     { prop_nameW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
308     { prop_processidW,        CIM_UINT32 },
309     { prop_servicetypeW,      CIM_STRING },
310     { prop_startmodeW,        CIM_STRING },
311     { prop_stateW,            CIM_STRING },
312     { prop_systemnameW,       CIM_STRING|COL_FLAG_DYNAMIC }
313 };
314 static const struct column col_sounddevice[] =
315 {
316     { prop_productnameW, CIM_STRING }
317 };
318 static const struct column col_stdregprov[] =
319 {
320     { method_enumkeyW,    CIM_OBJECT|COL_FLAG_METHOD },
321     { method_enumvaluesW, CIM_OBJECT|COL_FLAG_METHOD }
322 };
323 static const struct column col_videocontroller[] =
324 {
325     { prop_adapterramW,           CIM_UINT32 },
326     { prop_currentbitsperpixelW,  CIM_UINT32 },
327     { prop_currenthorizontalresW, CIM_UINT32 },
328     { prop_currentverticalresW,   CIM_UINT32 },
329     { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
330     { prop_deviceidW,             CIM_STRING|COL_FLAG_KEY },
331     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC }
332 };
333
334 static const WCHAR baseboard_manufacturerW[] =
335     {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
336 static const WCHAR baseboard_serialnumberW[] =
337     {'N','o','n','e',0};
338 static const WCHAR baseboard_tagW[] =
339     {'B','a','s','e',' ','B','o','a','r','d',0};
340 static const WCHAR bios_descriptionW[] =
341     {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
342 static const WCHAR bios_manufacturerW[] =
343     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
344 static const WCHAR bios_releasedateW[] =
345     {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
346 static const WCHAR bios_serialnumberW[] =
347     {'0',0};
348 static const WCHAR bios_versionW[] =
349     {'W','I','N','E',' ',' ',' ','-',' ','1',0};
350 static const WCHAR cdromdrive_nameW[] =
351     {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
352 static const WCHAR compsys_descriptionW[] =
353     {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
354 static const WCHAR compsys_domainW[] =
355     {'W','O','R','K','G','R','O','U','P',0};
356 static const WCHAR compsys_manufacturerW[] =
357     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
358 static const WCHAR compsys_modelW[] =
359     {'W','i','n','e',0};
360 static const WCHAR diskdrive_modelW[] =
361     {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
362 static const WCHAR diskdrive_manufacturerW[] =
363     {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
364 static const WCHAR networkadapter_pnpdeviceidW[]=
365     {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
366      'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
367      '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
368 static const WCHAR os_captionW[] =
369     {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
370      'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
371 static const WCHAR os_csdversionW[] =
372     {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
373 static const WCHAR os_32bitW[] =
374     {'3','2','-','b','i','t',0};
375 static const WCHAR os_64bitW[] =
376     {'6','4','-','b','i','t',0};
377 static const WCHAR sounddevice_productnameW[] =
378     {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
379 static const WCHAR videocontroller_deviceidW[] =
380     {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
381
382 #include "pshpack1.h"
383 struct record_baseboard
384 {
385     const WCHAR *manufacturer;
386     const WCHAR *serialnumber;
387     const WCHAR *tag;
388 };
389 struct record_bios
390 {
391     const WCHAR *description;
392     const WCHAR *manufacturer;
393     const WCHAR *releasedate;
394     const WCHAR *serialnumber;
395     const WCHAR *version;
396 };
397 struct record_cdromdrive
398 {
399     const WCHAR *name;
400 };
401 struct record_computersystem
402 {
403     const WCHAR *description;
404     const WCHAR *domain;
405     UINT16       domainrole;
406     const WCHAR *manufacturer;
407     const WCHAR *model;
408     UINT32       num_logical_processors;
409     UINT32       num_processors;
410     UINT64       total_physical_memory;
411 };
412 struct record_diskdrive
413 {
414     const WCHAR *manufacturer;
415     const WCHAR *name;
416     const WCHAR *serialnumber;
417 };
418 struct record_logicaldisk
419 {
420     const WCHAR *device_id;
421     UINT32       drivetype;
422     const WCHAR *filesystem;
423     UINT64       freespace;
424     UINT64       size;
425 };
426 struct record_networkadapter
427 {
428     const WCHAR *adaptertype;
429     const WCHAR *device_id;
430     INT32        interface_index;
431     const WCHAR *mac_address;
432     const WCHAR *manufacturer;
433     UINT16       netconnection_status;
434     const WCHAR *pnpdevice_id;
435     UINT64       speed;
436 };
437 struct record_operatingsystem
438 {
439     const WCHAR *caption;
440     const WCHAR *csdversion;
441     const WCHAR *lastbootuptime;
442     const WCHAR *osarchitecture;
443     UINT32       oslanguage;
444     const WCHAR *systemdirectory;
445 };
446 struct record_params
447 {
448     const WCHAR *class;
449     const WCHAR *method;
450     INT32        direction;
451     const WCHAR *parameter;
452     UINT32       type;
453     UINT32       defaultvalue;
454 };
455 struct record_process
456 {
457     const WCHAR *caption;
458     const WCHAR *commandline;
459     const WCHAR *description;
460     const WCHAR *handle;
461     UINT32       pprocess_id;
462     UINT32       process_id;
463     UINT32       thread_count;
464 };
465 struct record_processor
466 {
467     UINT16       cpu_status;
468     const WCHAR *device_id;
469     const WCHAR *manufacturer;
470     UINT32       maxclockspeed;
471     const WCHAR *name;
472     UINT32       num_logical_processors;
473     const WCHAR *processor_id;
474     const WCHAR *unique_id;
475 };
476 struct record_service
477 {
478     int          accept_pause;
479     int          accept_stop;
480     const WCHAR *displayname;
481     const WCHAR *name;
482     UINT32       process_id;
483     const WCHAR *servicetype;
484     const WCHAR *startmode;
485     const WCHAR *state;
486     const WCHAR *systemname;
487 };
488 struct record_sounddevice
489 {
490     const WCHAR *productname;
491 };
492 struct record_stdregprov
493 {
494     class_method *enumkey;
495     class_method *enumvalues;
496 };
497 struct record_videocontroller
498 {
499     UINT32       adapter_ram;
500     UINT32       current_bitsperpixel;
501     UINT32       current_horizontalres;
502     UINT32       current_verticalres;
503     const WCHAR *description;
504     const WCHAR *device_id;
505     const WCHAR *name;
506 };
507 #include "poppack.h"
508
509 static HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
510 {
511     FIXME("\n");
512     return E_NOTIMPL;
513 }
514 static HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
515 {
516     FIXME("\n");
517     return E_NOTIMPL;
518 }
519
520 static const struct record_baseboard data_baseboard[] =
521 {
522     { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
523 };
524 static const struct record_bios data_bios[] =
525 {
526     { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW, bios_versionW }
527 };
528 static const struct record_cdromdrive data_cdromdrive[] =
529 {
530     { cdromdrive_nameW }
531 };
532 static const struct record_diskdrive data_diskdrive[] =
533 {
534     { diskdrive_manufacturerW, diskdrive_modelW }
535 };
536 static const struct record_params data_params[] =
537 {
538     { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
539     { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
540     { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32 },
541     { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
542     { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
543     { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
544     { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32 },
545     { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
546     { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY }
547 };
548 static const struct record_sounddevice data_sounddevice[] =
549 {
550     { sounddevice_productnameW }
551 };
552 static const struct record_stdregprov data_stdregprov[] =
553 {
554     { reg_enumkey, reg_enumvalues }
555 };
556
557 static UINT get_processor_count(void)
558 {
559     SYSTEM_BASIC_INFORMATION info;
560
561     if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
562     return info.NumberOfProcessors;
563 }
564
565 static UINT get_logical_processor_count(void)
566 {
567     SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
568     UINT i, j, count = 0;
569     NTSTATUS status;
570     ULONG len;
571
572     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
573     if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
574
575     if (!(info = heap_alloc( len ))) return get_processor_count();
576     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
577     if (status != STATUS_SUCCESS)
578     {
579         heap_free( info );
580         return get_processor_count();
581     }
582     for (i = 0; i < len / sizeof(*info); i++)
583     {
584         if (info[i].Relationship != RelationProcessorCore) continue;
585         for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
586     }
587     heap_free( info );
588     return count;
589 }
590
591 static UINT64 get_total_physical_memory(void)
592 {
593     MEMORYSTATUSEX status;
594
595     status.dwLength = sizeof(status);
596     if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
597     return status.ullTotalPhys;
598 }
599
600 static void fill_compsys( struct table *table )
601 {
602     struct record_computersystem *rec;
603
604     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
605
606     rec = (struct record_computersystem *)table->data;
607     rec->description            = compsys_descriptionW;
608     rec->domain                 = compsys_domainW;
609     rec->domainrole             = 0; /* standalone workstation */
610     rec->manufacturer           = compsys_manufacturerW;
611     rec->model                  = compsys_modelW;
612     rec->num_logical_processors = get_logical_processor_count();
613     rec->num_processors         = get_processor_count();
614     rec->total_physical_memory  = get_total_physical_memory();
615
616     TRACE("created 1 row\n");
617     table->num_rows = 1;
618 }
619
620 static WCHAR *get_filesystem( const WCHAR *root )
621 {
622     static const WCHAR ntfsW[] = {'N','T','F','S',0};
623     WCHAR buffer[MAX_PATH + 1];
624
625     if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
626         return heap_strdupW( buffer );
627     return heap_strdupW( ntfsW );
628 }
629
630 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
631 {
632     WCHAR root[] = {'\\','\\','.','\\','A',':',0};
633     ULARGE_INTEGER free;
634     DISK_GEOMETRY_EX info;
635     HANDLE handle;
636
637     free.QuadPart = 512 * 1024 * 1024;
638     GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
639
640     root[4] = dir[0];
641     handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
642     if (handle != INVALID_HANDLE_VALUE)
643     {
644         if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
645             *disksize = info.DiskSize.QuadPart;
646         CloseHandle( handle );
647     }
648     return free.QuadPart;
649 }
650
651 static void fill_logicaldisk( struct table *table )
652 {
653     static const WCHAR fmtW[] = {'%','c',':',0};
654     WCHAR device_id[3], root[] = {'A',':','\\',0};
655     struct record_logicaldisk *rec;
656     UINT i, num_rows = 0, offset = 0, count = 4, type;
657     UINT64 size = 1024 * 1024 * 1024;
658     DWORD drives = GetLogicalDrives();
659
660     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
661
662     for (i = 0; i < sizeof(drives); i++)
663     {
664         if (drives & (1 << i))
665         {
666             root[0] = 'A' + i;
667             type = GetDriveTypeW( root );
668             if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
669                 continue;
670
671             if (num_rows > count)
672             {
673                 BYTE *data;
674                 count *= 2;
675                 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
676                 table->data = data;
677             }
678             rec = (struct record_logicaldisk *)(table->data + offset);
679             sprintfW( device_id, fmtW, 'A' + i );
680             rec->device_id  = heap_strdupW( device_id );
681             rec->drivetype  = type;
682             rec->filesystem = get_filesystem( root );
683             rec->freespace  = get_freespace( root, &size );
684             rec->size       = size;
685             offset += sizeof(*rec);
686             num_rows++;
687         }
688     }
689     TRACE("created %u rows\n", num_rows);
690     table->num_rows = num_rows;
691 }
692
693 static UINT16 get_connection_status( IF_OPER_STATUS status )
694 {
695     switch (status)
696     {
697     case IfOperStatusDown:
698         return 0; /* Disconnected */
699     case IfOperStatusUp:
700         return 2; /* Connected */
701     default:
702         ERR("unhandled status %u\n", status);
703         break;
704     }
705     return 0;
706 }
707 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
708 {
709     static const WCHAR fmtW[] =
710         {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
711          '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
712     WCHAR *ret;
713
714     if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
715     sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
716     return ret;
717 }
718 static const WCHAR *get_adaptertype( DWORD type )
719 {
720     static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
721     static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
722     static const WCHAR firewireW[] = {'1','3','9','4',0};
723     static const WCHAR tunnelW[]   = {'T','u','n','n','e','l',0};
724
725     switch (type)
726     {
727     case IF_TYPE_ETHERNET_CSMACD: return ethernetW;
728     case IF_TYPE_IEEE80211:       return wirelessW;
729     case IF_TYPE_IEEE1394:        return firewireW;
730     case IF_TYPE_TUNNEL:          return tunnelW;
731     default: break;
732     }
733     return NULL;
734 }
735
736 static void fill_networkadapter( struct table *table )
737 {
738     static const WCHAR fmtW[] = {'%','u',0};
739     WCHAR device_id[11];
740     struct record_networkadapter *rec;
741     IP_ADAPTER_ADDRESSES *aa, *buffer;
742     UINT num_rows = 0, offset = 0;
743     DWORD size = 0, ret;
744
745     ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
746     if (ret != ERROR_BUFFER_OVERFLOW) return;
747
748     if (!(buffer = heap_alloc( size ))) return;
749     if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
750     {
751         heap_free( buffer );
752         return;
753     }
754     for (aa = buffer; aa; aa = aa->Next) num_rows++;
755     if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
756     {
757         heap_free( buffer );
758         return;
759     }
760     for (aa = buffer; aa; aa = aa->Next)
761     {
762         rec = (struct record_networkadapter *)(table->data + offset);
763         sprintfW( device_id, fmtW, aa->u.s.IfIndex );
764         rec->adaptertype          = get_adaptertype( aa->IfType );
765         rec->device_id            = heap_strdupW( device_id );
766         rec->interface_index      = aa->u.s.IfIndex;
767         rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
768         rec->manufacturer         = compsys_manufacturerW;
769         rec->netconnection_status = get_connection_status( aa->OperStatus );
770         rec->pnpdevice_id         = networkadapter_pnpdeviceidW;
771         rec->speed                = 1000000;
772         offset += sizeof(*rec);
773     }
774     TRACE("created %u rows\n", num_rows);
775     table->num_rows = num_rows;
776
777     heap_free( buffer );
778 }
779
780 static WCHAR *get_cmdline( DWORD process_id )
781 {
782     if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
783     return NULL; /* FIXME handle different process case */
784 }
785
786 static void fill_process( struct table *table )
787 {
788     static const WCHAR fmtW[] = {'%','u',0};
789     WCHAR handle[11];
790     struct record_process *rec;
791     PROCESSENTRY32W entry;
792     HANDLE snap;
793     UINT num_rows = 0, offset = 0, count = 8;
794
795     snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
796     if (snap == INVALID_HANDLE_VALUE) return;
797
798     entry.dwSize = sizeof(entry);
799     if (!Process32FirstW( snap, &entry )) goto done;
800     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
801
802     do
803     {
804         if (num_rows > count)
805         {
806             BYTE *data;
807             count *= 2;
808             if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
809             table->data = data;
810         }
811         rec = (struct record_process *)(table->data + offset);
812         rec->caption      = heap_strdupW( entry.szExeFile );
813         rec->commandline  = get_cmdline( entry.th32ProcessID );
814         rec->description  = heap_strdupW( entry.szExeFile );
815         sprintfW( handle, fmtW, entry.th32ProcessID );
816         rec->handle       = heap_strdupW( handle );
817         rec->process_id   = entry.th32ProcessID;
818         rec->pprocess_id  = entry.th32ParentProcessID;
819         rec->thread_count = entry.cntThreads;
820         offset += sizeof(*rec);
821         num_rows++;
822     } while (Process32NextW( snap, &entry ));
823
824     TRACE("created %u rows\n", num_rows);
825     table->num_rows = num_rows;
826
827 done:
828     CloseHandle( snap );
829 }
830
831 static inline void do_cpuid( unsigned int ax, unsigned int *p )
832 {
833 #ifdef __i386__
834     __asm__("pushl %%ebx\n\t"
835                 "cpuid\n\t"
836                 "movl %%ebx, %%esi\n\t"
837                 "popl %%ebx"
838                 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
839                 :  "0" (ax));
840 #endif
841 }
842
843 static void get_processor_id( WCHAR *processor_id )
844 {
845     static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
846     unsigned int regs[4] = {0, 0, 0, 0};
847
848     do_cpuid( 1, regs );
849     sprintfW( processor_id, fmtW, regs[3], regs[0] );
850 }
851 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
852 {
853     unsigned int i;
854     unsigned char *p = (unsigned char *)regs;
855
856     for (i = 0; i < len; i++)
857     {
858         buffer[i] = *p++;
859     }
860     buffer[i] = 0;
861 }
862 static void get_processor_manufacturer( WCHAR *manufacturer )
863 {
864     unsigned int tmp, regs[4] = {0, 0, 0, 0};
865
866     do_cpuid( 0, regs );
867     tmp = regs[2];      /* swap edx and ecx */
868     regs[2] = regs[3];
869     regs[3] = tmp;
870
871     regs_to_str( regs + 1, 12, manufacturer );
872 }
873 static void get_processor_name( WCHAR *name )
874 {
875     unsigned int regs[4] = {0, 0, 0, 0};
876
877     do_cpuid( 0x80000000, regs );
878     if (regs[0] >= 0x80000004)
879     {
880         do_cpuid( 0x80000002, regs );
881         regs_to_str( regs, 16, name );
882         do_cpuid( 0x80000003, regs );
883         regs_to_str( regs, 16, name + 16 );
884         do_cpuid( 0x80000004, regs );
885         regs_to_str( regs, 16, name + 32 );
886     }
887 }
888 static UINT get_processor_maxclockspeed( void )
889 {
890     PROCESSOR_POWER_INFORMATION *info;
891     UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
892     NTSTATUS status;
893
894     if ((info = heap_alloc( size )))
895     {
896         status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
897         if (!status) ret = info[0].MaxMhz;
898         heap_free( info );
899     }
900     return ret;
901 }
902
903 static void fill_processor( struct table *table )
904 {
905     static const WCHAR fmtW[] = {'C','P','U','%','u',0};
906     WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
907     struct record_processor *rec;
908     UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
909
910     if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
911
912     get_processor_id( processor_id );
913     get_processor_manufacturer( manufacturer );
914     get_processor_name( name );
915
916     maxclockspeed = get_processor_maxclockspeed();
917     num_logical_processors = get_logical_processor_count() / count;
918
919     for (i = 0; i < count; i++)
920     {
921         rec = (struct record_processor *)(table->data + offset);
922         rec->cpu_status             = 1; /* CPU Enabled */
923         sprintfW( device_id, fmtW, i );
924         rec->device_id              = heap_strdupW( device_id );
925         rec->manufacturer           = heap_strdupW( manufacturer );
926         rec->maxclockspeed          = maxclockspeed;
927         rec->name                   = heap_strdupW( name );
928         rec->num_logical_processors = num_logical_processors;
929         rec->processor_id           = heap_strdupW( processor_id );
930         rec->unique_id              = NULL;
931         offset += sizeof(*rec);
932     }
933
934     TRACE("created %u rows\n", count);
935     table->num_rows = count;
936 }
937
938 static WCHAR *get_lastbootuptime(void)
939 {
940     static const WCHAR fmtW[] =
941         {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
942          '.','%','0','6','u','+','0','0','0',0};
943     SYSTEMTIME st;
944     FILETIME ft;
945     ULARGE_INTEGER ticks;
946     WCHAR *ret;
947
948     if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
949     GetSystemTime( &st );
950     SystemTimeToFileTime( &st, &ft );
951     ticks.u.LowPart  = ft.dwLowDateTime;
952     ticks.u.HighPart = ft.dwHighDateTime;
953     ticks.QuadPart -= GetTickCount64() * 10000;
954     ft.dwLowDateTime  = ticks.u.LowPart;
955     ft.dwHighDateTime = ticks.u.HighPart;
956     FileTimeToSystemTime( &ft, &st );
957     sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000 );
958     return ret;
959 }
960 static const WCHAR *get_osarchitecture(void)
961 {
962     SYSTEM_INFO info;
963     GetNativeSystemInfo( &info );
964     if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
965     return os_32bitW;
966 }
967 static WCHAR *get_systemdirectory(void)
968 {
969     void *redir;
970     WCHAR *ret;
971
972     if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
973     Wow64DisableWow64FsRedirection( &redir );
974     GetSystemDirectoryW( ret, MAX_PATH );
975     Wow64RevertWow64FsRedirection( redir );
976     return ret;
977 }
978
979 static void fill_os( struct table *table )
980 {
981     struct record_operatingsystem *rec;
982
983     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
984
985     rec = (struct record_operatingsystem *)table->data;
986     rec->caption         = os_captionW;
987     rec->csdversion      = os_csdversionW;
988     rec->lastbootuptime  = get_lastbootuptime();
989     rec->osarchitecture  = get_osarchitecture();
990     rec->oslanguage      = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
991     rec->systemdirectory = get_systemdirectory();
992
993     TRACE("created 1 row\n");
994     table->num_rows = 1;
995 }
996
997 static const WCHAR *get_service_type( DWORD type )
998 {
999     static const WCHAR filesystem_driverW[] =
1000         {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1001     static const WCHAR kernel_driverW[] =
1002         {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1003     static const WCHAR own_processW[] =
1004         {'O','w','n',' ','P','r','o','c','e','s','s',0};
1005     static const WCHAR share_processW[] =
1006         {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1007
1008     if (type & SERVICE_KERNEL_DRIVER)            return kernel_driverW;
1009     else if (type & SERVICE_FILE_SYSTEM_DRIVER)  return filesystem_driverW;
1010     else if (type & SERVICE_WIN32_OWN_PROCESS)   return own_processW;
1011     else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1012     else ERR("unhandled type 0x%08x\n", type);
1013     return NULL;
1014 }
1015 static const WCHAR *get_service_state( DWORD state )
1016 {
1017     static const WCHAR runningW[] =
1018         {'R','u','n','n','i','n','g',0};
1019     static const WCHAR start_pendingW[] =
1020         {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1021     static const WCHAR stop_pendingW[] =
1022         {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1023     static const WCHAR stoppedW[] =
1024         {'S','t','o','p','p','e','d',0};
1025     static const WCHAR unknownW[] =
1026         {'U','n','k','n','o','w','n',0};
1027
1028     switch (state)
1029     {
1030     case SERVICE_STOPPED:       return stoppedW;
1031     case SERVICE_START_PENDING: return start_pendingW;
1032     case SERVICE_STOP_PENDING:  return stop_pendingW;
1033     case SERVICE_RUNNING:       return runningW;
1034     default:
1035         ERR("unknown state %u\n", state);
1036         return unknownW;
1037     }
1038 }
1039
1040 static const WCHAR *get_service_startmode( DWORD mode )
1041 {
1042     static const WCHAR bootW[] = {'B','o','o','t',0};
1043     static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
1044     static const WCHAR autoW[] = {'A','u','t','o',0};
1045     static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
1046     static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
1047     static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
1048
1049     switch (mode)
1050     {
1051     case SERVICE_BOOT_START:   return bootW;
1052     case SERVICE_SYSTEM_START: return systemW;
1053     case SERVICE_AUTO_START:   return autoW;
1054     case SERVICE_DEMAND_START: return manualW;
1055     case SERVICE_DISABLED:     return disabledW;
1056     default:
1057         ERR("unknown mode 0x%x\n", mode);
1058         return unknownW;
1059     }
1060 }
1061
1062 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
1063 {
1064     QUERY_SERVICE_CONFIGW *config = NULL;
1065     SC_HANDLE service;
1066     DWORD size;
1067
1068     if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
1069     QueryServiceConfigW( service, NULL, 0, &size );
1070     if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
1071     if (!(config = heap_alloc( size ))) goto done;
1072     if (QueryServiceConfigW( service, config, size, &size )) goto done;
1073     heap_free( config );
1074     config = NULL;
1075
1076 done:
1077     CloseServiceHandle( service );
1078     return config;
1079 }
1080
1081 static void fill_service( struct table *table )
1082 {
1083     struct record_service *rec;
1084     SC_HANDLE manager;
1085     ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
1086     SERVICE_STATUS_PROCESS *status;
1087     WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
1088     DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
1089     UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
1090     BOOL ret;
1091
1092     if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
1093     if (!(services = heap_alloc( size ))) goto done;
1094
1095     ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1096                                  SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1097                                  &count, NULL, NULL );
1098     if (!ret)
1099     {
1100         if (GetLastError() != ERROR_MORE_DATA) goto done;
1101         size = needed;
1102         if (!(tmp = heap_realloc( services, size ))) goto done;
1103         services = tmp;
1104         ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1105                                      SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1106                                      &count, NULL, NULL );
1107         if (!ret) goto done;
1108     }
1109     if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
1110
1111     GetComputerNameW( sysnameW, &len );
1112
1113     for (i = 0; i < count; i++)
1114     {
1115         QUERY_SERVICE_CONFIGW *config;
1116
1117         if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
1118
1119         status = &services[i].ServiceStatusProcess;
1120         rec = (struct record_service *)(table->data + offset);
1121         rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
1122         rec->accept_stop  = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
1123         rec->displayname  = heap_strdupW( services[i].lpDisplayName );
1124         rec->name         = heap_strdupW( services[i].lpServiceName );
1125         rec->process_id   = status->dwProcessId;
1126         rec->servicetype  = get_service_type( status->dwServiceType );
1127         rec->startmode    = get_service_startmode( config->dwStartType );
1128         rec->state        = get_service_state( status->dwCurrentState );
1129         rec->systemname   = heap_strdupW( sysnameW );
1130         heap_free( config );
1131         offset += sizeof(*rec);
1132         num_rows++;
1133     }
1134
1135     TRACE("created %u rows\n", num_rows);
1136     table->num_rows = num_rows;
1137
1138 done:
1139     CloseServiceHandle( manager );
1140     heap_free( services );
1141 }
1142
1143 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1144 {
1145     HDC hdc = GetDC( NULL );
1146     UINT32 ret;
1147
1148     if (!hdc) return 32;
1149     ret = GetDeviceCaps( hdc, BITSPIXEL );
1150     *hres = GetDeviceCaps( hdc, HORZRES );
1151     *vres = GetDeviceCaps( hdc, VERTRES );
1152     ReleaseDC( NULL, hdc );
1153     return ret;
1154 }
1155
1156 static void fill_videocontroller( struct table *table )
1157 {
1158
1159     struct record_videocontroller *rec;
1160     HRESULT hr;
1161     IDXGIFactory *factory = NULL;
1162     IDXGIAdapter *adapter = NULL;
1163     DXGI_ADAPTER_DESC desc;
1164     UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1165     const WCHAR *name = videocontroller_deviceidW;
1166
1167     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1168
1169     hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1170     if (FAILED(hr)) goto done;
1171
1172     hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1173     if (FAILED(hr)) goto done;
1174
1175     hr = IDXGIAdapter_GetDesc( adapter, &desc );
1176     if (SUCCEEDED(hr))
1177     {
1178         vidmem = desc.DedicatedVideoMemory;
1179         name   = desc.Description;
1180     }
1181
1182 done:
1183     rec = (struct record_videocontroller *)table->data;
1184     rec->adapter_ram           = vidmem;
1185     rec->current_bitsperpixel  = get_bits_per_pixel( &hres, &vres );
1186     rec->current_horizontalres = hres;
1187     rec->current_verticalres   = vres;
1188     rec->description           = heap_strdupW( name );
1189     rec->device_id             = videocontroller_deviceidW;
1190     rec->name                  = heap_strdupW( name );
1191
1192     TRACE("created 1 row\n");
1193     table->num_rows = 1;
1194
1195     if (adapter) IDXGIAdapter_Release( adapter );
1196     if (factory) IDXGIFactory_Release( factory );
1197 }
1198
1199 static struct table builtin_classes[] =
1200 {
1201     { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1202     { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1203     { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, SIZEOF(data_cdromdrive), (BYTE *)data_cdromdrive },
1204     { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1205     { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), (BYTE *)data_diskdrive },
1206     { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1207     { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1208     { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1209     { class_paramsW, SIZEOF(col_params), col_params, SIZEOF(data_params), (BYTE *)data_params },
1210     { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1211     { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1212     { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1213     { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), (BYTE *)data_sounddevice },
1214     { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1215     { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1216 };
1217
1218 void init_table_list( void )
1219 {
1220     static struct list tables = LIST_INIT( tables );
1221     UINT i;
1222
1223     for (i = 0; i < SIZEOF(builtin_classes); i++)
1224     {
1225         list_add_tail( &tables, &builtin_classes[i].entry );
1226     }
1227     table_list = &tables;
1228 }