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
38 #include "wine/debug.h"
39 #include "wbemprox_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
43 static const WCHAR class_baseboardW[] =
44 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
45 static const WCHAR class_biosW[] =
46 {'W','i','n','3','2','_','B','I','O','S',0};
47 static const WCHAR class_compsysW[] =
48 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
49 static const WCHAR class_logicaldiskW[] =
50 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
51 static const WCHAR class_networkadapterW[] =
52 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
53 static const WCHAR class_osW[] =
54 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
55 static const WCHAR class_paramsW[] =
56 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
57 static const WCHAR class_processW[] =
58 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
59 static const WCHAR class_processorW[] =
60 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
61 static const WCHAR class_serviceW[] =
62 {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
63 static const WCHAR class_stdregprovW[] =
64 {'S','t','d','R','e','g','P','r','o','v',0};
65 static const WCHAR class_videocontrollerW[] =
66 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
68 static const WCHAR prop_acceptpauseW[] =
69 {'A','c','c','e','p','t','P','a','u','s','e',0};
70 static const WCHAR prop_acceptstopW[] =
71 {'A','c','c','e','p','t','S','t','o','p',0};
72 static const WCHAR prop_adapterramW[] =
73 {'A','d','a','p','t','e','r','R','A','M',0};
74 static const WCHAR prop_captionW[] =
75 {'C','a','p','t','i','o','n',0};
76 static const WCHAR prop_classW[] =
77 {'C','l','a','s','s',0};
78 static const WCHAR prop_commandlineW[] =
79 {'C','o','m','m','a','n','d','L','i','n','e',0};
80 static const WCHAR prop_cpustatusW[] =
81 {'C','p','u','S','t','a','t','u','s',0};
82 static const WCHAR prop_csdversionW[] =
83 {'C','S','D','V','e','r','s','i','o','n',0};
84 static const WCHAR prop_currentbitsperpixelW[] =
85 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
86 static const WCHAR prop_currenthorizontalresW[] =
87 {'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};
88 static const WCHAR prop_currentverticalresW[] =
89 {'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};
90 static const WCHAR prop_defaultvalueW[] =
91 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
92 static const WCHAR prop_descriptionW[] =
93 {'D','e','s','c','r','i','p','t','i','o','n',0};
94 static const WCHAR prop_deviceidW[] =
95 {'D','e','v','i','c','e','I','d',0};
96 static const WCHAR prop_directionW[] =
97 {'D','i','r','e','c','t','i','o','n',0};
98 static const WCHAR prop_displaynameW[] =
99 {'D','i','s','p','l','a','y','N','a','m','e',0};
100 static const WCHAR prop_domainroleW[] =
101 {'D','o','m','a','i','n','R','o','l','e',0};
102 static const WCHAR prop_drivetypeW[] =
103 {'D','r','i','v','e','T','y','p','e',0};
104 static const WCHAR prop_filesystemW[] =
105 {'F','i','l','e','S','y','s','t','e','m',0};
106 static const WCHAR prop_freespaceW[] =
107 {'F','r','e','e','S','p','a','c','e',0};
108 static const WCHAR prop_handleW[] =
109 {'H','a','n','d','l','e',0};
110 static const WCHAR prop_interfaceindexW[] =
111 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
112 static const WCHAR prop_macaddressW[] =
113 {'M','A','C','A','d','d','r','e','s','s',0};
114 static const WCHAR prop_manufacturerW[] =
115 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
116 static const WCHAR prop_maxclockspeedW[] =
117 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
118 static const WCHAR prop_methodW[] =
119 {'M','e','t','h','o','d',0};
120 static const WCHAR prop_modelW[] =
121 {'M','o','d','e','l',0};
122 static const WCHAR prop_nameW[] =
124 static const WCHAR prop_netconnectionstatusW[] =
125 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
126 static const WCHAR prop_numlogicalprocessorsW[] =
127 {'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};
128 static const WCHAR prop_numprocessorsW[] =
129 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
130 static const WCHAR prop_osarchitectureW[] =
131 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
132 static const WCHAR prop_oslanguageW[] =
133 {'O','S','L','a','n','g','u','a','g','e',0};
134 static const WCHAR prop_parameterW[] =
135 {'P','a','r','a','m','e','t','e','r',0};
136 static const WCHAR prop_pnpdeviceidW[] =
137 {'P','N','P','D','e','v','i','c','e','I','D',0};
138 static const WCHAR prop_pprocessidW[] =
139 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
140 static const WCHAR prop_processidW[] =
141 {'P','r','o','c','e','s','s','I','D',0};
142 static const WCHAR prop_processoridW[] =
143 {'P','r','o','c','e','s','s','o','r','I','d',0};
144 static const WCHAR prop_releasedateW[] =
145 {'R','e','l','e','a','s','e','D','a','t','e',0};
146 static const WCHAR prop_serialnumberW[] =
147 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
148 static const WCHAR prop_servicetypeW[] =
149 {'S','e','r','v','i','c','e','T','y','p','e',0};
150 static const WCHAR prop_startmodeW[] =
151 {'S','t','a','r','t','M','o','d','e',0};
152 static const WCHAR prop_sizeW[] =
154 static const WCHAR prop_speedW[] =
155 {'S','p','e','e','d',0};
156 static const WCHAR prop_stateW[] =
157 {'S','t','a','t','e',0};
158 static const WCHAR prop_systemdirectoryW[] =
159 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
160 static const WCHAR prop_systemnameW[] =
161 {'S','y','s','t','e','m','N','a','m','e',0};
162 static const WCHAR prop_tagW[] =
164 static const WCHAR prop_threadcountW[] =
165 {'T','h','r','e','a','d','C','o','u','n','t',0};
166 static const WCHAR prop_totalphysicalmemoryW[] =
167 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
168 static const WCHAR prop_typeW[] =
171 static const WCHAR method_enumkeyW[] =
172 {'E','n','u','m','K','e','y',0};
173 static const WCHAR method_enumvaluesW[] =
174 {'E','n','u','m','V','a','l','u','e','s',0};
176 static const WCHAR param_defkeyW[] =
177 {'h','D','e','f','K','e','y',0};
178 static const WCHAR param_namesW[] =
179 {'N','a','m','e','s',0};
180 static const WCHAR param_returnvalueW[] =
181 {'R','e','t','u','r','n','V','a','l','u','e',0};
182 static const WCHAR param_subkeynameW[] =
183 {'s','S','u','b','K','e','y','N','a','m','e',0};
184 static const WCHAR param_typesW[] =
185 {'T','y','p','e','s',0};
187 /* column definitions must be kept in sync with record structures below */
188 static const struct column col_baseboard[] =
190 { prop_manufacturerW, CIM_STRING },
191 { prop_serialnumberW, CIM_STRING },
192 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
194 static const struct column col_bios[] =
196 { prop_descriptionW, CIM_STRING },
197 { prop_manufacturerW, CIM_STRING },
198 { prop_releasedateW, CIM_DATETIME },
199 { prop_serialnumberW, CIM_STRING }
201 static const struct column col_compsys[] =
203 { prop_descriptionW, CIM_STRING },
204 { prop_domainroleW, CIM_UINT16 },
205 { prop_manufacturerW, CIM_STRING },
206 { prop_modelW, CIM_STRING },
207 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
208 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
209 { prop_totalphysicalmemoryW, CIM_UINT64 }
211 static const struct column col_logicaldisk[] =
213 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
214 { prop_drivetypeW, CIM_UINT32, VT_I4 },
215 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
216 { prop_freespaceW, CIM_UINT64 },
217 { prop_sizeW, CIM_UINT64 }
219 static const struct column col_networkadapter[] =
221 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
222 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
223 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
224 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
225 { prop_pnpdeviceidW, CIM_STRING },
226 { prop_speedW, CIM_UINT64 }
228 static const struct column col_os[] =
230 { prop_captionW, CIM_STRING },
231 { prop_csdversionW, CIM_STRING },
232 { prop_osarchitectureW, CIM_STRING },
233 { prop_oslanguageW, CIM_UINT32, VT_I4 },
234 { prop_systemdirectoryW, CIM_STRING }
236 static const struct column col_params[] =
238 { prop_classW, CIM_STRING },
239 { prop_methodW, CIM_STRING },
240 { prop_directionW, CIM_SINT32 },
241 { prop_parameterW, CIM_STRING },
242 { prop_typeW, CIM_UINT32 },
243 { prop_defaultvalueW, CIM_UINT32 }
245 static const struct column col_process[] =
247 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
248 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
249 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
250 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
251 { prop_pprocessidW, CIM_UINT32, VT_I4 },
252 { prop_processidW, CIM_UINT32, VT_I4 },
253 { prop_threadcountW, CIM_UINT32, VT_I4 }
255 static const struct column col_processor[] =
257 { prop_cpustatusW, CIM_UINT16 },
258 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
259 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
260 { prop_maxclockspeedW, CIM_UINT32 },
261 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
262 { prop_numlogicalprocessorsW, CIM_UINT32 },
263 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC }
265 static const struct column col_service[] =
267 { prop_acceptpauseW, CIM_BOOLEAN },
268 { prop_acceptstopW, CIM_BOOLEAN },
269 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
270 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
271 { prop_processidW, CIM_UINT32 },
272 { prop_servicetypeW, CIM_STRING },
273 { prop_startmodeW, CIM_STRING },
274 { prop_stateW, CIM_STRING },
275 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC }
277 static const struct column col_stdregprov[] =
279 { method_enumkeyW, CIM_OBJECT|COL_FLAG_METHOD },
280 { method_enumvaluesW, CIM_OBJECT|COL_FLAG_METHOD }
282 static const struct column col_videocontroller[] =
284 { prop_adapterramW, CIM_UINT32 },
285 { prop_currentbitsperpixelW, CIM_UINT32 },
286 { prop_currenthorizontalresW, CIM_UINT32 },
287 { prop_currentverticalresW, CIM_UINT32 },
288 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
289 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC }
292 static const WCHAR baseboard_manufacturerW[] =
293 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
294 static const WCHAR baseboard_serialnumberW[] =
296 static const WCHAR baseboard_tagW[] =
297 {'B','a','s','e',' ','B','o','a','r','d',0};
298 static const WCHAR bios_descriptionW[] =
299 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
300 static const WCHAR bios_manufacturerW[] =
301 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
302 static const WCHAR bios_releasedateW[] =
303 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
304 static const WCHAR bios_serialnumberW[] =
306 static const WCHAR compsys_descriptionW[] =
307 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
308 static const WCHAR compsys_manufacturerW[] =
309 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
310 static const WCHAR compsys_modelW[] =
312 static const WCHAR networkadapter_pnpdeviceidW[]=
313 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
314 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
315 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
316 static const WCHAR os_captionW[] =
317 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
318 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
319 static const WCHAR os_csdversionW[] =
320 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
321 static const WCHAR os_32bitW[] =
322 {'3','2','-','b','i','t',0};
323 static const WCHAR os_64bitW[] =
324 {'6','4','-','b','i','t',0};
325 static const WCHAR videocontroller_deviceidW[] =
326 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
328 #include "pshpack1.h"
329 struct record_baseboard
331 const WCHAR *manufacturer;
332 const WCHAR *serialnumber;
337 const WCHAR *description;
338 const WCHAR *manufacturer;
339 const WCHAR *releasedate;
340 const WCHAR *serialnumber;
342 struct record_computersystem
344 const WCHAR *description;
346 const WCHAR *manufacturer;
348 UINT32 num_logical_processors;
349 UINT32 num_processors;
350 UINT64 total_physical_memory;
352 struct record_logicaldisk
354 const WCHAR *device_id;
356 const WCHAR *filesystem;
360 struct record_networkadapter
362 const WCHAR *device_id;
363 INT32 interface_index;
364 const WCHAR *mac_address;
365 UINT16 netconnection_status;
366 const WCHAR *pnpdevice_id;
369 struct record_operatingsystem
371 const WCHAR *caption;
372 const WCHAR *csdversion;
373 const WCHAR *osarchitecture;
375 const WCHAR *systemdirectory;
382 const WCHAR *parameter;
386 struct record_process
388 const WCHAR *caption;
389 const WCHAR *commandline;
390 const WCHAR *description;
396 struct record_processor
399 const WCHAR *device_id;
400 const WCHAR *manufacturer;
401 UINT32 maxclockspeed;
403 UINT32 numberoflogicalprocessors;
404 const WCHAR *processor_id;
406 struct record_service
410 const WCHAR *displayname;
413 const WCHAR *servicetype;
414 const WCHAR *startmode;
416 const WCHAR *systemname;
418 struct record_stdregprov
420 class_method *enumkey;
421 class_method *enumvalues;
423 struct record_videocontroller
426 UINT32 current_bitsperpixel;
427 UINT32 current_horizontalres;
428 UINT32 current_verticalres;
429 const WCHAR *device_id;
434 static HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
439 static HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
445 static const struct record_baseboard data_baseboard[] =
447 { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
449 static const struct record_bios data_bios[] =
451 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
453 static const struct record_params data_params[] =
455 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
456 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
457 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32 },
458 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
459 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
460 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
461 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32 },
462 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
463 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY }
465 static const struct record_stdregprov data_stdregprov[] =
467 { reg_enumkey, reg_enumvalues }
470 static UINT get_processor_count(void)
472 SYSTEM_BASIC_INFORMATION info;
474 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
475 return info.NumberOfProcessors;
478 static UINT64 get_total_physical_memory(void)
480 MEMORYSTATUSEX status;
482 status.dwLength = sizeof(status);
483 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
484 return status.ullTotalPhys;
487 static void fill_compsys( struct table *table )
489 struct record_computersystem *rec;
491 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
493 rec = (struct record_computersystem *)table->data;
494 rec->description = compsys_descriptionW;
495 rec->domainrole = 0; /* standalone workstation */
496 rec->manufacturer = compsys_manufacturerW;
497 rec->model = compsys_modelW;
498 rec->num_logical_processors = get_processor_count();
499 rec->num_processors = rec->num_logical_processors;
500 rec->total_physical_memory = get_total_physical_memory();
502 TRACE("created 1 row\n");
506 static WCHAR *get_filesystem( const WCHAR *root )
508 static const WCHAR ntfsW[] = {'N','T','F','S',0};
509 WCHAR buffer[MAX_PATH + 1];
511 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
512 return heap_strdupW( buffer );
513 return heap_strdupW( ntfsW );
516 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
518 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
520 DISK_GEOMETRY_EX info;
523 free.QuadPart = 512 * 1024 * 1024;
524 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
527 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
528 if (handle != INVALID_HANDLE_VALUE)
530 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
531 *disksize = info.DiskSize.QuadPart;
532 CloseHandle( handle );
534 return free.QuadPart;
537 static void fill_logicaldisk( struct table *table )
539 static const WCHAR fmtW[] = {'%','c',':',0};
540 WCHAR device_id[3], root[] = {'A',':','\\',0};
541 struct record_logicaldisk *rec;
542 UINT i, num_rows = 0, offset = 0, count = 4, type;
543 UINT64 size = 1024 * 1024 * 1024;
544 DWORD drives = GetLogicalDrives();
546 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
548 for (i = 0; i < sizeof(drives); i++)
550 if (drives & (1 << i))
553 type = GetDriveTypeW( root );
554 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
557 if (num_rows > count)
561 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
564 rec = (struct record_logicaldisk *)(table->data + offset);
565 sprintfW( device_id, fmtW, 'A' + i );
566 rec->device_id = heap_strdupW( device_id );
567 rec->drivetype = type;
568 rec->filesystem = get_filesystem( root );
569 rec->freespace = get_freespace( root, &size );
571 offset += sizeof(*rec);
575 TRACE("created %u rows\n", num_rows);
576 table->num_rows = num_rows;
579 static UINT16 get_connection_status( IF_OPER_STATUS status )
583 case IfOperStatusDown:
584 return 0; /* Disconnected */
586 return 2; /* Connected */
588 ERR("unhandled status %u\n", status);
593 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
595 static const WCHAR fmtW[] =
596 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
597 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
600 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
601 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
605 static void fill_networkadapter( struct table *table )
607 static const WCHAR fmtW[] = {'%','u',0};
609 struct record_networkadapter *rec;
610 IP_ADAPTER_ADDRESSES *aa, *buffer;
611 UINT num_rows = 0, offset = 0;
614 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
615 if (ret != ERROR_BUFFER_OVERFLOW) return;
617 if (!(buffer = heap_alloc( size ))) return;
618 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
623 for (aa = buffer; aa; aa = aa->Next) num_rows++;
624 if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
629 for (aa = buffer; aa; aa = aa->Next)
631 rec = (struct record_networkadapter *)(table->data + offset);
632 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
633 rec->device_id = heap_strdupW( device_id );
634 rec->interface_index = aa->u.s.IfIndex;
635 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
636 rec->netconnection_status = get_connection_status( aa->OperStatus );
637 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
638 rec->speed = 1000000;
639 offset += sizeof(*rec);
641 TRACE("created %u rows\n", num_rows);
642 table->num_rows = num_rows;
647 static WCHAR *get_cmdline( DWORD process_id )
649 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
650 return NULL; /* FIXME handle different process case */
653 static void fill_process( struct table *table )
655 static const WCHAR fmtW[] = {'%','u',0};
657 struct record_process *rec;
658 PROCESSENTRY32W entry;
660 UINT num_rows = 0, offset = 0, count = 8;
662 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
663 if (snap == INVALID_HANDLE_VALUE) return;
665 entry.dwSize = sizeof(entry);
666 if (!Process32FirstW( snap, &entry )) goto done;
667 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
671 if (num_rows > count)
675 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
678 rec = (struct record_process *)(table->data + offset);
679 rec->caption = heap_strdupW( entry.szExeFile );
680 rec->commandline = get_cmdline( entry.th32ProcessID );
681 rec->description = heap_strdupW( entry.szExeFile );
682 sprintfW( handle, fmtW, entry.th32ProcessID );
683 rec->handle = heap_strdupW( handle );
684 rec->process_id = entry.th32ProcessID;
685 rec->pprocess_id = entry.th32ParentProcessID;
686 rec->thread_count = entry.cntThreads;
687 offset += sizeof(*rec);
689 } while (Process32NextW( snap, &entry ));
691 TRACE("created %u rows\n", num_rows);
692 table->num_rows = num_rows;
698 static inline void do_cpuid( unsigned int ax, unsigned int *p )
701 __asm__("pushl %%ebx\n\t"
703 "movl %%ebx, %%esi\n\t"
705 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
710 static void get_processor_id( WCHAR *processor_id )
712 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
713 unsigned int regs[4] = {0, 0, 0, 0};
716 sprintfW( processor_id, fmtW, regs[3], regs[0] );
718 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
721 unsigned char *p = (unsigned char *)regs;
723 for (i = 0; i < len; i++)
729 static void get_processor_manufacturer( WCHAR *manufacturer )
731 unsigned int tmp, regs[4] = {0, 0, 0, 0};
734 tmp = regs[2]; /* swap edx and ecx */
738 regs_to_str( regs + 1, 12, manufacturer );
740 static void get_processor_name( WCHAR *name )
742 unsigned int regs[4] = {0, 0, 0, 0};
744 do_cpuid( 0x80000000, regs );
745 if (regs[0] >= 0x80000004)
747 do_cpuid( 0x80000002, regs );
748 regs_to_str( regs, 16, name );
749 do_cpuid( 0x80000003, regs );
750 regs_to_str( regs, 16, name + 16 );
751 do_cpuid( 0x80000004, regs );
752 regs_to_str( regs, 16, name + 32 );
756 static void fill_processor( struct table *table )
758 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
759 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
760 struct record_processor *rec;
761 UINT i, offset = 0, count = get_processor_count(), cpuMhz;
762 PROCESSOR_POWER_INFORMATION ppi;
764 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
766 get_processor_id( processor_id );
767 get_processor_manufacturer( manufacturer );
768 get_processor_name( name );
770 if(!NtPowerInformation(ProcessorInformation, NULL, 0, &ppi, sizeof(ppi)))
775 for (i = 0; i < count; i++)
777 rec = (struct record_processor *)(table->data + offset);
778 rec->cpu_status = 1; /* CPU Enabled */
779 sprintfW( device_id, fmtW, i );
780 rec->device_id = heap_strdupW( device_id );
781 rec->manufacturer = heap_strdupW( manufacturer );
782 rec->maxclockspeed = cpuMhz;
783 rec->name = heap_strdupW( name );
784 rec->numberoflogicalprocessors = count;
785 rec->processor_id = heap_strdupW( processor_id );
786 offset += sizeof(*rec);
789 TRACE("created %u rows\n", count);
790 table->num_rows = count;
793 static void fill_os( struct table *table )
795 struct record_operatingsystem *rec;
796 WCHAR path[MAX_PATH];
800 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
802 rec = (struct record_operatingsystem *)table->data;
803 rec->caption = os_captionW;
804 rec->csdversion = os_csdversionW;
806 GetNativeSystemInfo( &info );
807 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
808 rec->osarchitecture = os_64bitW;
810 rec->osarchitecture = os_32bitW;
812 rec->oslanguage = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
814 Wow64DisableWow64FsRedirection( &redir );
815 GetSystemDirectoryW( path, MAX_PATH );
816 Wow64RevertWow64FsRedirection( redir );
817 rec->systemdirectory = heap_strdupW( path );
819 TRACE("created 1 row\n");
823 static const WCHAR *get_service_type( DWORD type )
825 static const WCHAR filesystem_driverW[] =
826 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
827 static const WCHAR kernel_driverW[] =
828 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
829 static const WCHAR own_processW[] =
830 {'O','w','n',' ','P','r','o','c','e','s','s',0};
831 static const WCHAR share_processW[] =
832 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
834 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
835 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
836 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
837 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
838 else ERR("unhandled type 0x%08x\n", type);
841 static const WCHAR *get_service_state( DWORD state )
843 static const WCHAR runningW[] =
844 {'R','u','n','n','i','n','g',0};
845 static const WCHAR start_pendingW[] =
846 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
847 static const WCHAR stop_pendingW[] =
848 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
849 static const WCHAR stoppedW[] =
850 {'S','t','o','p','p','e','d',0};
851 static const WCHAR unknownW[] =
852 {'U','n','k','n','o','w','n',0};
856 case SERVICE_STOPPED: return stoppedW;
857 case SERVICE_START_PENDING: return start_pendingW;
858 case SERVICE_STOP_PENDING: return stop_pendingW;
859 case SERVICE_RUNNING: return runningW;
861 ERR("unknown state %u\n", state);
866 static const WCHAR *get_service_startmode( DWORD mode )
868 static const WCHAR bootW[] = {'B','o','o','t',0};
869 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
870 static const WCHAR autoW[] = {'A','u','t','o',0};
871 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
872 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
873 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
877 case SERVICE_BOOT_START: return bootW;
878 case SERVICE_SYSTEM_START: return systemW;
879 case SERVICE_AUTO_START: return autoW;
880 case SERVICE_DEMAND_START: return manualW;
881 case SERVICE_DISABLED: return disabledW;
883 ERR("unknown mode 0x%x\n", mode);
888 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
890 QUERY_SERVICE_CONFIGW *config = NULL;
894 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
895 QueryServiceConfigW( service, NULL, 0, &size );
896 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
897 if (!(config = heap_alloc( size ))) goto done;
898 if (QueryServiceConfigW( service, config, size, &size )) goto done;
903 CloseServiceHandle( service );
907 static void fill_service( struct table *table )
909 struct record_service *rec;
911 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
912 SERVICE_STATUS_PROCESS *status;
913 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
914 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
915 UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
918 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
919 if (!(services = heap_alloc( size ))) goto done;
921 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
922 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
923 &count, NULL, NULL );
926 if (GetLastError() != ERROR_MORE_DATA) goto done;
928 if (!(tmp = heap_realloc( services, size ))) goto done;
930 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
931 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
932 &count, NULL, NULL );
935 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
937 GetComputerNameW( sysnameW, &len );
939 for (i = 0; i < count; i++)
941 QUERY_SERVICE_CONFIGW *config;
943 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
945 status = &services[i].ServiceStatusProcess;
946 rec = (struct record_service *)(table->data + offset);
947 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
948 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
949 rec->displayname = heap_strdupW( services[i].lpDisplayName );
950 rec->name = heap_strdupW( services[i].lpServiceName );
951 rec->process_id = status->dwProcessId;
952 rec->servicetype = get_service_type( status->dwServiceType );
953 rec->startmode = get_service_startmode( config->dwStartType );
954 rec->state = get_service_state( status->dwCurrentState );
955 rec->systemname = heap_strdupW( sysnameW );
957 offset += sizeof(*rec);
961 TRACE("created %u rows\n", num_rows);
962 table->num_rows = num_rows;
965 CloseServiceHandle( manager );
966 heap_free( services );
969 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
971 HDC hdc = GetDC( NULL );
975 ret = GetDeviceCaps( hdc, BITSPIXEL );
976 *hres = GetDeviceCaps( hdc, HORZRES );
977 *vres = GetDeviceCaps( hdc, VERTRES );
978 ReleaseDC( NULL, hdc );
982 static void fill_videocontroller( struct table *table )
985 struct record_videocontroller *rec;
987 IDXGIFactory *factory = NULL;
988 IDXGIAdapter *adapter = NULL;
989 DXGI_ADAPTER_DESC desc;
990 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
991 const WCHAR *name = videocontroller_deviceidW;
993 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
995 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
996 if (FAILED(hr)) goto done;
998 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
999 if (FAILED(hr)) goto done;
1001 hr = IDXGIAdapter_GetDesc( adapter, &desc );
1004 vidmem = desc.DedicatedVideoMemory;
1005 name = desc.Description;
1009 rec = (struct record_videocontroller *)table->data;
1010 rec->adapter_ram = vidmem;
1011 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
1012 rec->current_horizontalres = hres;
1013 rec->current_verticalres = vres;
1014 rec->device_id = videocontroller_deviceidW;
1015 rec->name = heap_strdupW( name );
1017 TRACE("created 1 row\n");
1018 table->num_rows = 1;
1020 if (adapter) IDXGIAdapter_Release( adapter );
1021 if (factory) IDXGIFactory_Release( factory );
1024 static struct table builtin_classes[] =
1026 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1027 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1028 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1029 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1030 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1031 { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1032 { class_paramsW, SIZEOF(col_params), col_params, SIZEOF(data_params), (BYTE *)data_params },
1033 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1034 { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1035 { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1036 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1037 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1040 void init_table_list( void )
1042 static struct list tables = LIST_INIT( tables );
1045 for (i = 0; i < SIZEOF(builtin_classes); i++)
1047 list_add_tail( &tables, &builtin_classes[i].entry );
1049 table_list = &tables;