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
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
27 #define WIN32_NO_STATUS
40 #include "wine/debug.h"
41 #include "wbemprox_private.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
45 static const WCHAR class_baseboardW[] =
46 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
47 static const WCHAR class_biosW[] =
48 {'W','i','n','3','2','_','B','I','O','S',0};
49 static const WCHAR class_compsysW[] =
50 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
51 static const WCHAR class_logicaldiskW[] =
52 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
53 static const WCHAR class_networkadapterW[] =
54 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
55 static const WCHAR class_osW[] =
56 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
57 static const WCHAR class_paramsW[] =
58 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
59 static const WCHAR class_processW[] =
60 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
61 static const WCHAR class_processorW[] =
62 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
63 static const WCHAR class_serviceW[] =
64 {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
65 static const WCHAR class_stdregprovW[] =
66 {'S','t','d','R','e','g','P','r','o','v',0};
67 static const WCHAR class_videocontrollerW[] =
68 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
70 static const WCHAR prop_acceptpauseW[] =
71 {'A','c','c','e','p','t','P','a','u','s','e',0};
72 static const WCHAR prop_acceptstopW[] =
73 {'A','c','c','e','p','t','S','t','o','p',0};
74 static const WCHAR prop_adapterramW[] =
75 {'A','d','a','p','t','e','r','R','A','M',0};
76 static const WCHAR prop_captionW[] =
77 {'C','a','p','t','i','o','n',0};
78 static const WCHAR prop_classW[] =
79 {'C','l','a','s','s',0};
80 static const WCHAR prop_commandlineW[] =
81 {'C','o','m','m','a','n','d','L','i','n','e',0};
82 static const WCHAR prop_cpustatusW[] =
83 {'C','p','u','S','t','a','t','u','s',0};
84 static const WCHAR prop_csdversionW[] =
85 {'C','S','D','V','e','r','s','i','o','n',0};
86 static const WCHAR prop_currentbitsperpixelW[] =
87 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
88 static const WCHAR prop_currenthorizontalresW[] =
89 {'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};
90 static const WCHAR prop_currentverticalresW[] =
91 {'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};
92 static const WCHAR prop_defaultvalueW[] =
93 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
94 static const WCHAR prop_descriptionW[] =
95 {'D','e','s','c','r','i','p','t','i','o','n',0};
96 static const WCHAR prop_deviceidW[] =
97 {'D','e','v','i','c','e','I','d',0};
98 static const WCHAR prop_directionW[] =
99 {'D','i','r','e','c','t','i','o','n',0};
100 static const WCHAR prop_displaynameW[] =
101 {'D','i','s','p','l','a','y','N','a','m','e',0};
102 static const WCHAR prop_domainroleW[] =
103 {'D','o','m','a','i','n','R','o','l','e',0};
104 static const WCHAR prop_drivetypeW[] =
105 {'D','r','i','v','e','T','y','p','e',0};
106 static const WCHAR prop_filesystemW[] =
107 {'F','i','l','e','S','y','s','t','e','m',0};
108 static const WCHAR prop_freespaceW[] =
109 {'F','r','e','e','S','p','a','c','e',0};
110 static const WCHAR prop_handleW[] =
111 {'H','a','n','d','l','e',0};
112 static const WCHAR prop_interfaceindexW[] =
113 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
114 static const WCHAR prop_macaddressW[] =
115 {'M','A','C','A','d','d','r','e','s','s',0};
116 static const WCHAR prop_manufacturerW[] =
117 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
118 static const WCHAR prop_maxclockspeedW[] =
119 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
120 static const WCHAR prop_methodW[] =
121 {'M','e','t','h','o','d',0};
122 static const WCHAR prop_modelW[] =
123 {'M','o','d','e','l',0};
124 static const WCHAR prop_nameW[] =
126 static const WCHAR prop_netconnectionstatusW[] =
127 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
128 static const WCHAR prop_numlogicalprocessorsW[] =
129 {'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};
130 static const WCHAR prop_numprocessorsW[] =
131 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
132 static const WCHAR prop_osarchitectureW[] =
133 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
134 static const WCHAR prop_oslanguageW[] =
135 {'O','S','L','a','n','g','u','a','g','e',0};
136 static const WCHAR prop_parameterW[] =
137 {'P','a','r','a','m','e','t','e','r',0};
138 static const WCHAR prop_pnpdeviceidW[] =
139 {'P','N','P','D','e','v','i','c','e','I','D',0};
140 static const WCHAR prop_pprocessidW[] =
141 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
142 static const WCHAR prop_processidW[] =
143 {'P','r','o','c','e','s','s','I','D',0};
144 static const WCHAR prop_processoridW[] =
145 {'P','r','o','c','e','s','s','o','r','I','d',0};
146 static const WCHAR prop_releasedateW[] =
147 {'R','e','l','e','a','s','e','D','a','t','e',0};
148 static const WCHAR prop_serialnumberW[] =
149 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
150 static const WCHAR prop_servicetypeW[] =
151 {'S','e','r','v','i','c','e','T','y','p','e',0};
152 static const WCHAR prop_startmodeW[] =
153 {'S','t','a','r','t','M','o','d','e',0};
154 static const WCHAR prop_sizeW[] =
156 static const WCHAR prop_speedW[] =
157 {'S','p','e','e','d',0};
158 static const WCHAR prop_stateW[] =
159 {'S','t','a','t','e',0};
160 static const WCHAR prop_systemdirectoryW[] =
161 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
162 static const WCHAR prop_systemnameW[] =
163 {'S','y','s','t','e','m','N','a','m','e',0};
164 static const WCHAR prop_tagW[] =
166 static const WCHAR prop_threadcountW[] =
167 {'T','h','r','e','a','d','C','o','u','n','t',0};
168 static const WCHAR prop_totalphysicalmemoryW[] =
169 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
170 static const WCHAR prop_typeW[] =
173 static const WCHAR method_enumkeyW[] =
174 {'E','n','u','m','K','e','y',0};
175 static const WCHAR method_enumvaluesW[] =
176 {'E','n','u','m','V','a','l','u','e','s',0};
178 static const WCHAR param_defkeyW[] =
179 {'h','D','e','f','K','e','y',0};
180 static const WCHAR param_namesW[] =
181 {'N','a','m','e','s',0};
182 static const WCHAR param_returnvalueW[] =
183 {'R','e','t','u','r','n','V','a','l','u','e',0};
184 static const WCHAR param_subkeynameW[] =
185 {'s','S','u','b','K','e','y','N','a','m','e',0};
186 static const WCHAR param_typesW[] =
187 {'T','y','p','e','s',0};
189 /* column definitions must be kept in sync with record structures below */
190 static const struct column col_baseboard[] =
192 { prop_manufacturerW, CIM_STRING },
193 { prop_serialnumberW, CIM_STRING },
194 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
196 static const struct column col_bios[] =
198 { prop_descriptionW, CIM_STRING },
199 { prop_manufacturerW, CIM_STRING },
200 { prop_releasedateW, CIM_DATETIME },
201 { prop_serialnumberW, CIM_STRING }
203 static const struct column col_compsys[] =
205 { prop_descriptionW, CIM_STRING },
206 { prop_domainroleW, CIM_UINT16 },
207 { prop_manufacturerW, CIM_STRING },
208 { prop_modelW, CIM_STRING },
209 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
210 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
211 { prop_totalphysicalmemoryW, CIM_UINT64 }
213 static const struct column col_logicaldisk[] =
215 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
216 { prop_drivetypeW, CIM_UINT32, VT_I4 },
217 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
218 { prop_freespaceW, CIM_UINT64 },
219 { prop_sizeW, CIM_UINT64 }
221 static const struct column col_networkadapter[] =
223 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
224 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
225 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
226 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
227 { prop_pnpdeviceidW, CIM_STRING },
228 { prop_speedW, CIM_UINT64 }
230 static const struct column col_os[] =
232 { prop_captionW, CIM_STRING },
233 { prop_csdversionW, CIM_STRING },
234 { prop_osarchitectureW, CIM_STRING },
235 { prop_oslanguageW, CIM_UINT32, VT_I4 },
236 { prop_systemdirectoryW, CIM_STRING }
238 static const struct column col_params[] =
240 { prop_classW, CIM_STRING },
241 { prop_methodW, CIM_STRING },
242 { prop_directionW, CIM_SINT32 },
243 { prop_parameterW, CIM_STRING },
244 { prop_typeW, CIM_UINT32 },
245 { prop_defaultvalueW, CIM_UINT32 }
247 static const struct column col_process[] =
249 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
250 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
251 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
252 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
253 { prop_pprocessidW, CIM_UINT32, VT_I4 },
254 { prop_processidW, CIM_UINT32, VT_I4 },
255 { prop_threadcountW, CIM_UINT32, VT_I4 }
257 static const struct column col_processor[] =
259 { prop_cpustatusW, CIM_UINT16 },
260 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
261 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
262 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
263 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
264 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
265 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC }
267 static const struct column col_service[] =
269 { prop_acceptpauseW, CIM_BOOLEAN },
270 { prop_acceptstopW, CIM_BOOLEAN },
271 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
272 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
273 { prop_processidW, CIM_UINT32 },
274 { prop_servicetypeW, CIM_STRING },
275 { prop_startmodeW, CIM_STRING },
276 { prop_stateW, CIM_STRING },
277 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC }
279 static const struct column col_stdregprov[] =
281 { method_enumkeyW, CIM_OBJECT|COL_FLAG_METHOD },
282 { method_enumvaluesW, CIM_OBJECT|COL_FLAG_METHOD }
284 static const struct column col_videocontroller[] =
286 { prop_adapterramW, CIM_UINT32 },
287 { prop_currentbitsperpixelW, CIM_UINT32 },
288 { prop_currenthorizontalresW, CIM_UINT32 },
289 { prop_currentverticalresW, CIM_UINT32 },
290 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
291 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
292 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC }
295 static const WCHAR baseboard_manufacturerW[] =
296 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
297 static const WCHAR baseboard_serialnumberW[] =
299 static const WCHAR baseboard_tagW[] =
300 {'B','a','s','e',' ','B','o','a','r','d',0};
301 static const WCHAR bios_descriptionW[] =
302 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
303 static const WCHAR bios_manufacturerW[] =
304 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
305 static const WCHAR bios_releasedateW[] =
306 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
307 static const WCHAR bios_serialnumberW[] =
309 static const WCHAR compsys_descriptionW[] =
310 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
311 static const WCHAR compsys_manufacturerW[] =
312 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
313 static const WCHAR compsys_modelW[] =
315 static const WCHAR networkadapter_pnpdeviceidW[]=
316 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
317 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
318 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
319 static const WCHAR os_captionW[] =
320 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
321 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
322 static const WCHAR os_csdversionW[] =
323 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
324 static const WCHAR os_32bitW[] =
325 {'3','2','-','b','i','t',0};
326 static const WCHAR os_64bitW[] =
327 {'6','4','-','b','i','t',0};
328 static const WCHAR videocontroller_deviceidW[] =
329 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
331 #include "pshpack1.h"
332 struct record_baseboard
334 const WCHAR *manufacturer;
335 const WCHAR *serialnumber;
340 const WCHAR *description;
341 const WCHAR *manufacturer;
342 const WCHAR *releasedate;
343 const WCHAR *serialnumber;
345 struct record_computersystem
347 const WCHAR *description;
349 const WCHAR *manufacturer;
351 UINT32 num_logical_processors;
352 UINT32 num_processors;
353 UINT64 total_physical_memory;
355 struct record_logicaldisk
357 const WCHAR *device_id;
359 const WCHAR *filesystem;
363 struct record_networkadapter
365 const WCHAR *device_id;
366 INT32 interface_index;
367 const WCHAR *mac_address;
368 UINT16 netconnection_status;
369 const WCHAR *pnpdevice_id;
372 struct record_operatingsystem
374 const WCHAR *caption;
375 const WCHAR *csdversion;
376 const WCHAR *osarchitecture;
378 const WCHAR *systemdirectory;
385 const WCHAR *parameter;
389 struct record_process
391 const WCHAR *caption;
392 const WCHAR *commandline;
393 const WCHAR *description;
399 struct record_processor
402 const WCHAR *device_id;
403 const WCHAR *manufacturer;
404 UINT32 maxclockspeed;
406 UINT32 num_logical_processors;
407 const WCHAR *processor_id;
409 struct record_service
413 const WCHAR *displayname;
416 const WCHAR *servicetype;
417 const WCHAR *startmode;
419 const WCHAR *systemname;
421 struct record_stdregprov
423 class_method *enumkey;
424 class_method *enumvalues;
426 struct record_videocontroller
429 UINT32 current_bitsperpixel;
430 UINT32 current_horizontalres;
431 UINT32 current_verticalres;
432 const WCHAR *description;
433 const WCHAR *device_id;
438 static HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
443 static HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
449 static const struct record_baseboard data_baseboard[] =
451 { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
453 static const struct record_bios data_bios[] =
455 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
457 static const struct record_params data_params[] =
459 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
460 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
461 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32 },
462 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
463 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
464 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
465 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32 },
466 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
467 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY }
469 static const struct record_stdregprov data_stdregprov[] =
471 { reg_enumkey, reg_enumvalues }
474 static UINT get_processor_count(void)
476 SYSTEM_BASIC_INFORMATION info;
478 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
479 return info.NumberOfProcessors;
482 static UINT get_logical_processor_count(void)
484 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
485 UINT i, j, count = 0;
489 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
490 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
492 if (!(info = heap_alloc( len ))) return get_processor_count();
493 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
494 if (status != STATUS_SUCCESS)
497 return get_processor_count();
499 for (i = 0; i < len / sizeof(*info); i++)
501 if (info[i].Relationship != RelationProcessorCore) continue;
502 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
508 static UINT64 get_total_physical_memory(void)
510 MEMORYSTATUSEX status;
512 status.dwLength = sizeof(status);
513 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
514 return status.ullTotalPhys;
517 static void fill_compsys( struct table *table )
519 struct record_computersystem *rec;
521 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
523 rec = (struct record_computersystem *)table->data;
524 rec->description = compsys_descriptionW;
525 rec->domainrole = 0; /* standalone workstation */
526 rec->manufacturer = compsys_manufacturerW;
527 rec->model = compsys_modelW;
528 rec->num_logical_processors = get_logical_processor_count();
529 rec->num_processors = get_processor_count();
530 rec->total_physical_memory = get_total_physical_memory();
532 TRACE("created 1 row\n");
536 static WCHAR *get_filesystem( const WCHAR *root )
538 static const WCHAR ntfsW[] = {'N','T','F','S',0};
539 WCHAR buffer[MAX_PATH + 1];
541 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
542 return heap_strdupW( buffer );
543 return heap_strdupW( ntfsW );
546 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
548 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
550 DISK_GEOMETRY_EX info;
553 free.QuadPart = 512 * 1024 * 1024;
554 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
557 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
558 if (handle != INVALID_HANDLE_VALUE)
560 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
561 *disksize = info.DiskSize.QuadPart;
562 CloseHandle( handle );
564 return free.QuadPart;
567 static void fill_logicaldisk( struct table *table )
569 static const WCHAR fmtW[] = {'%','c',':',0};
570 WCHAR device_id[3], root[] = {'A',':','\\',0};
571 struct record_logicaldisk *rec;
572 UINT i, num_rows = 0, offset = 0, count = 4, type;
573 UINT64 size = 1024 * 1024 * 1024;
574 DWORD drives = GetLogicalDrives();
576 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
578 for (i = 0; i < sizeof(drives); i++)
580 if (drives & (1 << i))
583 type = GetDriveTypeW( root );
584 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
587 if (num_rows > count)
591 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
594 rec = (struct record_logicaldisk *)(table->data + offset);
595 sprintfW( device_id, fmtW, 'A' + i );
596 rec->device_id = heap_strdupW( device_id );
597 rec->drivetype = type;
598 rec->filesystem = get_filesystem( root );
599 rec->freespace = get_freespace( root, &size );
601 offset += sizeof(*rec);
605 TRACE("created %u rows\n", num_rows);
606 table->num_rows = num_rows;
609 static UINT16 get_connection_status( IF_OPER_STATUS status )
613 case IfOperStatusDown:
614 return 0; /* Disconnected */
616 return 2; /* Connected */
618 ERR("unhandled status %u\n", status);
623 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
625 static const WCHAR fmtW[] =
626 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
627 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
630 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
631 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
635 static void fill_networkadapter( struct table *table )
637 static const WCHAR fmtW[] = {'%','u',0};
639 struct record_networkadapter *rec;
640 IP_ADAPTER_ADDRESSES *aa, *buffer;
641 UINT num_rows = 0, offset = 0;
644 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
645 if (ret != ERROR_BUFFER_OVERFLOW) return;
647 if (!(buffer = heap_alloc( size ))) return;
648 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
653 for (aa = buffer; aa; aa = aa->Next) num_rows++;
654 if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
659 for (aa = buffer; aa; aa = aa->Next)
661 rec = (struct record_networkadapter *)(table->data + offset);
662 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
663 rec->device_id = heap_strdupW( device_id );
664 rec->interface_index = aa->u.s.IfIndex;
665 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
666 rec->netconnection_status = get_connection_status( aa->OperStatus );
667 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
668 rec->speed = 1000000;
669 offset += sizeof(*rec);
671 TRACE("created %u rows\n", num_rows);
672 table->num_rows = num_rows;
677 static WCHAR *get_cmdline( DWORD process_id )
679 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
680 return NULL; /* FIXME handle different process case */
683 static void fill_process( struct table *table )
685 static const WCHAR fmtW[] = {'%','u',0};
687 struct record_process *rec;
688 PROCESSENTRY32W entry;
690 UINT num_rows = 0, offset = 0, count = 8;
692 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
693 if (snap == INVALID_HANDLE_VALUE) return;
695 entry.dwSize = sizeof(entry);
696 if (!Process32FirstW( snap, &entry )) goto done;
697 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
701 if (num_rows > count)
705 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
708 rec = (struct record_process *)(table->data + offset);
709 rec->caption = heap_strdupW( entry.szExeFile );
710 rec->commandline = get_cmdline( entry.th32ProcessID );
711 rec->description = heap_strdupW( entry.szExeFile );
712 sprintfW( handle, fmtW, entry.th32ProcessID );
713 rec->handle = heap_strdupW( handle );
714 rec->process_id = entry.th32ProcessID;
715 rec->pprocess_id = entry.th32ParentProcessID;
716 rec->thread_count = entry.cntThreads;
717 offset += sizeof(*rec);
719 } while (Process32NextW( snap, &entry ));
721 TRACE("created %u rows\n", num_rows);
722 table->num_rows = num_rows;
728 static inline void do_cpuid( unsigned int ax, unsigned int *p )
731 __asm__("pushl %%ebx\n\t"
733 "movl %%ebx, %%esi\n\t"
735 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
740 static void get_processor_id( WCHAR *processor_id )
742 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
743 unsigned int regs[4] = {0, 0, 0, 0};
746 sprintfW( processor_id, fmtW, regs[3], regs[0] );
748 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
751 unsigned char *p = (unsigned char *)regs;
753 for (i = 0; i < len; i++)
759 static void get_processor_manufacturer( WCHAR *manufacturer )
761 unsigned int tmp, regs[4] = {0, 0, 0, 0};
764 tmp = regs[2]; /* swap edx and ecx */
768 regs_to_str( regs + 1, 12, manufacturer );
770 static void get_processor_name( WCHAR *name )
772 unsigned int regs[4] = {0, 0, 0, 0};
774 do_cpuid( 0x80000000, regs );
775 if (regs[0] >= 0x80000004)
777 do_cpuid( 0x80000002, regs );
778 regs_to_str( regs, 16, name );
779 do_cpuid( 0x80000003, regs );
780 regs_to_str( regs, 16, name + 16 );
781 do_cpuid( 0x80000004, regs );
782 regs_to_str( regs, 16, name + 32 );
785 static UINT get_processor_maxclockspeed( void )
787 PROCESSOR_POWER_INFORMATION *info;
788 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
791 if ((info = heap_alloc( size )))
793 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
794 if (!status) ret = info[0].MaxMhz;
800 static void fill_processor( struct table *table )
802 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
803 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
804 struct record_processor *rec;
805 UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
807 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
809 get_processor_id( processor_id );
810 get_processor_manufacturer( manufacturer );
811 get_processor_name( name );
813 maxclockspeed = get_processor_maxclockspeed();
814 num_logical_processors = get_logical_processor_count() / count;
816 for (i = 0; i < count; i++)
818 rec = (struct record_processor *)(table->data + offset);
819 rec->cpu_status = 1; /* CPU Enabled */
820 sprintfW( device_id, fmtW, i );
821 rec->device_id = heap_strdupW( device_id );
822 rec->manufacturer = heap_strdupW( manufacturer );
823 rec->maxclockspeed = maxclockspeed;
824 rec->name = heap_strdupW( name );
825 rec->num_logical_processors = num_logical_processors;
826 rec->processor_id = heap_strdupW( processor_id );
827 offset += sizeof(*rec);
830 TRACE("created %u rows\n", count);
831 table->num_rows = count;
834 static void fill_os( struct table *table )
836 struct record_operatingsystem *rec;
837 WCHAR path[MAX_PATH];
841 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
843 rec = (struct record_operatingsystem *)table->data;
844 rec->caption = os_captionW;
845 rec->csdversion = os_csdversionW;
847 GetNativeSystemInfo( &info );
848 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
849 rec->osarchitecture = os_64bitW;
851 rec->osarchitecture = os_32bitW;
853 rec->oslanguage = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
855 Wow64DisableWow64FsRedirection( &redir );
856 GetSystemDirectoryW( path, MAX_PATH );
857 Wow64RevertWow64FsRedirection( redir );
858 rec->systemdirectory = heap_strdupW( path );
860 TRACE("created 1 row\n");
864 static const WCHAR *get_service_type( DWORD type )
866 static const WCHAR filesystem_driverW[] =
867 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
868 static const WCHAR kernel_driverW[] =
869 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
870 static const WCHAR own_processW[] =
871 {'O','w','n',' ','P','r','o','c','e','s','s',0};
872 static const WCHAR share_processW[] =
873 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
875 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
876 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
877 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
878 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
879 else ERR("unhandled type 0x%08x\n", type);
882 static const WCHAR *get_service_state( DWORD state )
884 static const WCHAR runningW[] =
885 {'R','u','n','n','i','n','g',0};
886 static const WCHAR start_pendingW[] =
887 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
888 static const WCHAR stop_pendingW[] =
889 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
890 static const WCHAR stoppedW[] =
891 {'S','t','o','p','p','e','d',0};
892 static const WCHAR unknownW[] =
893 {'U','n','k','n','o','w','n',0};
897 case SERVICE_STOPPED: return stoppedW;
898 case SERVICE_START_PENDING: return start_pendingW;
899 case SERVICE_STOP_PENDING: return stop_pendingW;
900 case SERVICE_RUNNING: return runningW;
902 ERR("unknown state %u\n", state);
907 static const WCHAR *get_service_startmode( DWORD mode )
909 static const WCHAR bootW[] = {'B','o','o','t',0};
910 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
911 static const WCHAR autoW[] = {'A','u','t','o',0};
912 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
913 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
914 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
918 case SERVICE_BOOT_START: return bootW;
919 case SERVICE_SYSTEM_START: return systemW;
920 case SERVICE_AUTO_START: return autoW;
921 case SERVICE_DEMAND_START: return manualW;
922 case SERVICE_DISABLED: return disabledW;
924 ERR("unknown mode 0x%x\n", mode);
929 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
931 QUERY_SERVICE_CONFIGW *config = NULL;
935 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
936 QueryServiceConfigW( service, NULL, 0, &size );
937 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
938 if (!(config = heap_alloc( size ))) goto done;
939 if (QueryServiceConfigW( service, config, size, &size )) goto done;
944 CloseServiceHandle( service );
948 static void fill_service( struct table *table )
950 struct record_service *rec;
952 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
953 SERVICE_STATUS_PROCESS *status;
954 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
955 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
956 UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
959 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
960 if (!(services = heap_alloc( size ))) goto done;
962 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
963 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
964 &count, NULL, NULL );
967 if (GetLastError() != ERROR_MORE_DATA) goto done;
969 if (!(tmp = heap_realloc( services, size ))) goto done;
971 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
972 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
973 &count, NULL, NULL );
976 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
978 GetComputerNameW( sysnameW, &len );
980 for (i = 0; i < count; i++)
982 QUERY_SERVICE_CONFIGW *config;
984 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
986 status = &services[i].ServiceStatusProcess;
987 rec = (struct record_service *)(table->data + offset);
988 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
989 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
990 rec->displayname = heap_strdupW( services[i].lpDisplayName );
991 rec->name = heap_strdupW( services[i].lpServiceName );
992 rec->process_id = status->dwProcessId;
993 rec->servicetype = get_service_type( status->dwServiceType );
994 rec->startmode = get_service_startmode( config->dwStartType );
995 rec->state = get_service_state( status->dwCurrentState );
996 rec->systemname = heap_strdupW( sysnameW );
998 offset += sizeof(*rec);
1002 TRACE("created %u rows\n", num_rows);
1003 table->num_rows = num_rows;
1006 CloseServiceHandle( manager );
1007 heap_free( services );
1010 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1012 HDC hdc = GetDC( NULL );
1015 if (!hdc) return 32;
1016 ret = GetDeviceCaps( hdc, BITSPIXEL );
1017 *hres = GetDeviceCaps( hdc, HORZRES );
1018 *vres = GetDeviceCaps( hdc, VERTRES );
1019 ReleaseDC( NULL, hdc );
1023 static void fill_videocontroller( struct table *table )
1026 struct record_videocontroller *rec;
1028 IDXGIFactory *factory = NULL;
1029 IDXGIAdapter *adapter = NULL;
1030 DXGI_ADAPTER_DESC desc;
1031 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1032 const WCHAR *name = videocontroller_deviceidW;
1034 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1036 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1037 if (FAILED(hr)) goto done;
1039 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1040 if (FAILED(hr)) goto done;
1042 hr = IDXGIAdapter_GetDesc( adapter, &desc );
1045 vidmem = desc.DedicatedVideoMemory;
1046 name = desc.Description;
1050 rec = (struct record_videocontroller *)table->data;
1051 rec->adapter_ram = vidmem;
1052 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
1053 rec->current_horizontalres = hres;
1054 rec->current_verticalres = vres;
1055 rec->description = heap_strdupW( name );
1056 rec->device_id = videocontroller_deviceidW;
1057 rec->name = heap_strdupW( name );
1059 TRACE("created 1 row\n");
1060 table->num_rows = 1;
1062 if (adapter) IDXGIAdapter_Release( adapter );
1063 if (factory) IDXGIFactory_Release( factory );
1066 static struct table builtin_classes[] =
1068 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1069 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1070 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1071 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1072 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1073 { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1074 { class_paramsW, SIZEOF(col_params), col_params, SIZEOF(data_params), (BYTE *)data_params },
1075 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1076 { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1077 { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1078 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1079 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1082 void init_table_list( void )
1084 static struct list tables = LIST_INIT( tables );
1087 for (i = 0; i < SIZEOF(builtin_classes); i++)
1089 list_add_tail( &tables, &builtin_classes[i].entry );
1091 table_list = &tables;