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