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