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