wbemprox: Implement Win32_Processor.Family.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob3266bd26420fdfb84e82687e870fc78c06b3601d
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "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"
41 #include "wine/debug.h"
42 #include "wbemprox_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
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};
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_bootpartitionW[] =
89 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
90 static const WCHAR prop_captionW[] =
91 {'C','a','p','t','i','o','n',0};
92 static const WCHAR prop_classW[] =
93 {'C','l','a','s','s',0};
94 static const WCHAR prop_commandlineW[] =
95 {'C','o','m','m','a','n','d','L','i','n','e',0};
96 static const WCHAR prop_cpustatusW[] =
97 {'C','p','u','S','t','a','t','u','s',0};
98 static const WCHAR prop_csdversionW[] =
99 {'C','S','D','V','e','r','s','i','o','n',0};
100 static const WCHAR prop_currentbitsperpixelW[] =
101 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
102 static const WCHAR prop_currenthorizontalresW[] =
103 {'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};
104 static const WCHAR prop_currentverticalresW[] =
105 {'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};
106 static const WCHAR prop_defaultvalueW[] =
107 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
108 static const WCHAR prop_descriptionW[] =
109 {'D','e','s','c','r','i','p','t','i','o','n',0};
110 static const WCHAR prop_deviceidW[] =
111 {'D','e','v','i','c','e','I','d',0};
112 static const WCHAR prop_directionW[] =
113 {'D','i','r','e','c','t','i','o','n',0};
114 static const WCHAR prop_displaynameW[] =
115 {'D','i','s','p','l','a','y','N','a','m','e',0};
116 static const WCHAR prop_diskindexW[] =
117 {'D','i','s','k','I','n','d','e','x',0};
118 static const WCHAR prop_domainW[] =
119 {'D','o','m','a','i','n',0};
120 static const WCHAR prop_domainroleW[] =
121 {'D','o','m','a','i','n','R','o','l','e',0};
122 static const WCHAR prop_driveW[] =
123 {'D','r','i','v','e',0};
124 static const WCHAR prop_drivetypeW[] =
125 {'D','r','i','v','e','T','y','p','e',0};
126 static const WCHAR prop_familyW[] =
127 {'F','a','m','i','l','y',0};
128 static const WCHAR prop_filesystemW[] =
129 {'F','i','l','e','S','y','s','t','e','m',0};
130 static const WCHAR prop_flavorW[] =
131 {'F','l','a','v','o','r',0};
132 static const WCHAR prop_freespaceW[] =
133 {'F','r','e','e','S','p','a','c','e',0};
134 static const WCHAR prop_handleW[] =
135 {'H','a','n','d','l','e',0};
136 static const WCHAR prop_idW[] =
137 {'I','D',0};
138 static const WCHAR prop_indexW[] =
139 {'I','n','d','e','x',0};
140 static const WCHAR prop_interfaceindexW[] =
141 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
142 static const WCHAR prop_intvalueW[] =
143 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
144 static const WCHAR prop_lastbootuptimeW[] =
145 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
146 static const WCHAR prop_macaddressW[] =
147 {'M','A','C','A','d','d','r','e','s','s',0};
148 static const WCHAR prop_manufacturerW[] =
149 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
150 static const WCHAR prop_maxclockspeedW[] =
151 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
152 static const WCHAR prop_memberW[] =
153 {'M','e','m','b','e','r',0};
154 static const WCHAR prop_methodW[] =
155 {'M','e','t','h','o','d',0};
156 static const WCHAR prop_modelW[] =
157 {'M','o','d','e','l',0};
158 static const WCHAR prop_netconnectionstatusW[] =
159 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
160 static const WCHAR prop_numlogicalprocessorsW[] =
161 {'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};
162 static const WCHAR prop_numprocessorsW[] =
163 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
164 static const WCHAR prop_osarchitectureW[] =
165 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
166 static const WCHAR prop_oslanguageW[] =
167 {'O','S','L','a','n','g','u','a','g','e',0};
168 static const WCHAR prop_osproductsuiteW[] =
169 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
170 static const WCHAR prop_ostypeW[] =
171 {'O','S','T','y','p','e',0};
172 static const WCHAR prop_parameterW[] =
173 {'P','a','r','a','m','e','t','e','r',0};
174 static const WCHAR prop_pnpdeviceidW[] =
175 {'P','N','P','D','e','v','i','c','e','I','D',0};
176 static const WCHAR prop_pprocessidW[] =
177 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
178 static const WCHAR prop_processidW[] =
179 {'P','r','o','c','e','s','s','I','D',0};
180 static const WCHAR prop_processoridW[] =
181 {'P','r','o','c','e','s','s','o','r','I','d',0};
182 static const WCHAR prop_productnameW[] =
183 {'P','r','o','d','u','c','t','N','a','m','e',0};
184 static const WCHAR prop_releasedateW[] =
185 {'R','e','l','e','a','s','e','D','a','t','e',0};
186 static const WCHAR prop_serialnumberW[] =
187 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
188 static const WCHAR prop_servicepackmajorW[] =
189 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
190 static const WCHAR prop_servicetypeW[] =
191 {'S','e','r','v','i','c','e','T','y','p','e',0};
192 static const WCHAR prop_startmodeW[] =
193 {'S','t','a','r','t','M','o','d','e',0};
194 static const WCHAR prop_sizeW[] =
195 {'S','i','z','e',0};
196 static const WCHAR prop_speedW[] =
197 {'S','p','e','e','d',0};
198 static const WCHAR prop_startingoffsetW[] =
199 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
200 static const WCHAR prop_stateW[] =
201 {'S','t','a','t','e',0};
202 static const WCHAR prop_strvalueW[] =
203 {'S','t','r','i','n','g','V','a','l','u','e',0};
204 static const WCHAR prop_suitemaskW[] =
205 {'S','u','i','t','e','M','a','s','k',0};
206 static const WCHAR prop_systemdirectoryW[] =
207 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
208 static const WCHAR prop_systemnameW[] =
209 {'S','y','s','t','e','m','N','a','m','e',0};
210 static const WCHAR prop_tagW[] =
211 {'T','a','g',0};
212 static const WCHAR prop_threadcountW[] =
213 {'T','h','r','e','a','d','C','o','u','n','t',0};
214 static const WCHAR prop_totalphysicalmemoryW[] =
215 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
216 static const WCHAR prop_typeW[] =
217 {'T','y','p','e',0};
218 static const WCHAR prop_uniqueidW[] =
219 {'U','n','i','q','u','e','I','d',0};
220 static const WCHAR prop_varianttypeW[] =
221 {'V','a','r','i','a','n','t','T','y','p','e',0};
222 static const WCHAR prop_versionW[] =
223 {'V','e','r','s','i','o','n',0};
225 /* column definitions must be kept in sync with record structures below */
226 static const struct column col_baseboard[] =
228 { prop_manufacturerW, CIM_STRING },
229 { prop_serialnumberW, CIM_STRING },
230 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
232 static const struct column col_bios[] =
234 { prop_descriptionW, CIM_STRING },
235 { prop_manufacturerW, CIM_STRING },
236 { prop_releasedateW, CIM_DATETIME },
237 { prop_serialnumberW, CIM_STRING },
238 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
240 static const struct column col_cdromdrive[] =
242 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
243 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
244 { prop_nameW, CIM_STRING },
245 { prop_pnpdeviceidW, CIM_STRING }
247 static const struct column col_compsys[] =
249 { prop_descriptionW, CIM_STRING },
250 { prop_domainW, CIM_STRING },
251 { prop_domainroleW, CIM_UINT16 },
252 { prop_manufacturerW, CIM_STRING },
253 { prop_modelW, CIM_STRING },
254 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
255 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
256 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
257 { prop_totalphysicalmemoryW, CIM_UINT64 }
259 static const struct column col_diskdrive[] =
261 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
262 { prop_indexW, CIM_UINT32, VT_I4 },
263 { prop_manufacturerW, CIM_STRING },
264 { prop_modelW, CIM_STRING },
265 { prop_serialnumberW, CIM_STRING }
267 static const struct column col_diskpartition[] =
269 { prop_bootableW, CIM_BOOLEAN },
270 { prop_bootpartitionW, CIM_BOOLEAN },
271 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
272 { prop_diskindexW, CIM_UINT32, VT_I4 },
273 { prop_indexW, CIM_UINT32, VT_I4 },
274 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
275 { prop_sizeW, CIM_UINT64 },
276 { prop_startingoffsetW, CIM_UINT64 },
277 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
279 static const struct column col_logicaldisk[] =
281 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
282 { prop_drivetypeW, CIM_UINT32, VT_I4 },
283 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
284 { prop_freespaceW, CIM_UINT64 },
285 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
286 { prop_sizeW, CIM_UINT64 }
288 static const struct column col_networkadapter[] =
290 { prop_adaptertypeW, CIM_STRING },
291 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
292 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
293 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
294 { prop_manufacturerW, CIM_STRING },
295 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
296 { prop_pnpdeviceidW, CIM_STRING },
297 { prop_speedW, CIM_UINT64 }
299 static const struct column col_os[] =
301 { prop_captionW, CIM_STRING },
302 { prop_csdversionW, CIM_STRING },
303 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
304 { prop_osarchitectureW, CIM_STRING },
305 { prop_oslanguageW, CIM_UINT32, VT_I4 },
306 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
307 { prop_ostypeW, CIM_UINT16, VT_I4 },
308 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
309 { prop_suitemaskW, CIM_UINT32, VT_I4 },
310 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
311 { prop_versionW, CIM_STRING }
313 static const struct column col_param[] =
315 { prop_classW, CIM_STRING },
316 { prop_methodW, CIM_STRING },
317 { prop_directionW, CIM_SINT32 },
318 { prop_parameterW, CIM_STRING },
319 { prop_typeW, CIM_UINT32 },
320 { prop_varianttypeW, CIM_UINT32 },
321 { prop_defaultvalueW, CIM_UINT32 }
323 static const struct column col_process[] =
325 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
326 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
327 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
328 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
329 { prop_pprocessidW, CIM_UINT32, VT_I4 },
330 { prop_processidW, CIM_UINT32, VT_I4 },
331 { prop_threadcountW, CIM_UINT32, VT_I4 },
332 /* methods */
333 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
335 static const struct column col_processor[] =
337 { prop_cpustatusW, CIM_UINT16 },
338 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
339 { prop_familyW, CIM_UINT16, VT_I4 },
340 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
341 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
342 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
343 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
344 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
345 { prop_uniqueidW, CIM_STRING }
347 static const struct column col_qualifier[] =
349 { prop_classW, CIM_STRING },
350 { prop_memberW, CIM_STRING },
351 { prop_typeW, CIM_UINT32 },
352 { prop_flavorW, CIM_SINT32 },
353 { prop_nameW, CIM_STRING },
354 { prop_intvalueW, CIM_SINT32 },
355 { prop_strvalueW, CIM_STRING }
357 static const struct column col_service[] =
359 { prop_acceptpauseW, CIM_BOOLEAN },
360 { prop_acceptstopW, CIM_BOOLEAN },
361 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
362 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
363 { prop_processidW, CIM_UINT32 },
364 { prop_servicetypeW, CIM_STRING },
365 { prop_startmodeW, CIM_STRING },
366 { prop_stateW, CIM_STRING },
367 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
368 /* methods */
369 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
370 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
371 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
372 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
374 static const struct column col_sounddevice[] =
376 { prop_productnameW, CIM_STRING }
378 static const struct column col_stdregprov[] =
380 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
381 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
382 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
384 static const struct column col_videocontroller[] =
386 { prop_adapterramW, CIM_UINT32 },
387 { prop_currentbitsperpixelW, CIM_UINT32 },
388 { prop_currenthorizontalresW, CIM_UINT32 },
389 { prop_currentverticalresW, CIM_UINT32 },
390 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
391 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
392 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
393 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
396 static const WCHAR baseboard_manufacturerW[] =
397 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
398 static const WCHAR baseboard_serialnumberW[] =
399 {'N','o','n','e',0};
400 static const WCHAR baseboard_tagW[] =
401 {'B','a','s','e',' ','B','o','a','r','d',0};
402 static const WCHAR bios_descriptionW[] =
403 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
404 static const WCHAR bios_manufacturerW[] =
405 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
406 static const WCHAR bios_releasedateW[] =
407 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
408 static const WCHAR bios_serialnumberW[] =
409 {'0',0};
410 static const WCHAR bios_versionW[] =
411 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
412 static const WCHAR cdromdrive_nameW[] =
413 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
414 static const WCHAR cdromdrive_pnpdeviceidW[]=
415 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
416 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
417 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
418 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
419 static const WCHAR compsys_descriptionW[] =
420 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
421 static const WCHAR compsys_domainW[] =
422 {'W','O','R','K','G','R','O','U','P',0};
423 static const WCHAR compsys_manufacturerW[] =
424 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
425 static const WCHAR compsys_modelW[] =
426 {'W','i','n','e',0};
427 static const WCHAR diskdrive_deviceidW[] =
428 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
429 static const WCHAR diskdrive_modelW[] =
430 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
431 static const WCHAR diskdrive_manufacturerW[] =
432 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
433 static const WCHAR diskdrive_serialW[] =
434 {'W','I','N','E','H','D','I','S','K',0};
435 static const WCHAR networkadapter_pnpdeviceidW[]=
436 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
437 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
438 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
439 static const WCHAR os_captionW[] =
440 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
441 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
442 static const WCHAR os_csdversionW[] =
443 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
444 static const WCHAR os_32bitW[] =
445 {'3','2','-','b','i','t',0};
446 static const WCHAR os_64bitW[] =
447 {'6','4','-','b','i','t',0};
448 static const WCHAR os_versionW[] =
449 {'5','.','1','.','2','6','0','0',0};
450 static const WCHAR sounddevice_productnameW[] =
451 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
452 static const WCHAR videocontroller_deviceidW[] =
453 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
455 #include "pshpack1.h"
456 struct record_baseboard
458 const WCHAR *manufacturer;
459 const WCHAR *serialnumber;
460 const WCHAR *tag;
462 struct record_bios
464 const WCHAR *description;
465 const WCHAR *manufacturer;
466 const WCHAR *releasedate;
467 const WCHAR *serialnumber;
468 const WCHAR *version;
470 struct record_cdromdrive
472 const WCHAR *device_id;
473 const WCHAR *drive;
474 const WCHAR *name;
475 const WCHAR *pnpdevice_id;
477 struct record_computersystem
479 const WCHAR *description;
480 const WCHAR *domain;
481 UINT16 domainrole;
482 const WCHAR *manufacturer;
483 const WCHAR *model;
484 const WCHAR *name;
485 UINT32 num_logical_processors;
486 UINT32 num_processors;
487 UINT64 total_physical_memory;
489 struct record_diskdrive
491 const WCHAR *device_id;
492 UINT32 index;
493 const WCHAR *manufacturer;
494 const WCHAR *name;
495 const WCHAR *serialnumber;
497 struct record_diskpartition
499 int bootable;
500 int bootpartition;
501 const WCHAR *device_id;
502 UINT32 diskindex;
503 UINT32 index;
504 const WCHAR *pnpdevice_id;
505 UINT64 size;
506 UINT64 startingoffset;
507 const WCHAR *type;
509 struct record_logicaldisk
511 const WCHAR *device_id;
512 UINT32 drivetype;
513 const WCHAR *filesystem;
514 UINT64 freespace;
515 const WCHAR *name;
516 UINT64 size;
518 struct record_networkadapter
520 const WCHAR *adaptertype;
521 const WCHAR *device_id;
522 INT32 interface_index;
523 const WCHAR *mac_address;
524 const WCHAR *manufacturer;
525 UINT16 netconnection_status;
526 const WCHAR *pnpdevice_id;
527 UINT64 speed;
529 struct record_operatingsystem
531 const WCHAR *caption;
532 const WCHAR *csdversion;
533 const WCHAR *lastbootuptime;
534 const WCHAR *osarchitecture;
535 UINT32 oslanguage;
536 UINT32 osproductsuite;
537 UINT16 ostype;
538 UINT16 servicepackmajor;
539 UINT32 suitemask;
540 const WCHAR *systemdirectory;
541 const WCHAR *version;
543 struct record_param
545 const WCHAR *class;
546 const WCHAR *method;
547 INT32 direction;
548 const WCHAR *parameter;
549 UINT32 type;
550 UINT32 varianttype;
551 UINT32 defaultvalue;
553 struct record_process
555 const WCHAR *caption;
556 const WCHAR *commandline;
557 const WCHAR *description;
558 const WCHAR *handle;
559 UINT32 pprocess_id;
560 UINT32 process_id;
561 UINT32 thread_count;
562 /* methods */
563 class_method *get_owner;
565 struct record_processor
567 UINT16 cpu_status;
568 const WCHAR *device_id;
569 UINT16 family;
570 const WCHAR *manufacturer;
571 UINT32 maxclockspeed;
572 const WCHAR *name;
573 UINT32 num_logical_processors;
574 const WCHAR *processor_id;
575 const WCHAR *unique_id;
577 struct record_qualifier
579 const WCHAR *class;
580 const WCHAR *member;
581 UINT32 type;
582 INT32 flavor;
583 const WCHAR *name;
584 INT32 intvalue;
585 const WCHAR *strvalue;
587 struct record_service
589 int accept_pause;
590 int accept_stop;
591 const WCHAR *displayname;
592 const WCHAR *name;
593 UINT32 process_id;
594 const WCHAR *servicetype;
595 const WCHAR *startmode;
596 const WCHAR *state;
597 const WCHAR *systemname;
598 /* methods */
599 class_method *pause_service;
600 class_method *resume_service;
601 class_method *start_service;
602 class_method *stop_service;
604 struct record_sounddevice
606 const WCHAR *productname;
608 struct record_stdregprov
610 class_method *enumkey;
611 class_method *enumvalues;
612 class_method *getstringvalue;
614 struct record_videocontroller
616 UINT32 adapter_ram;
617 UINT32 current_bitsperpixel;
618 UINT32 current_horizontalres;
619 UINT32 current_verticalres;
620 const WCHAR *description;
621 const WCHAR *device_id;
622 const WCHAR *name;
623 const WCHAR *pnpdevice_id;
625 #include "poppack.h"
627 static const struct record_baseboard data_baseboard[] =
629 { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
631 static const struct record_bios data_bios[] =
633 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW, bios_versionW }
635 static const struct record_diskdrive data_diskdrive[] =
637 { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
639 static const struct record_param data_param[] =
641 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
642 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
643 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
644 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
645 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
646 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
647 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
648 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
649 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
650 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
651 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
652 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
653 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
654 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
655 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
656 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
657 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
658 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
659 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
660 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
661 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
664 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
665 WBEM_FLAVOR_ORIGIN_PROPAGATED)
667 static const struct record_qualifier data_qualifier[] =
669 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
670 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
672 static const struct record_sounddevice data_sounddevice[] =
674 { sounddevice_productnameW }
676 static const struct record_stdregprov data_stdregprov[] =
678 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
681 static void fill_cdromdrive( struct table *table )
683 static const WCHAR fmtW[] = {'%','c',':',0};
684 WCHAR drive[3], root[] = {'A',':','\\',0};
685 struct record_cdromdrive *rec;
686 UINT i, num_rows = 0, offset = 0, count = 1;
687 DWORD drives = GetLogicalDrives();
689 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
691 for (i = 0; i < sizeof(drives); i++)
693 if (drives & (1 << i))
695 root[0] = 'A' + i;
696 if (GetDriveTypeW( root ) != DRIVE_CDROM)
697 continue;
699 if (num_rows > count)
701 BYTE *data;
702 count *= 2;
703 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
704 table->data = data;
706 rec = (struct record_cdromdrive *)(table->data + offset);
707 rec->device_id = cdromdrive_pnpdeviceidW;
708 sprintfW( drive, fmtW, 'A' + i );
709 rec->drive = heap_strdupW( drive );
710 rec->name = cdromdrive_nameW;
711 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
712 offset += sizeof(*rec);
713 num_rows++;
716 TRACE("created %u rows\n", num_rows);
717 table->num_rows = num_rows;
720 static UINT get_processor_count(void)
722 SYSTEM_BASIC_INFORMATION info;
724 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
725 return info.NumberOfProcessors;
728 static UINT get_logical_processor_count(void)
730 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
731 UINT i, j, count = 0;
732 NTSTATUS status;
733 ULONG len;
735 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
736 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
738 if (!(info = heap_alloc( len ))) return get_processor_count();
739 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
740 if (status != STATUS_SUCCESS)
742 heap_free( info );
743 return get_processor_count();
745 for (i = 0; i < len / sizeof(*info); i++)
747 if (info[i].Relationship != RelationProcessorCore) continue;
748 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
750 heap_free( info );
751 return count;
754 static UINT64 get_total_physical_memory(void)
756 MEMORYSTATUSEX status;
758 status.dwLength = sizeof(status);
759 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
760 return status.ullTotalPhys;
763 static WCHAR *get_computername(void)
765 WCHAR *ret;
766 DWORD size=MAX_COMPUTERNAME_LENGTH;
768 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
769 GetComputerNameW( ret, &size );
770 return ret;
773 static void fill_compsys( struct table *table )
775 struct record_computersystem *rec;
777 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
779 rec = (struct record_computersystem *)table->data;
780 rec->description = compsys_descriptionW;
781 rec->domain = compsys_domainW;
782 rec->domainrole = 0; /* standalone workstation */
783 rec->manufacturer = compsys_manufacturerW;
784 rec->model = compsys_modelW;
785 rec->name = get_computername();
786 rec->num_logical_processors = get_logical_processor_count();
787 rec->num_processors = get_processor_count();
788 rec->total_physical_memory = get_total_physical_memory();
790 TRACE("created 1 row\n");
791 table->num_rows = 1;
794 static WCHAR *get_filesystem( const WCHAR *root )
796 static const WCHAR ntfsW[] = {'N','T','F','S',0};
797 WCHAR buffer[MAX_PATH + 1];
799 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
800 return heap_strdupW( buffer );
801 return heap_strdupW( ntfsW );
804 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
806 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
807 ULARGE_INTEGER free;
808 DISK_GEOMETRY_EX info;
809 HANDLE handle;
811 free.QuadPart = 512 * 1024 * 1024;
812 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
814 root[4] = dir[0];
815 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
816 if (handle != INVALID_HANDLE_VALUE)
818 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
819 *disksize = info.DiskSize.QuadPart;
820 CloseHandle( handle );
822 return free.QuadPart;
825 static void fill_diskpartition( struct table *table )
827 static const WCHAR fmtW[] =
828 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
829 WCHAR device_id[32], root[] = {'A',':','\\',0};
830 struct record_diskpartition *rec;
831 UINT i, num_rows = 0, offset = 0, count = 4, type, index = 0;
832 UINT64 size = 1024 * 1024 * 1024;
833 DWORD drives = GetLogicalDrives();
835 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
837 for (i = 0; i < sizeof(drives); i++)
839 if (drives & (1 << i))
841 root[0] = 'A' + i;
842 type = GetDriveTypeW( root );
843 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
844 continue;
846 if (num_rows > count)
848 BYTE *data;
849 count *= 2;
850 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
851 table->data = data;
853 rec = (struct record_diskpartition *)(table->data + offset);
854 rec->bootable = (i == 2) ? -1 : 0;
855 rec->bootpartition = (i == 2) ? -1 : 0;
856 sprintfW( device_id, fmtW, index );
857 rec->device_id = heap_strdupW( device_id );
858 rec->diskindex = index;
859 rec->index = 0;
860 rec->pnpdevice_id = heap_strdupW( device_id );
861 get_freespace( root, &size );
862 rec->size = size;
863 rec->startingoffset = 0;
864 rec->type = get_filesystem( root );
865 offset += sizeof(*rec);
866 num_rows++;
867 index++;
870 TRACE("created %u rows\n", num_rows);
871 table->num_rows = num_rows;
874 static void fill_logicaldisk( struct table *table )
876 static const WCHAR fmtW[] = {'%','c',':',0};
877 WCHAR device_id[3], root[] = {'A',':','\\',0};
878 struct record_logicaldisk *rec;
879 UINT i, num_rows = 0, offset = 0, count = 4, type;
880 UINT64 size = 1024 * 1024 * 1024;
881 DWORD drives = GetLogicalDrives();
883 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
885 for (i = 0; i < sizeof(drives); i++)
887 if (drives & (1 << i))
889 root[0] = 'A' + i;
890 type = GetDriveTypeW( root );
891 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
892 continue;
894 if (num_rows > count)
896 BYTE *data;
897 count *= 2;
898 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
899 table->data = data;
901 rec = (struct record_logicaldisk *)(table->data + offset);
902 sprintfW( device_id, fmtW, 'A' + i );
903 rec->device_id = heap_strdupW( device_id );
904 rec->drivetype = type;
905 rec->filesystem = get_filesystem( root );
906 rec->freespace = get_freespace( root, &size );
907 rec->name = heap_strdupW( device_id );
908 rec->size = size;
909 offset += sizeof(*rec);
910 num_rows++;
913 TRACE("created %u rows\n", num_rows);
914 table->num_rows = num_rows;
917 static UINT16 get_connection_status( IF_OPER_STATUS status )
919 switch (status)
921 case IfOperStatusDown:
922 return 0; /* Disconnected */
923 case IfOperStatusUp:
924 return 2; /* Connected */
925 default:
926 ERR("unhandled status %u\n", status);
927 break;
929 return 0;
931 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
933 static const WCHAR fmtW[] =
934 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
935 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
936 WCHAR *ret;
938 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
939 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
940 return ret;
942 static const WCHAR *get_adaptertype( DWORD type )
944 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
945 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
946 static const WCHAR firewireW[] = {'1','3','9','4',0};
947 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
949 switch (type)
951 case IF_TYPE_ETHERNET_CSMACD: return ethernetW;
952 case IF_TYPE_IEEE80211: return wirelessW;
953 case IF_TYPE_IEEE1394: return firewireW;
954 case IF_TYPE_TUNNEL: return tunnelW;
955 default: break;
957 return NULL;
960 static void fill_networkadapter( struct table *table )
962 static const WCHAR fmtW[] = {'%','u',0};
963 WCHAR device_id[11];
964 struct record_networkadapter *rec;
965 IP_ADAPTER_ADDRESSES *aa, *buffer;
966 UINT num_rows = 0, offset = 0;
967 DWORD size = 0, ret;
969 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
970 if (ret != ERROR_BUFFER_OVERFLOW) return;
972 if (!(buffer = heap_alloc( size ))) return;
973 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
975 heap_free( buffer );
976 return;
978 for (aa = buffer; aa; aa = aa->Next) num_rows++;
979 if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
981 heap_free( buffer );
982 return;
984 for (aa = buffer; aa; aa = aa->Next)
986 rec = (struct record_networkadapter *)(table->data + offset);
987 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
988 rec->adaptertype = get_adaptertype( aa->IfType );
989 rec->device_id = heap_strdupW( device_id );
990 rec->interface_index = aa->u.s.IfIndex;
991 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
992 rec->manufacturer = compsys_manufacturerW;
993 rec->netconnection_status = get_connection_status( aa->OperStatus );
994 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
995 rec->speed = 1000000;
996 offset += sizeof(*rec);
998 TRACE("created %u rows\n", num_rows);
999 table->num_rows = num_rows;
1001 heap_free( buffer );
1004 static WCHAR *get_cmdline( DWORD process_id )
1006 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1007 return NULL; /* FIXME handle different process case */
1010 static void fill_process( struct table *table )
1012 static const WCHAR fmtW[] = {'%','u',0};
1013 WCHAR handle[11];
1014 struct record_process *rec;
1015 PROCESSENTRY32W entry;
1016 HANDLE snap;
1017 UINT num_rows = 0, offset = 0, count = 8;
1019 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1020 if (snap == INVALID_HANDLE_VALUE) return;
1022 entry.dwSize = sizeof(entry);
1023 if (!Process32FirstW( snap, &entry )) goto done;
1024 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
1028 if (num_rows > count)
1030 BYTE *data;
1031 count *= 2;
1032 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
1033 table->data = data;
1035 rec = (struct record_process *)(table->data + offset);
1036 rec->caption = heap_strdupW( entry.szExeFile );
1037 rec->commandline = get_cmdline( entry.th32ProcessID );
1038 rec->description = heap_strdupW( entry.szExeFile );
1039 sprintfW( handle, fmtW, entry.th32ProcessID );
1040 rec->handle = heap_strdupW( handle );
1041 rec->process_id = entry.th32ProcessID;
1042 rec->pprocess_id = entry.th32ParentProcessID;
1043 rec->thread_count = entry.cntThreads;
1044 rec->get_owner = process_get_owner;
1045 offset += sizeof(*rec);
1046 num_rows++;
1047 } while (Process32NextW( snap, &entry ));
1049 TRACE("created %u rows\n", num_rows);
1050 table->num_rows = num_rows;
1052 done:
1053 CloseHandle( snap );
1056 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1058 #ifdef __i386__
1059 __asm__("pushl %%ebx\n\t"
1060 "cpuid\n\t"
1061 "movl %%ebx, %%esi\n\t"
1062 "popl %%ebx"
1063 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1064 : "0" (ax));
1065 #endif
1068 static void get_processor_id( WCHAR *processor_id )
1070 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1071 unsigned int regs[4] = {0, 0, 0, 0};
1073 do_cpuid( 1, regs );
1074 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1076 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1078 unsigned int i;
1079 unsigned char *p = (unsigned char *)regs;
1081 for (i = 0; i < len; i++)
1083 buffer[i] = *p++;
1085 buffer[i] = 0;
1087 static void get_processor_manufacturer( WCHAR *manufacturer )
1089 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1091 do_cpuid( 0, regs );
1092 tmp = regs[2]; /* swap edx and ecx */
1093 regs[2] = regs[3];
1094 regs[3] = tmp;
1096 regs_to_str( regs + 1, 12, manufacturer );
1098 static void get_processor_name( WCHAR *name )
1100 unsigned int regs[4] = {0, 0, 0, 0};
1102 do_cpuid( 0x80000000, regs );
1103 if (regs[0] >= 0x80000004)
1105 do_cpuid( 0x80000002, regs );
1106 regs_to_str( regs, 16, name );
1107 do_cpuid( 0x80000003, regs );
1108 regs_to_str( regs, 16, name + 16 );
1109 do_cpuid( 0x80000004, regs );
1110 regs_to_str( regs, 16, name + 32 );
1113 static UINT get_processor_maxclockspeed( void )
1115 PROCESSOR_POWER_INFORMATION *info;
1116 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1117 NTSTATUS status;
1119 if ((info = heap_alloc( size )))
1121 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1122 if (!status) ret = info[0].MaxMhz;
1123 heap_free( info );
1125 return ret;
1128 static void fill_processor( struct table *table )
1130 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1131 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1132 struct record_processor *rec;
1133 UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
1135 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
1137 get_processor_id( processor_id );
1138 get_processor_manufacturer( manufacturer );
1139 get_processor_name( name );
1141 maxclockspeed = get_processor_maxclockspeed();
1142 num_logical_processors = get_logical_processor_count() / count;
1144 for (i = 0; i < count; i++)
1146 rec = (struct record_processor *)(table->data + offset);
1147 rec->cpu_status = 1; /* CPU Enabled */
1148 sprintfW( device_id, fmtW, i );
1149 rec->device_id = heap_strdupW( device_id );
1150 rec->family = 2; /* Unknown */
1151 rec->manufacturer = heap_strdupW( manufacturer );
1152 rec->maxclockspeed = maxclockspeed;
1153 rec->name = heap_strdupW( name );
1154 rec->num_logical_processors = num_logical_processors;
1155 rec->processor_id = heap_strdupW( processor_id );
1156 rec->unique_id = NULL;
1157 offset += sizeof(*rec);
1160 TRACE("created %u rows\n", count);
1161 table->num_rows = count;
1164 static WCHAR *get_lastbootuptime(void)
1166 static const WCHAR fmtW[] =
1167 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1168 '.','%','0','6','u','+','0','0','0',0};
1169 SYSTEM_TIMEOFDAY_INFORMATION ti;
1170 TIME_FIELDS tf;
1171 WCHAR *ret;
1173 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1175 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1176 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1177 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1178 return ret;
1180 static const WCHAR *get_osarchitecture(void)
1182 SYSTEM_INFO info;
1183 GetNativeSystemInfo( &info );
1184 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1185 return os_32bitW;
1187 static WCHAR *get_systemdirectory(void)
1189 void *redir;
1190 WCHAR *ret;
1192 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1193 Wow64DisableWow64FsRedirection( &redir );
1194 GetSystemDirectoryW( ret, MAX_PATH );
1195 Wow64RevertWow64FsRedirection( redir );
1196 return ret;
1199 static void fill_os( struct table *table )
1201 struct record_operatingsystem *rec;
1203 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1205 rec = (struct record_operatingsystem *)table->data;
1206 rec->caption = os_captionW;
1207 rec->csdversion = os_csdversionW;
1208 rec->lastbootuptime = get_lastbootuptime();
1209 rec->osarchitecture = get_osarchitecture();
1210 rec->oslanguage = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
1211 rec->osproductsuite = 2461140; /* Windows XP Professional */
1212 rec->ostype = 18; /* WINNT */
1213 rec->servicepackmajor = 3;
1214 rec->suitemask = 272; /* Single User + Terminal */
1215 rec->systemdirectory = get_systemdirectory();
1216 rec->version = os_versionW;
1218 TRACE("created 1 row\n");
1219 table->num_rows = 1;
1222 static const WCHAR *get_service_type( DWORD type )
1224 static const WCHAR filesystem_driverW[] =
1225 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1226 static const WCHAR kernel_driverW[] =
1227 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1228 static const WCHAR own_processW[] =
1229 {'O','w','n',' ','P','r','o','c','e','s','s',0};
1230 static const WCHAR share_processW[] =
1231 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1233 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
1234 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
1235 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
1236 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1237 else ERR("unhandled type 0x%08x\n", type);
1238 return NULL;
1240 static const WCHAR *get_service_state( DWORD state )
1242 static const WCHAR runningW[] =
1243 {'R','u','n','n','i','n','g',0};
1244 static const WCHAR start_pendingW[] =
1245 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1246 static const WCHAR stop_pendingW[] =
1247 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1248 static const WCHAR stoppedW[] =
1249 {'S','t','o','p','p','e','d',0};
1250 static const WCHAR unknownW[] =
1251 {'U','n','k','n','o','w','n',0};
1253 switch (state)
1255 case SERVICE_STOPPED: return stoppedW;
1256 case SERVICE_START_PENDING: return start_pendingW;
1257 case SERVICE_STOP_PENDING: return stop_pendingW;
1258 case SERVICE_RUNNING: return runningW;
1259 default:
1260 ERR("unknown state %u\n", state);
1261 return unknownW;
1265 static const WCHAR *get_service_startmode( DWORD mode )
1267 static const WCHAR bootW[] = {'B','o','o','t',0};
1268 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
1269 static const WCHAR autoW[] = {'A','u','t','o',0};
1270 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
1271 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
1272 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
1274 switch (mode)
1276 case SERVICE_BOOT_START: return bootW;
1277 case SERVICE_SYSTEM_START: return systemW;
1278 case SERVICE_AUTO_START: return autoW;
1279 case SERVICE_DEMAND_START: return manualW;
1280 case SERVICE_DISABLED: return disabledW;
1281 default:
1282 ERR("unknown mode 0x%x\n", mode);
1283 return unknownW;
1287 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
1289 QUERY_SERVICE_CONFIGW *config = NULL;
1290 SC_HANDLE service;
1291 DWORD size;
1293 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
1294 QueryServiceConfigW( service, NULL, 0, &size );
1295 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
1296 if (!(config = heap_alloc( size ))) goto done;
1297 if (QueryServiceConfigW( service, config, size, &size )) goto done;
1298 heap_free( config );
1299 config = NULL;
1301 done:
1302 CloseServiceHandle( service );
1303 return config;
1306 static void fill_service( struct table *table )
1308 struct record_service *rec;
1309 SC_HANDLE manager;
1310 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
1311 SERVICE_STATUS_PROCESS *status;
1312 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
1313 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
1314 UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
1315 BOOL ret;
1317 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
1318 if (!(services = heap_alloc( size ))) goto done;
1320 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1321 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1322 &count, NULL, NULL );
1323 if (!ret)
1325 if (GetLastError() != ERROR_MORE_DATA) goto done;
1326 size = needed;
1327 if (!(tmp = heap_realloc( services, size ))) goto done;
1328 services = tmp;
1329 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1330 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1331 &count, NULL, NULL );
1332 if (!ret) goto done;
1334 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
1336 GetComputerNameW( sysnameW, &len );
1338 for (i = 0; i < count; i++)
1340 QUERY_SERVICE_CONFIGW *config;
1342 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
1344 status = &services[i].ServiceStatusProcess;
1345 rec = (struct record_service *)(table->data + offset);
1346 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
1347 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
1348 rec->displayname = heap_strdupW( services[i].lpDisplayName );
1349 rec->name = heap_strdupW( services[i].lpServiceName );
1350 rec->process_id = status->dwProcessId;
1351 rec->servicetype = get_service_type( status->dwServiceType );
1352 rec->startmode = get_service_startmode( config->dwStartType );
1353 rec->state = get_service_state( status->dwCurrentState );
1354 rec->systemname = heap_strdupW( sysnameW );
1355 rec->pause_service = service_pause_service;
1356 rec->resume_service = service_resume_service;
1357 rec->start_service = service_start_service;
1358 rec->stop_service = service_stop_service;
1359 heap_free( config );
1360 offset += sizeof(*rec);
1361 num_rows++;
1364 TRACE("created %u rows\n", num_rows);
1365 table->num_rows = num_rows;
1367 done:
1368 CloseServiceHandle( manager );
1369 heap_free( services );
1372 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1374 HDC hdc = GetDC( NULL );
1375 UINT32 ret;
1377 if (!hdc) return 32;
1378 ret = GetDeviceCaps( hdc, BITSPIXEL );
1379 *hres = GetDeviceCaps( hdc, HORZRES );
1380 *vres = GetDeviceCaps( hdc, VERTRES );
1381 ReleaseDC( NULL, hdc );
1382 return ret;
1385 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
1387 static const WCHAR fmtW[] =
1388 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
1389 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
1390 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
1391 WCHAR *ret;
1393 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
1394 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
1395 return ret;
1398 static void fill_videocontroller( struct table *table )
1401 struct record_videocontroller *rec;
1402 HRESULT hr;
1403 IDXGIFactory *factory = NULL;
1404 IDXGIAdapter *adapter = NULL;
1405 DXGI_ADAPTER_DESC desc;
1406 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1407 const WCHAR *name = videocontroller_deviceidW;
1409 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1411 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1412 if (FAILED(hr)) goto done;
1414 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1415 if (FAILED(hr)) goto done;
1417 hr = IDXGIAdapter_GetDesc( adapter, &desc );
1418 if (SUCCEEDED(hr))
1420 vidmem = desc.DedicatedVideoMemory;
1421 name = desc.Description;
1424 done:
1425 rec = (struct record_videocontroller *)table->data;
1426 rec->adapter_ram = vidmem;
1427 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
1428 rec->current_horizontalres = hres;
1429 rec->current_verticalres = vres;
1430 rec->description = heap_strdupW( name );
1431 rec->device_id = videocontroller_deviceidW;
1432 rec->name = heap_strdupW( name );
1433 rec->pnpdevice_id = get_pnpdeviceid( &desc );
1435 TRACE("created 1 row\n");
1436 table->num_rows = 1;
1438 if (adapter) IDXGIAdapter_Release( adapter );
1439 if (factory) IDXGIFactory_Release( factory );
1442 static struct table builtin_classes[] =
1444 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1445 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1446 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, NULL, fill_cdromdrive },
1447 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1448 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), (BYTE *)data_diskdrive },
1449 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, NULL, fill_diskpartition },
1450 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1451 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1452 { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1453 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), (BYTE *)data_param },
1454 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1455 { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1456 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), (BYTE *)data_qualifier },
1457 { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1458 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), (BYTE *)data_sounddevice },
1459 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1460 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1463 void init_table_list( void )
1465 static struct list tables = LIST_INIT( tables );
1466 UINT i;
1468 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
1469 table_list = &tables;