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 },
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_deviceidW, CIM_STRING|COL_FLAG_KEY },
291 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC }
294 static const WCHAR baseboard_manufacturerW[] =
295 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
296 static const WCHAR baseboard_serialnumberW[] =
298 static const WCHAR baseboard_tagW[] =
299 {'B','a','s','e',' ','B','o','a','r','d',0};
300 static const WCHAR bios_descriptionW[] =
301 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
302 static const WCHAR bios_manufacturerW[] =
303 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
304 static const WCHAR bios_releasedateW[] =
305 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
306 static const WCHAR bios_serialnumberW[] =
308 static const WCHAR compsys_descriptionW[] =
309 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
310 static const WCHAR compsys_manufacturerW[] =
311 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
312 static const WCHAR compsys_modelW[] =
314 static const WCHAR networkadapter_pnpdeviceidW[]=
315 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
316 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
317 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
318 static const WCHAR os_captionW[] =
319 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
320 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
321 static const WCHAR os_csdversionW[] =
322 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
323 static const WCHAR os_32bitW[] =
324 {'3','2','-','b','i','t',0};
325 static const WCHAR os_64bitW[] =
326 {'6','4','-','b','i','t',0};
327 static const WCHAR videocontroller_deviceidW[] =
328 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
330 #include "pshpack1.h"
331 struct record_baseboard
333 const WCHAR *manufacturer;
334 const WCHAR *serialnumber;
339 const WCHAR *description;
340 const WCHAR *manufacturer;
341 const WCHAR *releasedate;
342 const WCHAR *serialnumber;
344 struct record_computersystem
346 const WCHAR *description;
348 const WCHAR *manufacturer;
350 UINT32 num_logical_processors;
351 UINT32 num_processors;
352 UINT64 total_physical_memory;
354 struct record_logicaldisk
356 const WCHAR *device_id;
358 const WCHAR *filesystem;
362 struct record_networkadapter
364 const WCHAR *device_id;
365 INT32 interface_index;
366 const WCHAR *mac_address;
367 UINT16 netconnection_status;
368 const WCHAR *pnpdevice_id;
371 struct record_operatingsystem
373 const WCHAR *caption;
374 const WCHAR *csdversion;
375 const WCHAR *osarchitecture;
377 const WCHAR *systemdirectory;
384 const WCHAR *parameter;
388 struct record_process
390 const WCHAR *caption;
391 const WCHAR *commandline;
392 const WCHAR *description;
398 struct record_processor
401 const WCHAR *device_id;
402 const WCHAR *manufacturer;
403 UINT32 maxclockspeed;
405 UINT32 num_logical_processors;
406 const WCHAR *processor_id;
408 struct record_service
412 const WCHAR *displayname;
415 const WCHAR *servicetype;
416 const WCHAR *startmode;
418 const WCHAR *systemname;
420 struct record_stdregprov
422 class_method *enumkey;
423 class_method *enumvalues;
425 struct record_videocontroller
428 UINT32 current_bitsperpixel;
429 UINT32 current_horizontalres;
430 UINT32 current_verticalres;
431 const WCHAR *device_id;
436 static HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
441 static HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
447 static const struct record_baseboard data_baseboard[] =
449 { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
451 static const struct record_bios data_bios[] =
453 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
455 static const struct record_params data_params[] =
457 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
458 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
459 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32 },
460 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
461 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
462 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
463 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32 },
464 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
465 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY }
467 static const struct record_stdregprov data_stdregprov[] =
469 { reg_enumkey, reg_enumvalues }
472 static UINT get_processor_count(void)
474 SYSTEM_BASIC_INFORMATION info;
476 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
477 return info.NumberOfProcessors;
480 static UINT get_logical_processor_count(void)
482 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
483 UINT i, j, count = 0;
487 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
488 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
490 if (!(info = heap_alloc( len ))) return get_processor_count();
491 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
492 if (status != STATUS_SUCCESS)
495 return get_processor_count();
497 for (i = 0; i < len / sizeof(*info); i++)
499 if (info[i].Relationship != RelationProcessorCore) continue;
500 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
506 static UINT64 get_total_physical_memory(void)
508 MEMORYSTATUSEX status;
510 status.dwLength = sizeof(status);
511 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
512 return status.ullTotalPhys;
515 static void fill_compsys( struct table *table )
517 struct record_computersystem *rec;
519 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
521 rec = (struct record_computersystem *)table->data;
522 rec->description = compsys_descriptionW;
523 rec->domainrole = 0; /* standalone workstation */
524 rec->manufacturer = compsys_manufacturerW;
525 rec->model = compsys_modelW;
526 rec->num_logical_processors = get_logical_processor_count();
527 rec->num_processors = get_processor_count();
528 rec->total_physical_memory = get_total_physical_memory();
530 TRACE("created 1 row\n");
534 static WCHAR *get_filesystem( const WCHAR *root )
536 static const WCHAR ntfsW[] = {'N','T','F','S',0};
537 WCHAR buffer[MAX_PATH + 1];
539 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
540 return heap_strdupW( buffer );
541 return heap_strdupW( ntfsW );
544 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
546 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
548 DISK_GEOMETRY_EX info;
551 free.QuadPart = 512 * 1024 * 1024;
552 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
555 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
556 if (handle != INVALID_HANDLE_VALUE)
558 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
559 *disksize = info.DiskSize.QuadPart;
560 CloseHandle( handle );
562 return free.QuadPart;
565 static void fill_logicaldisk( struct table *table )
567 static const WCHAR fmtW[] = {'%','c',':',0};
568 WCHAR device_id[3], root[] = {'A',':','\\',0};
569 struct record_logicaldisk *rec;
570 UINT i, num_rows = 0, offset = 0, count = 4, type;
571 UINT64 size = 1024 * 1024 * 1024;
572 DWORD drives = GetLogicalDrives();
574 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
576 for (i = 0; i < sizeof(drives); i++)
578 if (drives & (1 << i))
581 type = GetDriveTypeW( root );
582 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
585 if (num_rows > count)
589 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
592 rec = (struct record_logicaldisk *)(table->data + offset);
593 sprintfW( device_id, fmtW, 'A' + i );
594 rec->device_id = heap_strdupW( device_id );
595 rec->drivetype = type;
596 rec->filesystem = get_filesystem( root );
597 rec->freespace = get_freespace( root, &size );
599 offset += sizeof(*rec);
603 TRACE("created %u rows\n", num_rows);
604 table->num_rows = num_rows;
607 static UINT16 get_connection_status( IF_OPER_STATUS status )
611 case IfOperStatusDown:
612 return 0; /* Disconnected */
614 return 2; /* Connected */
616 ERR("unhandled status %u\n", status);
621 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
623 static const WCHAR fmtW[] =
624 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
625 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
628 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
629 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
633 static void fill_networkadapter( struct table *table )
635 static const WCHAR fmtW[] = {'%','u',0};
637 struct record_networkadapter *rec;
638 IP_ADAPTER_ADDRESSES *aa, *buffer;
639 UINT num_rows = 0, offset = 0;
642 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
643 if (ret != ERROR_BUFFER_OVERFLOW) return;
645 if (!(buffer = heap_alloc( size ))) return;
646 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
651 for (aa = buffer; aa; aa = aa->Next) num_rows++;
652 if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
657 for (aa = buffer; aa; aa = aa->Next)
659 rec = (struct record_networkadapter *)(table->data + offset);
660 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
661 rec->device_id = heap_strdupW( device_id );
662 rec->interface_index = aa->u.s.IfIndex;
663 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
664 rec->netconnection_status = get_connection_status( aa->OperStatus );
665 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
666 rec->speed = 1000000;
667 offset += sizeof(*rec);
669 TRACE("created %u rows\n", num_rows);
670 table->num_rows = num_rows;
675 static WCHAR *get_cmdline( DWORD process_id )
677 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
678 return NULL; /* FIXME handle different process case */
681 static void fill_process( struct table *table )
683 static const WCHAR fmtW[] = {'%','u',0};
685 struct record_process *rec;
686 PROCESSENTRY32W entry;
688 UINT num_rows = 0, offset = 0, count = 8;
690 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
691 if (snap == INVALID_HANDLE_VALUE) return;
693 entry.dwSize = sizeof(entry);
694 if (!Process32FirstW( snap, &entry )) goto done;
695 if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
699 if (num_rows > count)
703 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
706 rec = (struct record_process *)(table->data + offset);
707 rec->caption = heap_strdupW( entry.szExeFile );
708 rec->commandline = get_cmdline( entry.th32ProcessID );
709 rec->description = heap_strdupW( entry.szExeFile );
710 sprintfW( handle, fmtW, entry.th32ProcessID );
711 rec->handle = heap_strdupW( handle );
712 rec->process_id = entry.th32ProcessID;
713 rec->pprocess_id = entry.th32ParentProcessID;
714 rec->thread_count = entry.cntThreads;
715 offset += sizeof(*rec);
717 } while (Process32NextW( snap, &entry ));
719 TRACE("created %u rows\n", num_rows);
720 table->num_rows = num_rows;
726 static inline void do_cpuid( unsigned int ax, unsigned int *p )
729 __asm__("pushl %%ebx\n\t"
731 "movl %%ebx, %%esi\n\t"
733 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
738 static void get_processor_id( WCHAR *processor_id )
740 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
741 unsigned int regs[4] = {0, 0, 0, 0};
744 sprintfW( processor_id, fmtW, regs[3], regs[0] );
746 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
749 unsigned char *p = (unsigned char *)regs;
751 for (i = 0; i < len; i++)
757 static void get_processor_manufacturer( WCHAR *manufacturer )
759 unsigned int tmp, regs[4] = {0, 0, 0, 0};
762 tmp = regs[2]; /* swap edx and ecx */
766 regs_to_str( regs + 1, 12, manufacturer );
768 static void get_processor_name( WCHAR *name )
770 unsigned int regs[4] = {0, 0, 0, 0};
772 do_cpuid( 0x80000000, regs );
773 if (regs[0] >= 0x80000004)
775 do_cpuid( 0x80000002, regs );
776 regs_to_str( regs, 16, name );
777 do_cpuid( 0x80000003, regs );
778 regs_to_str( regs, 16, name + 16 );
779 do_cpuid( 0x80000004, regs );
780 regs_to_str( regs, 16, name + 32 );
783 static UINT get_processor_maxclockspeed( void )
785 PROCESSOR_POWER_INFORMATION info;
786 if (!NtPowerInformation( ProcessorInformation, NULL, 0, &info, sizeof(info) )) return info.MaxMhz;
790 static void fill_processor( struct table *table )
792 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
793 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
794 struct record_processor *rec;
795 UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
797 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
799 get_processor_id( processor_id );
800 get_processor_manufacturer( manufacturer );
801 get_processor_name( name );
803 maxclockspeed = get_processor_maxclockspeed();
804 num_logical_processors = get_logical_processor_count() / count;
806 for (i = 0; i < count; i++)
808 rec = (struct record_processor *)(table->data + offset);
809 rec->cpu_status = 1; /* CPU Enabled */
810 sprintfW( device_id, fmtW, i );
811 rec->device_id = heap_strdupW( device_id );
812 rec->manufacturer = heap_strdupW( manufacturer );
813 rec->maxclockspeed = maxclockspeed;
814 rec->name = heap_strdupW( name );
815 rec->num_logical_processors = num_logical_processors;
816 rec->processor_id = heap_strdupW( processor_id );
817 offset += sizeof(*rec);
820 TRACE("created %u rows\n", count);
821 table->num_rows = count;
824 static void fill_os( struct table *table )
826 struct record_operatingsystem *rec;
827 WCHAR path[MAX_PATH];
831 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
833 rec = (struct record_operatingsystem *)table->data;
834 rec->caption = os_captionW;
835 rec->csdversion = os_csdversionW;
837 GetNativeSystemInfo( &info );
838 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
839 rec->osarchitecture = os_64bitW;
841 rec->osarchitecture = os_32bitW;
843 rec->oslanguage = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
845 Wow64DisableWow64FsRedirection( &redir );
846 GetSystemDirectoryW( path, MAX_PATH );
847 Wow64RevertWow64FsRedirection( redir );
848 rec->systemdirectory = heap_strdupW( path );
850 TRACE("created 1 row\n");
854 static const WCHAR *get_service_type( DWORD type )
856 static const WCHAR filesystem_driverW[] =
857 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
858 static const WCHAR kernel_driverW[] =
859 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
860 static const WCHAR own_processW[] =
861 {'O','w','n',' ','P','r','o','c','e','s','s',0};
862 static const WCHAR share_processW[] =
863 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
865 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
866 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
867 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
868 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
869 else ERR("unhandled type 0x%08x\n", type);
872 static const WCHAR *get_service_state( DWORD state )
874 static const WCHAR runningW[] =
875 {'R','u','n','n','i','n','g',0};
876 static const WCHAR start_pendingW[] =
877 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
878 static const WCHAR stop_pendingW[] =
879 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
880 static const WCHAR stoppedW[] =
881 {'S','t','o','p','p','e','d',0};
882 static const WCHAR unknownW[] =
883 {'U','n','k','n','o','w','n',0};
887 case SERVICE_STOPPED: return stoppedW;
888 case SERVICE_START_PENDING: return start_pendingW;
889 case SERVICE_STOP_PENDING: return stop_pendingW;
890 case SERVICE_RUNNING: return runningW;
892 ERR("unknown state %u\n", state);
897 static const WCHAR *get_service_startmode( DWORD mode )
899 static const WCHAR bootW[] = {'B','o','o','t',0};
900 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
901 static const WCHAR autoW[] = {'A','u','t','o',0};
902 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
903 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
904 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
908 case SERVICE_BOOT_START: return bootW;
909 case SERVICE_SYSTEM_START: return systemW;
910 case SERVICE_AUTO_START: return autoW;
911 case SERVICE_DEMAND_START: return manualW;
912 case SERVICE_DISABLED: return disabledW;
914 ERR("unknown mode 0x%x\n", mode);
919 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
921 QUERY_SERVICE_CONFIGW *config = NULL;
925 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
926 QueryServiceConfigW( service, NULL, 0, &size );
927 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
928 if (!(config = heap_alloc( size ))) goto done;
929 if (QueryServiceConfigW( service, config, size, &size )) goto done;
934 CloseServiceHandle( service );
938 static void fill_service( struct table *table )
940 struct record_service *rec;
942 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
943 SERVICE_STATUS_PROCESS *status;
944 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
945 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
946 UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
949 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
950 if (!(services = heap_alloc( size ))) goto done;
952 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
953 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
954 &count, NULL, NULL );
957 if (GetLastError() != ERROR_MORE_DATA) goto done;
959 if (!(tmp = heap_realloc( services, size ))) goto done;
961 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
962 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
963 &count, NULL, NULL );
966 if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
968 GetComputerNameW( sysnameW, &len );
970 for (i = 0; i < count; i++)
972 QUERY_SERVICE_CONFIGW *config;
974 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
976 status = &services[i].ServiceStatusProcess;
977 rec = (struct record_service *)(table->data + offset);
978 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
979 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
980 rec->displayname = heap_strdupW( services[i].lpDisplayName );
981 rec->name = heap_strdupW( services[i].lpServiceName );
982 rec->process_id = status->dwProcessId;
983 rec->servicetype = get_service_type( status->dwServiceType );
984 rec->startmode = get_service_startmode( config->dwStartType );
985 rec->state = get_service_state( status->dwCurrentState );
986 rec->systemname = heap_strdupW( sysnameW );
988 offset += sizeof(*rec);
992 TRACE("created %u rows\n", num_rows);
993 table->num_rows = num_rows;
996 CloseServiceHandle( manager );
997 heap_free( services );
1000 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1002 HDC hdc = GetDC( NULL );
1005 if (!hdc) return 32;
1006 ret = GetDeviceCaps( hdc, BITSPIXEL );
1007 *hres = GetDeviceCaps( hdc, HORZRES );
1008 *vres = GetDeviceCaps( hdc, VERTRES );
1009 ReleaseDC( NULL, hdc );
1013 static void fill_videocontroller( struct table *table )
1016 struct record_videocontroller *rec;
1018 IDXGIFactory *factory = NULL;
1019 IDXGIAdapter *adapter = NULL;
1020 DXGI_ADAPTER_DESC desc;
1021 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1022 const WCHAR *name = videocontroller_deviceidW;
1024 if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1026 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1027 if (FAILED(hr)) goto done;
1029 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1030 if (FAILED(hr)) goto done;
1032 hr = IDXGIAdapter_GetDesc( adapter, &desc );
1035 vidmem = desc.DedicatedVideoMemory;
1036 name = desc.Description;
1040 rec = (struct record_videocontroller *)table->data;
1041 rec->adapter_ram = vidmem;
1042 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
1043 rec->current_horizontalres = hres;
1044 rec->current_verticalres = vres;
1045 rec->device_id = videocontroller_deviceidW;
1046 rec->name = heap_strdupW( name );
1048 TRACE("created 1 row\n");
1049 table->num_rows = 1;
1051 if (adapter) IDXGIAdapter_Release( adapter );
1052 if (factory) IDXGIFactory_Release( factory );
1055 static struct table builtin_classes[] =
1057 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1058 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1059 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1060 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1061 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1062 { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1063 { class_paramsW, SIZEOF(col_params), col_params, SIZEOF(data_params), (BYTE *)data_params },
1064 { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1065 { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1066 { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1067 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1068 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1071 void init_table_list( void )
1073 static struct list tables = LIST_INIT( tables );
1076 for (i = 0; i < SIZEOF(builtin_classes); i++)
1078 list_add_tail( &tables, &builtin_classes[i].entry );
1080 table_list = &tables;