wbemprox: Implement more properties of Win32_OperatingSystem.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob2106f67e75c29249779b0030cb5be3d98dd12f90
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_filesystemW[] =
127 {'F','i','l','e','S','y','s','t','e','m',0};
128 static const WCHAR prop_flavorW[] =
129 {'F','l','a','v','o','r',0};
130 static const WCHAR prop_freespaceW[] =
131 {'F','r','e','e','S','p','a','c','e',0};
132 static const WCHAR prop_handleW[] =
133 {'H','a','n','d','l','e',0};
134 static const WCHAR prop_idW[] =
135 {'I','D',0};
136 static const WCHAR prop_indexW[] =
137 {'I','n','d','e','x',0};
138 static const WCHAR prop_interfaceindexW[] =
139 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
140 static const WCHAR prop_intvalueW[] =
141 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
142 static const WCHAR prop_lastbootuptimeW[] =
143 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
144 static const WCHAR prop_macaddressW[] =
145 {'M','A','C','A','d','d','r','e','s','s',0};
146 static const WCHAR prop_manufacturerW[] =
147 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
148 static const WCHAR prop_maxclockspeedW[] =
149 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
150 static const WCHAR prop_memberW[] =
151 {'M','e','m','b','e','r',0};
152 static const WCHAR prop_methodW[] =
153 {'M','e','t','h','o','d',0};
154 static const WCHAR prop_modelW[] =
155 {'M','o','d','e','l',0};
156 static const WCHAR prop_netconnectionstatusW[] =
157 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
158 static const WCHAR prop_numlogicalprocessorsW[] =
159 {'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};
160 static const WCHAR prop_numprocessorsW[] =
161 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
162 static const WCHAR prop_osarchitectureW[] =
163 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
164 static const WCHAR prop_oslanguageW[] =
165 {'O','S','L','a','n','g','u','a','g','e',0};
166 static const WCHAR prop_osproductsuiteW[] =
167 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
168 static const WCHAR prop_ostypeW[] =
169 {'O','S','T','y','p','e',0};
170 static const WCHAR prop_parameterW[] =
171 {'P','a','r','a','m','e','t','e','r',0};
172 static const WCHAR prop_pnpdeviceidW[] =
173 {'P','N','P','D','e','v','i','c','e','I','D',0};
174 static const WCHAR prop_pprocessidW[] =
175 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
176 static const WCHAR prop_processidW[] =
177 {'P','r','o','c','e','s','s','I','D',0};
178 static const WCHAR prop_processoridW[] =
179 {'P','r','o','c','e','s','s','o','r','I','d',0};
180 static const WCHAR prop_productnameW[] =
181 {'P','r','o','d','u','c','t','N','a','m','e',0};
182 static const WCHAR prop_releasedateW[] =
183 {'R','e','l','e','a','s','e','D','a','t','e',0};
184 static const WCHAR prop_serialnumberW[] =
185 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
186 static const WCHAR prop_servicepackmajorW[] =
187 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
188 static const WCHAR prop_servicetypeW[] =
189 {'S','e','r','v','i','c','e','T','y','p','e',0};
190 static const WCHAR prop_startmodeW[] =
191 {'S','t','a','r','t','M','o','d','e',0};
192 static const WCHAR prop_sizeW[] =
193 {'S','i','z','e',0};
194 static const WCHAR prop_speedW[] =
195 {'S','p','e','e','d',0};
196 static const WCHAR prop_startingoffsetW[] =
197 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
198 static const WCHAR prop_stateW[] =
199 {'S','t','a','t','e',0};
200 static const WCHAR prop_strvalueW[] =
201 {'S','t','r','i','n','g','V','a','l','u','e',0};
202 static const WCHAR prop_suitemaskW[] =
203 {'S','u','i','t','e','M','a','s','k',0};
204 static const WCHAR prop_systemdirectoryW[] =
205 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
206 static const WCHAR prop_systemnameW[] =
207 {'S','y','s','t','e','m','N','a','m','e',0};
208 static const WCHAR prop_tagW[] =
209 {'T','a','g',0};
210 static const WCHAR prop_threadcountW[] =
211 {'T','h','r','e','a','d','C','o','u','n','t',0};
212 static const WCHAR prop_totalphysicalmemoryW[] =
213 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
214 static const WCHAR prop_typeW[] =
215 {'T','y','p','e',0};
216 static const WCHAR prop_uniqueidW[] =
217 {'U','n','i','q','u','e','I','d',0};
218 static const WCHAR prop_varianttypeW[] =
219 {'V','a','r','i','a','n','t','T','y','p','e',0};
220 static const WCHAR prop_versionW[] =
221 {'V','e','r','s','i','o','n',0};
223 /* column definitions must be kept in sync with record structures below */
224 static const struct column col_baseboard[] =
226 { prop_manufacturerW, CIM_STRING },
227 { prop_serialnumberW, CIM_STRING },
228 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
230 static const struct column col_bios[] =
232 { prop_descriptionW, CIM_STRING },
233 { prop_manufacturerW, CIM_STRING },
234 { prop_releasedateW, CIM_DATETIME },
235 { prop_serialnumberW, CIM_STRING },
236 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
238 static const struct column col_cdromdrive[] =
240 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
241 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
242 { prop_nameW, CIM_STRING },
243 { prop_pnpdeviceidW, CIM_STRING }
245 static const struct column col_compsys[] =
247 { prop_descriptionW, CIM_STRING },
248 { prop_domainW, CIM_STRING },
249 { prop_domainroleW, CIM_UINT16 },
250 { prop_manufacturerW, CIM_STRING },
251 { prop_modelW, CIM_STRING },
252 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
253 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
254 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
255 { prop_totalphysicalmemoryW, CIM_UINT64 }
257 static const struct column col_diskdrive[] =
259 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
260 { prop_indexW, CIM_UINT32, VT_I4 },
261 { prop_manufacturerW, CIM_STRING },
262 { prop_modelW, CIM_STRING },
263 { prop_serialnumberW, CIM_STRING }
265 static const struct column col_diskpartition[] =
267 { prop_bootableW, CIM_BOOLEAN },
268 { prop_bootpartitionW, CIM_BOOLEAN },
269 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
270 { prop_diskindexW, CIM_UINT32, VT_I4 },
271 { prop_indexW, CIM_UINT32, VT_I4 },
272 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
273 { prop_sizeW, CIM_UINT64 },
274 { prop_startingoffsetW, CIM_UINT64 },
275 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
277 static const struct column col_logicaldisk[] =
279 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
280 { prop_drivetypeW, CIM_UINT32, VT_I4 },
281 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
282 { prop_freespaceW, CIM_UINT64 },
283 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
284 { prop_sizeW, CIM_UINT64 }
286 static const struct column col_networkadapter[] =
288 { prop_adaptertypeW, CIM_STRING },
289 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
290 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
291 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
292 { prop_manufacturerW, CIM_STRING },
293 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
294 { prop_pnpdeviceidW, CIM_STRING },
295 { prop_speedW, CIM_UINT64 }
297 static const struct column col_os[] =
299 { prop_captionW, CIM_STRING },
300 { prop_csdversionW, CIM_STRING },
301 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
302 { prop_osarchitectureW, CIM_STRING },
303 { prop_oslanguageW, CIM_UINT32, VT_I4 },
304 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
305 { prop_ostypeW, CIM_UINT16, VT_I4 },
306 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
307 { prop_suitemaskW, CIM_UINT32, VT_I4 },
308 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
309 { prop_versionW, CIM_STRING }
311 static const struct column col_param[] =
313 { prop_classW, CIM_STRING },
314 { prop_methodW, CIM_STRING },
315 { prop_directionW, CIM_SINT32 },
316 { prop_parameterW, CIM_STRING },
317 { prop_typeW, CIM_UINT32 },
318 { prop_varianttypeW, CIM_UINT32 },
319 { prop_defaultvalueW, CIM_UINT32 }
321 static const struct column col_process[] =
323 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
324 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
325 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
326 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
327 { prop_pprocessidW, CIM_UINT32, VT_I4 },
328 { prop_processidW, CIM_UINT32, VT_I4 },
329 { prop_threadcountW, CIM_UINT32, VT_I4 },
330 /* methods */
331 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
333 static const struct column col_processor[] =
335 { prop_cpustatusW, CIM_UINT16 },
336 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
337 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
338 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
339 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
340 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
341 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
342 { prop_uniqueidW, CIM_STRING }
344 static const struct column col_qualifier[] =
346 { prop_classW, CIM_STRING },
347 { prop_memberW, CIM_STRING },
348 { prop_typeW, CIM_UINT32 },
349 { prop_flavorW, CIM_SINT32 },
350 { prop_nameW, CIM_STRING },
351 { prop_intvalueW, CIM_SINT32 },
352 { prop_strvalueW, CIM_STRING }
354 static const struct column col_service[] =
356 { prop_acceptpauseW, CIM_BOOLEAN },
357 { prop_acceptstopW, CIM_BOOLEAN },
358 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
359 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
360 { prop_processidW, CIM_UINT32 },
361 { prop_servicetypeW, CIM_STRING },
362 { prop_startmodeW, CIM_STRING },
363 { prop_stateW, CIM_STRING },
364 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
365 /* methods */
366 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
367 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
368 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
369 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
371 static const struct column col_sounddevice[] =
373 { prop_productnameW, CIM_STRING }
375 static const struct column col_stdregprov[] =
377 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
378 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
379 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
381 static const struct column col_videocontroller[] =
383 { prop_adapterramW, CIM_UINT32 },
384 { prop_currentbitsperpixelW, CIM_UINT32 },
385 { prop_currenthorizontalresW, CIM_UINT32 },
386 { prop_currentverticalresW, CIM_UINT32 },
387 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
388 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
389 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
390 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
393 static const WCHAR baseboard_manufacturerW[] =
394 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
395 static const WCHAR baseboard_serialnumberW[] =
396 {'N','o','n','e',0};
397 static const WCHAR baseboard_tagW[] =
398 {'B','a','s','e',' ','B','o','a','r','d',0};
399 static const WCHAR bios_descriptionW[] =
400 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
401 static const WCHAR bios_manufacturerW[] =
402 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
403 static const WCHAR bios_releasedateW[] =
404 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
405 static const WCHAR bios_serialnumberW[] =
406 {'0',0};
407 static const WCHAR bios_versionW[] =
408 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
409 static const WCHAR cdromdrive_nameW[] =
410 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
411 static const WCHAR cdromdrive_pnpdeviceidW[]=
412 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
413 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
414 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
415 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
416 static const WCHAR compsys_descriptionW[] =
417 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
418 static const WCHAR compsys_domainW[] =
419 {'W','O','R','K','G','R','O','U','P',0};
420 static const WCHAR compsys_manufacturerW[] =
421 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
422 static const WCHAR compsys_modelW[] =
423 {'W','i','n','e',0};
424 static const WCHAR diskdrive_deviceidW[] =
425 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
426 static const WCHAR diskdrive_modelW[] =
427 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
428 static const WCHAR diskdrive_manufacturerW[] =
429 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
430 static const WCHAR diskdrive_serialW[] =
431 {'W','I','N','E','H','D','I','S','K',0};
432 static const WCHAR networkadapter_pnpdeviceidW[]=
433 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
434 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
435 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
436 static const WCHAR os_captionW[] =
437 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
438 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
439 static const WCHAR os_csdversionW[] =
440 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
441 static const WCHAR os_32bitW[] =
442 {'3','2','-','b','i','t',0};
443 static const WCHAR os_64bitW[] =
444 {'6','4','-','b','i','t',0};
445 static const WCHAR os_versionW[] =
446 {'5','.','1','.','2','6','0','0',0};
447 static const WCHAR sounddevice_productnameW[] =
448 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
449 static const WCHAR videocontroller_deviceidW[] =
450 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
452 #include "pshpack1.h"
453 struct record_baseboard
455 const WCHAR *manufacturer;
456 const WCHAR *serialnumber;
457 const WCHAR *tag;
459 struct record_bios
461 const WCHAR *description;
462 const WCHAR *manufacturer;
463 const WCHAR *releasedate;
464 const WCHAR *serialnumber;
465 const WCHAR *version;
467 struct record_cdromdrive
469 const WCHAR *device_id;
470 const WCHAR *drive;
471 const WCHAR *name;
472 const WCHAR *pnpdevice_id;
474 struct record_computersystem
476 const WCHAR *description;
477 const WCHAR *domain;
478 UINT16 domainrole;
479 const WCHAR *manufacturer;
480 const WCHAR *model;
481 const WCHAR *name;
482 UINT32 num_logical_processors;
483 UINT32 num_processors;
484 UINT64 total_physical_memory;
486 struct record_diskdrive
488 const WCHAR *device_id;
489 UINT32 index;
490 const WCHAR *manufacturer;
491 const WCHAR *name;
492 const WCHAR *serialnumber;
494 struct record_diskpartition
496 int bootable;
497 int bootpartition;
498 const WCHAR *device_id;
499 UINT32 diskindex;
500 UINT32 index;
501 const WCHAR *pnpdevice_id;
502 UINT64 size;
503 UINT64 startingoffset;
504 const WCHAR *type;
506 struct record_logicaldisk
508 const WCHAR *device_id;
509 UINT32 drivetype;
510 const WCHAR *filesystem;
511 UINT64 freespace;
512 const WCHAR *name;
513 UINT64 size;
515 struct record_networkadapter
517 const WCHAR *adaptertype;
518 const WCHAR *device_id;
519 INT32 interface_index;
520 const WCHAR *mac_address;
521 const WCHAR *manufacturer;
522 UINT16 netconnection_status;
523 const WCHAR *pnpdevice_id;
524 UINT64 speed;
526 struct record_operatingsystem
528 const WCHAR *caption;
529 const WCHAR *csdversion;
530 const WCHAR *lastbootuptime;
531 const WCHAR *osarchitecture;
532 UINT32 oslanguage;
533 UINT32 osproductsuite;
534 UINT16 ostype;
535 UINT16 servicepackmajor;
536 UINT32 suitemask;
537 const WCHAR *systemdirectory;
538 const WCHAR *version;
540 struct record_param
542 const WCHAR *class;
543 const WCHAR *method;
544 INT32 direction;
545 const WCHAR *parameter;
546 UINT32 type;
547 UINT32 varianttype;
548 UINT32 defaultvalue;
550 struct record_process
552 const WCHAR *caption;
553 const WCHAR *commandline;
554 const WCHAR *description;
555 const WCHAR *handle;
556 UINT32 pprocess_id;
557 UINT32 process_id;
558 UINT32 thread_count;
559 /* methods */
560 class_method *get_owner;
562 struct record_processor
564 UINT16 cpu_status;
565 const WCHAR *device_id;
566 const WCHAR *manufacturer;
567 UINT32 maxclockspeed;
568 const WCHAR *name;
569 UINT32 num_logical_processors;
570 const WCHAR *processor_id;
571 const WCHAR *unique_id;
573 struct record_qualifier
575 const WCHAR *class;
576 const WCHAR *member;
577 UINT32 type;
578 INT32 flavor;
579 const WCHAR *name;
580 INT32 intvalue;
581 const WCHAR *strvalue;
583 struct record_service
585 int accept_pause;
586 int accept_stop;
587 const WCHAR *displayname;
588 const WCHAR *name;
589 UINT32 process_id;
590 const WCHAR *servicetype;
591 const WCHAR *startmode;
592 const WCHAR *state;
593 const WCHAR *systemname;
594 /* methods */
595 class_method *pause_service;
596 class_method *resume_service;
597 class_method *start_service;
598 class_method *stop_service;
600 struct record_sounddevice
602 const WCHAR *productname;
604 struct record_stdregprov
606 class_method *enumkey;
607 class_method *enumvalues;
608 class_method *getstringvalue;
610 struct record_videocontroller
612 UINT32 adapter_ram;
613 UINT32 current_bitsperpixel;
614 UINT32 current_horizontalres;
615 UINT32 current_verticalres;
616 const WCHAR *description;
617 const WCHAR *device_id;
618 const WCHAR *name;
619 const WCHAR *pnpdevice_id;
621 #include "poppack.h"
623 static const struct record_baseboard data_baseboard[] =
625 { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
627 static const struct record_bios data_bios[] =
629 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW, bios_versionW }
631 static const struct record_diskdrive data_diskdrive[] =
633 { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
635 static const struct record_param data_param[] =
637 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
638 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
639 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
640 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
641 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
642 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
643 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
644 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
645 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
646 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
647 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
648 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
649 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
650 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
651 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
652 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
653 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
654 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
655 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
656 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
657 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
660 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
661 WBEM_FLAVOR_ORIGIN_PROPAGATED)
663 static const struct record_qualifier data_qualifier[] =
665 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
666 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
668 static const struct record_sounddevice data_sounddevice[] =
670 { sounddevice_productnameW }
672 static const struct record_stdregprov data_stdregprov[] =
674 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
677 static void fill_cdromdrive( struct table *table )
679 static const WCHAR fmtW[] = {'%','c',':',0};
680 WCHAR drive[3], root[] = {'A',':','\\',0};
681 struct record_cdromdrive *rec;
682 UINT i, num_rows = 0, offset = 0, count = 1;
683 DWORD drives = GetLogicalDrives();
685 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
687 for (i = 0; i < sizeof(drives); i++)
689 if (drives & (1 << i))
691 root[0] = 'A' + i;
692 if (GetDriveTypeW( root ) != DRIVE_CDROM)
693 continue;
695 if (num_rows > count)
697 BYTE *data;
698 count *= 2;
699 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
700 table->data = data;
702 rec = (struct record_cdromdrive *)(table->data + offset);
703 rec->device_id = cdromdrive_pnpdeviceidW;
704 sprintfW( drive, fmtW, 'A' + i );
705 rec->drive = heap_strdupW( drive );
706 rec->name = cdromdrive_nameW;
707 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
708 offset += sizeof(*rec);
709 num_rows++;
712 TRACE("created %u rows\n", num_rows);
713 table->num_rows = num_rows;
716 static UINT get_processor_count(void)
718 SYSTEM_BASIC_INFORMATION info;
720 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
721 return info.NumberOfProcessors;
724 static UINT get_logical_processor_count(void)
726 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
727 UINT i, j, count = 0;
728 NTSTATUS status;
729 ULONG len;
731 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
732 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
734 if (!(info = heap_alloc( len ))) return get_processor_count();
735 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
736 if (status != STATUS_SUCCESS)
738 heap_free( info );
739 return get_processor_count();
741 for (i = 0; i < len / sizeof(*info); i++)
743 if (info[i].Relationship != RelationProcessorCore) continue;
744 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
746 heap_free( info );
747 return count;
750 static UINT64 get_total_physical_memory(void)
752 MEMORYSTATUSEX status;
754 status.dwLength = sizeof(status);
755 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
756 return status.ullTotalPhys;
759 static WCHAR *get_computername(void)
761 WCHAR *ret;
762 DWORD size=MAX_COMPUTERNAME_LENGTH;
764 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
765 GetComputerNameW( ret, &size );
766 return ret;
769 static void fill_compsys( struct table *table )
771 struct record_computersystem *rec;
773 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
775 rec = (struct record_computersystem *)table->data;
776 rec->description = compsys_descriptionW;
777 rec->domain = compsys_domainW;
778 rec->domainrole = 0; /* standalone workstation */
779 rec->manufacturer = compsys_manufacturerW;
780 rec->model = compsys_modelW;
781 rec->name = get_computername();
782 rec->num_logical_processors = get_logical_processor_count();
783 rec->num_processors = get_processor_count();
784 rec->total_physical_memory = get_total_physical_memory();
786 TRACE("created 1 row\n");
787 table->num_rows = 1;
790 static WCHAR *get_filesystem( const WCHAR *root )
792 static const WCHAR ntfsW[] = {'N','T','F','S',0};
793 WCHAR buffer[MAX_PATH + 1];
795 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
796 return heap_strdupW( buffer );
797 return heap_strdupW( ntfsW );
800 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
802 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
803 ULARGE_INTEGER free;
804 DISK_GEOMETRY_EX info;
805 HANDLE handle;
807 free.QuadPart = 512 * 1024 * 1024;
808 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
810 root[4] = dir[0];
811 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
812 if (handle != INVALID_HANDLE_VALUE)
814 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
815 *disksize = info.DiskSize.QuadPart;
816 CloseHandle( handle );
818 return free.QuadPart;
821 static void fill_diskpartition( struct table *table )
823 static const WCHAR fmtW[] =
824 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
825 WCHAR device_id[32], root[] = {'A',':','\\',0};
826 struct record_diskpartition *rec;
827 UINT i, num_rows = 0, offset = 0, count = 4, type, index = 0;
828 UINT64 size = 1024 * 1024 * 1024;
829 DWORD drives = GetLogicalDrives();
831 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
833 for (i = 0; i < sizeof(drives); i++)
835 if (drives & (1 << i))
837 root[0] = 'A' + i;
838 type = GetDriveTypeW( root );
839 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
840 continue;
842 if (num_rows > count)
844 BYTE *data;
845 count *= 2;
846 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
847 table->data = data;
849 rec = (struct record_diskpartition *)(table->data + offset);
850 rec->bootable = (i == 2) ? -1 : 0;
851 rec->bootpartition = (i == 2) ? -1 : 0;
852 sprintfW( device_id, fmtW, index );
853 rec->device_id = heap_strdupW( device_id );
854 rec->diskindex = index;
855 rec->index = 0;
856 rec->pnpdevice_id = heap_strdupW( device_id );
857 get_freespace( root, &size );
858 rec->size = size;
859 rec->startingoffset = 0;
860 rec->type = get_filesystem( root );
861 offset += sizeof(*rec);
862 num_rows++;
863 index++;
866 TRACE("created %u rows\n", num_rows);
867 table->num_rows = num_rows;
870 static void fill_logicaldisk( struct table *table )
872 static const WCHAR fmtW[] = {'%','c',':',0};
873 WCHAR device_id[3], root[] = {'A',':','\\',0};
874 struct record_logicaldisk *rec;
875 UINT i, num_rows = 0, offset = 0, count = 4, type;
876 UINT64 size = 1024 * 1024 * 1024;
877 DWORD drives = GetLogicalDrives();
879 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
881 for (i = 0; i < sizeof(drives); i++)
883 if (drives & (1 << i))
885 root[0] = 'A' + i;
886 type = GetDriveTypeW( root );
887 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
888 continue;
890 if (num_rows > count)
892 BYTE *data;
893 count *= 2;
894 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
895 table->data = data;
897 rec = (struct record_logicaldisk *)(table->data + offset);
898 sprintfW( device_id, fmtW, 'A' + i );
899 rec->device_id = heap_strdupW( device_id );
900 rec->drivetype = type;
901 rec->filesystem = get_filesystem( root );
902 rec->freespace = get_freespace( root, &size );
903 rec->name = heap_strdupW( device_id );
904 rec->size = size;
905 offset += sizeof(*rec);
906 num_rows++;
909 TRACE("created %u rows\n", num_rows);
910 table->num_rows = num_rows;
913 static UINT16 get_connection_status( IF_OPER_STATUS status )
915 switch (status)
917 case IfOperStatusDown:
918 return 0; /* Disconnected */
919 case IfOperStatusUp:
920 return 2; /* Connected */
921 default:
922 ERR("unhandled status %u\n", status);
923 break;
925 return 0;
927 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
929 static const WCHAR fmtW[] =
930 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
931 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
932 WCHAR *ret;
934 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
935 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
936 return ret;
938 static const WCHAR *get_adaptertype( DWORD type )
940 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
941 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
942 static const WCHAR firewireW[] = {'1','3','9','4',0};
943 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
945 switch (type)
947 case IF_TYPE_ETHERNET_CSMACD: return ethernetW;
948 case IF_TYPE_IEEE80211: return wirelessW;
949 case IF_TYPE_IEEE1394: return firewireW;
950 case IF_TYPE_TUNNEL: return tunnelW;
951 default: break;
953 return NULL;
956 static void fill_networkadapter( struct table *table )
958 static const WCHAR fmtW[] = {'%','u',0};
959 WCHAR device_id[11];
960 struct record_networkadapter *rec;
961 IP_ADAPTER_ADDRESSES *aa, *buffer;
962 UINT num_rows = 0, offset = 0;
963 DWORD size = 0, ret;
965 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
966 if (ret != ERROR_BUFFER_OVERFLOW) return;
968 if (!(buffer = heap_alloc( size ))) return;
969 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
971 heap_free( buffer );
972 return;
974 for (aa = buffer; aa; aa = aa->Next) num_rows++;
975 if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
977 heap_free( buffer );
978 return;
980 for (aa = buffer; aa; aa = aa->Next)
982 rec = (struct record_networkadapter *)(table->data + offset);
983 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
984 rec->adaptertype = get_adaptertype( aa->IfType );
985 rec->device_id = heap_strdupW( device_id );
986 rec->interface_index = aa->u.s.IfIndex;
987 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
988 rec->manufacturer = compsys_manufacturerW;
989 rec->netconnection_status = get_connection_status( aa->OperStatus );
990 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
991 rec->speed = 1000000;
992 offset += sizeof(*rec);
994 TRACE("created %u rows\n", num_rows);
995 table->num_rows = num_rows;
997 heap_free( buffer );
1000 static WCHAR *get_cmdline( DWORD process_id )
1002 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1003 return NULL; /* FIXME handle different process case */
1006 static void fill_process( struct table *table )
1008 static const WCHAR fmtW[] = {'%','u',0};
1009 WCHAR handle[11];
1010 struct record_process *rec;
1011 PROCESSENTRY32W entry;
1012 HANDLE snap;
1013 UINT num_rows = 0, offset = 0, count = 8;
1015 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1016 if (snap == INVALID_HANDLE_VALUE) return;
1018 entry.dwSize = sizeof(entry);
1019 if (!Process32FirstW( snap, &entry )) goto done;
1020 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
1024 if (num_rows > count)
1026 BYTE *data;
1027 count *= 2;
1028 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
1029 table->data = data;
1031 rec = (struct record_process *)(table->data + offset);
1032 rec->caption = heap_strdupW( entry.szExeFile );
1033 rec->commandline = get_cmdline( entry.th32ProcessID );
1034 rec->description = heap_strdupW( entry.szExeFile );
1035 sprintfW( handle, fmtW, entry.th32ProcessID );
1036 rec->handle = heap_strdupW( handle );
1037 rec->process_id = entry.th32ProcessID;
1038 rec->pprocess_id = entry.th32ParentProcessID;
1039 rec->thread_count = entry.cntThreads;
1040 rec->get_owner = process_get_owner;
1041 offset += sizeof(*rec);
1042 num_rows++;
1043 } while (Process32NextW( snap, &entry ));
1045 TRACE("created %u rows\n", num_rows);
1046 table->num_rows = num_rows;
1048 done:
1049 CloseHandle( snap );
1052 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1054 #ifdef __i386__
1055 __asm__("pushl %%ebx\n\t"
1056 "cpuid\n\t"
1057 "movl %%ebx, %%esi\n\t"
1058 "popl %%ebx"
1059 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1060 : "0" (ax));
1061 #endif
1064 static void get_processor_id( WCHAR *processor_id )
1066 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1067 unsigned int regs[4] = {0, 0, 0, 0};
1069 do_cpuid( 1, regs );
1070 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1072 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1074 unsigned int i;
1075 unsigned char *p = (unsigned char *)regs;
1077 for (i = 0; i < len; i++)
1079 buffer[i] = *p++;
1081 buffer[i] = 0;
1083 static void get_processor_manufacturer( WCHAR *manufacturer )
1085 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1087 do_cpuid( 0, regs );
1088 tmp = regs[2]; /* swap edx and ecx */
1089 regs[2] = regs[3];
1090 regs[3] = tmp;
1092 regs_to_str( regs + 1, 12, manufacturer );
1094 static void get_processor_name( WCHAR *name )
1096 unsigned int regs[4] = {0, 0, 0, 0};
1098 do_cpuid( 0x80000000, regs );
1099 if (regs[0] >= 0x80000004)
1101 do_cpuid( 0x80000002, regs );
1102 regs_to_str( regs, 16, name );
1103 do_cpuid( 0x80000003, regs );
1104 regs_to_str( regs, 16, name + 16 );
1105 do_cpuid( 0x80000004, regs );
1106 regs_to_str( regs, 16, name + 32 );
1109 static UINT get_processor_maxclockspeed( void )
1111 PROCESSOR_POWER_INFORMATION *info;
1112 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1113 NTSTATUS status;
1115 if ((info = heap_alloc( size )))
1117 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1118 if (!status) ret = info[0].MaxMhz;
1119 heap_free( info );
1121 return ret;
1124 static void fill_processor( struct table *table )
1126 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1127 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1128 struct record_processor *rec;
1129 UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
1131 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
1133 get_processor_id( processor_id );
1134 get_processor_manufacturer( manufacturer );
1135 get_processor_name( name );
1137 maxclockspeed = get_processor_maxclockspeed();
1138 num_logical_processors = get_logical_processor_count() / count;
1140 for (i = 0; i < count; i++)
1142 rec = (struct record_processor *)(table->data + offset);
1143 rec->cpu_status = 1; /* CPU Enabled */
1144 sprintfW( device_id, fmtW, i );
1145 rec->device_id = heap_strdupW( device_id );
1146 rec->manufacturer = heap_strdupW( manufacturer );
1147 rec->maxclockspeed = maxclockspeed;
1148 rec->name = heap_strdupW( name );
1149 rec->num_logical_processors = num_logical_processors;
1150 rec->processor_id = heap_strdupW( processor_id );
1151 rec->unique_id = NULL;
1152 offset += sizeof(*rec);
1155 TRACE("created %u rows\n", count);
1156 table->num_rows = count;
1159 static WCHAR *get_lastbootuptime(void)
1161 static const WCHAR fmtW[] =
1162 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1163 '.','%','0','6','u','+','0','0','0',0};
1164 SYSTEM_TIMEOFDAY_INFORMATION ti;
1165 TIME_FIELDS tf;
1166 WCHAR *ret;
1168 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1170 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1171 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1172 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1173 return ret;
1175 static const WCHAR *get_osarchitecture(void)
1177 SYSTEM_INFO info;
1178 GetNativeSystemInfo( &info );
1179 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1180 return os_32bitW;
1182 static WCHAR *get_systemdirectory(void)
1184 void *redir;
1185 WCHAR *ret;
1187 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1188 Wow64DisableWow64FsRedirection( &redir );
1189 GetSystemDirectoryW( ret, MAX_PATH );
1190 Wow64RevertWow64FsRedirection( redir );
1191 return ret;
1194 static void fill_os( struct table *table )
1196 struct record_operatingsystem *rec;
1198 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1200 rec = (struct record_operatingsystem *)table->data;
1201 rec->caption = os_captionW;
1202 rec->csdversion = os_csdversionW;
1203 rec->lastbootuptime = get_lastbootuptime();
1204 rec->osarchitecture = get_osarchitecture();
1205 rec->oslanguage = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
1206 rec->osproductsuite = 2461140; /* Windows XP Professional */
1207 rec->ostype = 18; /* WINNT */
1208 rec->servicepackmajor = 3;
1209 rec->suitemask = 272; /* Single User + Terminal */
1210 rec->systemdirectory = get_systemdirectory();
1211 rec->version = os_versionW;
1213 TRACE("created 1 row\n");
1214 table->num_rows = 1;
1217 static const WCHAR *get_service_type( DWORD type )
1219 static const WCHAR filesystem_driverW[] =
1220 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1221 static const WCHAR kernel_driverW[] =
1222 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1223 static const WCHAR own_processW[] =
1224 {'O','w','n',' ','P','r','o','c','e','s','s',0};
1225 static const WCHAR share_processW[] =
1226 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1228 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
1229 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
1230 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
1231 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1232 else ERR("unhandled type 0x%08x\n", type);
1233 return NULL;
1235 static const WCHAR *get_service_state( DWORD state )
1237 static const WCHAR runningW[] =
1238 {'R','u','n','n','i','n','g',0};
1239 static const WCHAR start_pendingW[] =
1240 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1241 static const WCHAR stop_pendingW[] =
1242 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1243 static const WCHAR stoppedW[] =
1244 {'S','t','o','p','p','e','d',0};
1245 static const WCHAR unknownW[] =
1246 {'U','n','k','n','o','w','n',0};
1248 switch (state)
1250 case SERVICE_STOPPED: return stoppedW;
1251 case SERVICE_START_PENDING: return start_pendingW;
1252 case SERVICE_STOP_PENDING: return stop_pendingW;
1253 case SERVICE_RUNNING: return runningW;
1254 default:
1255 ERR("unknown state %u\n", state);
1256 return unknownW;
1260 static const WCHAR *get_service_startmode( DWORD mode )
1262 static const WCHAR bootW[] = {'B','o','o','t',0};
1263 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
1264 static const WCHAR autoW[] = {'A','u','t','o',0};
1265 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
1266 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
1267 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
1269 switch (mode)
1271 case SERVICE_BOOT_START: return bootW;
1272 case SERVICE_SYSTEM_START: return systemW;
1273 case SERVICE_AUTO_START: return autoW;
1274 case SERVICE_DEMAND_START: return manualW;
1275 case SERVICE_DISABLED: return disabledW;
1276 default:
1277 ERR("unknown mode 0x%x\n", mode);
1278 return unknownW;
1282 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
1284 QUERY_SERVICE_CONFIGW *config = NULL;
1285 SC_HANDLE service;
1286 DWORD size;
1288 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
1289 QueryServiceConfigW( service, NULL, 0, &size );
1290 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
1291 if (!(config = heap_alloc( size ))) goto done;
1292 if (QueryServiceConfigW( service, config, size, &size )) goto done;
1293 heap_free( config );
1294 config = NULL;
1296 done:
1297 CloseServiceHandle( service );
1298 return config;
1301 static void fill_service( struct table *table )
1303 struct record_service *rec;
1304 SC_HANDLE manager;
1305 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
1306 SERVICE_STATUS_PROCESS *status;
1307 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
1308 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
1309 UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
1310 BOOL ret;
1312 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
1313 if (!(services = heap_alloc( size ))) goto done;
1315 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1316 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1317 &count, NULL, NULL );
1318 if (!ret)
1320 if (GetLastError() != ERROR_MORE_DATA) goto done;
1321 size = needed;
1322 if (!(tmp = heap_realloc( services, size ))) goto done;
1323 services = tmp;
1324 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1325 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1326 &count, NULL, NULL );
1327 if (!ret) goto done;
1329 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
1331 GetComputerNameW( sysnameW, &len );
1333 for (i = 0; i < count; i++)
1335 QUERY_SERVICE_CONFIGW *config;
1337 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
1339 status = &services[i].ServiceStatusProcess;
1340 rec = (struct record_service *)(table->data + offset);
1341 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
1342 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
1343 rec->displayname = heap_strdupW( services[i].lpDisplayName );
1344 rec->name = heap_strdupW( services[i].lpServiceName );
1345 rec->process_id = status->dwProcessId;
1346 rec->servicetype = get_service_type( status->dwServiceType );
1347 rec->startmode = get_service_startmode( config->dwStartType );
1348 rec->state = get_service_state( status->dwCurrentState );
1349 rec->systemname = heap_strdupW( sysnameW );
1350 rec->pause_service = service_pause_service;
1351 rec->resume_service = service_resume_service;
1352 rec->start_service = service_start_service;
1353 rec->stop_service = service_stop_service;
1354 heap_free( config );
1355 offset += sizeof(*rec);
1356 num_rows++;
1359 TRACE("created %u rows\n", num_rows);
1360 table->num_rows = num_rows;
1362 done:
1363 CloseServiceHandle( manager );
1364 heap_free( services );
1367 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1369 HDC hdc = GetDC( NULL );
1370 UINT32 ret;
1372 if (!hdc) return 32;
1373 ret = GetDeviceCaps( hdc, BITSPIXEL );
1374 *hres = GetDeviceCaps( hdc, HORZRES );
1375 *vres = GetDeviceCaps( hdc, VERTRES );
1376 ReleaseDC( NULL, hdc );
1377 return ret;
1380 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
1382 static const WCHAR fmtW[] =
1383 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
1384 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
1385 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
1386 WCHAR *ret;
1388 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
1389 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
1390 return ret;
1393 static void fill_videocontroller( struct table *table )
1396 struct record_videocontroller *rec;
1397 HRESULT hr;
1398 IDXGIFactory *factory = NULL;
1399 IDXGIAdapter *adapter = NULL;
1400 DXGI_ADAPTER_DESC desc;
1401 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1402 const WCHAR *name = videocontroller_deviceidW;
1404 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1406 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1407 if (FAILED(hr)) goto done;
1409 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1410 if (FAILED(hr)) goto done;
1412 hr = IDXGIAdapter_GetDesc( adapter, &desc );
1413 if (SUCCEEDED(hr))
1415 vidmem = desc.DedicatedVideoMemory;
1416 name = desc.Description;
1419 done:
1420 rec = (struct record_videocontroller *)table->data;
1421 rec->adapter_ram = vidmem;
1422 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
1423 rec->current_horizontalres = hres;
1424 rec->current_verticalres = vres;
1425 rec->description = heap_strdupW( name );
1426 rec->device_id = videocontroller_deviceidW;
1427 rec->name = heap_strdupW( name );
1428 rec->pnpdevice_id = get_pnpdeviceid( &desc );
1430 TRACE("created 1 row\n");
1431 table->num_rows = 1;
1433 if (adapter) IDXGIAdapter_Release( adapter );
1434 if (factory) IDXGIFactory_Release( factory );
1437 static struct table builtin_classes[] =
1439 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1440 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1441 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, NULL, fill_cdromdrive },
1442 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1443 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), (BYTE *)data_diskdrive },
1444 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, NULL, fill_diskpartition },
1445 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1446 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1447 { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1448 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), (BYTE *)data_param },
1449 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1450 { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1451 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), (BYTE *)data_qualifier },
1452 { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1453 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), (BYTE *)data_sounddevice },
1454 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1455 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1458 void init_table_list( void )
1460 static struct list tables = LIST_INIT( tables );
1461 UINT i;
1463 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
1464 table_list = &tables;