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_drivetypeW
[] =
101 {'D','r','i','v','e','T','y','p','e',0};
102 static const WCHAR prop_filesystemW
[] =
103 {'F','i','l','e','S','y','s','t','e','m',0};
104 static const WCHAR prop_freespaceW
[] =
105 {'F','r','e','e','S','p','a','c','e',0};
106 static const WCHAR prop_handleW
[] =
107 {'H','a','n','d','l','e',0};
108 static const WCHAR prop_interfaceindexW
[] =
109 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
110 static const WCHAR prop_macaddressW
[] =
111 {'M','A','C','A','d','d','r','e','s','s',0};
112 static const WCHAR prop_manufacturerW
[] =
113 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
114 static const WCHAR prop_methodW
[] =
115 {'M','e','t','h','o','d',0};
116 static const WCHAR prop_modelW
[] =
117 {'M','o','d','e','l',0};
118 static const WCHAR prop_nameW
[] =
120 static const WCHAR prop_netconnectionstatusW
[] =
121 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
122 static const WCHAR prop_numlogicalprocessorsW
[] =
123 {'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};
124 static const WCHAR prop_numprocessorsW
[] =
125 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
126 static const WCHAR prop_osarchitectureW
[] =
127 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
128 static const WCHAR prop_oslanguageW
[] =
129 {'O','S','L','a','n','g','u','a','g','e',0};
130 static const WCHAR prop_parameterW
[] =
131 {'P','a','r','a','m','e','t','e','r',0};
132 static const WCHAR prop_pnpdeviceidW
[] =
133 {'P','N','P','D','e','v','i','c','e','I','D',0};
134 static const WCHAR prop_pprocessidW
[] =
135 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
136 static const WCHAR prop_processidW
[] =
137 {'P','r','o','c','e','s','s','I','D',0};
138 static const WCHAR prop_processoridW
[] =
139 {'P','r','o','c','e','s','s','o','r','I','d',0};
140 static const WCHAR prop_releasedateW
[] =
141 {'R','e','l','e','a','s','e','D','a','t','e',0};
142 static const WCHAR prop_serialnumberW
[] =
143 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
144 static const WCHAR prop_servicetypeW
[] =
145 {'S','e','r','v','i','c','e','T','y','p','e',0};
146 static const WCHAR prop_startmodeW
[] =
147 {'S','t','a','r','t','M','o','d','e',0};
148 static const WCHAR prop_sizeW
[] =
150 static const WCHAR prop_speedW
[] =
151 {'S','p','e','e','d',0};
152 static const WCHAR prop_stateW
[] =
153 {'S','t','a','t','e',0};
154 static const WCHAR prop_systemdirectoryW
[] =
155 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
156 static const WCHAR prop_tagW
[] =
158 static const WCHAR prop_threadcountW
[] =
159 {'T','h','r','e','a','d','C','o','u','n','t',0};
160 static const WCHAR prop_totalphysicalmemoryW
[] =
161 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
162 static const WCHAR prop_typeW
[] =
165 static const WCHAR method_enumkeyW
[] =
166 {'E','n','u','m','K','e','y',0};
167 static const WCHAR method_enumvaluesW
[] =
168 {'E','n','u','m','V','a','l','u','e','s',0};
170 static const WCHAR param_defkeyW
[] =
171 {'h','D','e','f','K','e','y',0};
172 static const WCHAR param_namesW
[] =
173 {'N','a','m','e','s',0};
174 static const WCHAR param_returnvalueW
[] =
175 {'R','e','t','u','r','n','V','a','l','u','e',0};
176 static const WCHAR param_subkeynameW
[] =
177 {'s','S','u','b','K','e','y','N','a','m','e',0};
178 static const WCHAR param_typesW
[] =
179 {'T','y','p','e','s',0};
181 /* column definitions must be kept in sync with record structures below */
182 static const struct column col_baseboard
[] =
184 { prop_manufacturerW
, CIM_STRING
},
185 { prop_serialnumberW
, CIM_STRING
},
186 { prop_tagW
, CIM_STRING
|COL_FLAG_KEY
}
188 static const struct column col_bios
[] =
190 { prop_descriptionW
, CIM_STRING
},
191 { prop_manufacturerW
, CIM_STRING
},
192 { prop_releasedateW
, CIM_DATETIME
},
193 { prop_serialnumberW
, CIM_STRING
}
195 static const struct column col_compsys
[] =
197 { prop_descriptionW
, CIM_STRING
},
198 { prop_manufacturerW
, CIM_STRING
},
199 { prop_modelW
, CIM_STRING
},
200 { prop_numlogicalprocessorsW
, CIM_UINT32
, VT_I4
},
201 { prop_numprocessorsW
, CIM_UINT32
, VT_I4
},
202 { prop_totalphysicalmemoryW
, CIM_UINT64
}
204 static const struct column col_logicaldisk
[] =
206 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
207 { prop_drivetypeW
, CIM_UINT32
, VT_I4
},
208 { prop_filesystemW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
209 { prop_freespaceW
, CIM_UINT64
},
210 { prop_sizeW
, CIM_UINT64
}
212 static const struct column col_networkadapter
[] =
214 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
215 { prop_interfaceindexW
, CIM_UINT32
, VT_I4
},
216 { prop_macaddressW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
217 { prop_netconnectionstatusW
, CIM_UINT16
, VT_I4
},
218 { prop_pnpdeviceidW
, CIM_STRING
},
219 { prop_speedW
, CIM_UINT64
}
221 static const struct column col_os
[] =
223 { prop_captionW
, CIM_STRING
},
224 { prop_csdversionW
, CIM_STRING
},
225 { prop_osarchitectureW
, CIM_STRING
},
226 { prop_oslanguageW
, CIM_UINT32
, VT_I4
},
227 { prop_systemdirectoryW
, CIM_STRING
}
229 static const struct column col_params
[] =
231 { prop_classW
, CIM_STRING
},
232 { prop_methodW
, CIM_STRING
},
233 { prop_directionW
, CIM_SINT32
},
234 { prop_parameterW
, CIM_STRING
},
235 { prop_typeW
, CIM_UINT32
},
236 { prop_defaultvalueW
, CIM_UINT32
}
238 static const struct column col_process
[] =
240 { prop_captionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
241 { prop_commandlineW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
242 { prop_descriptionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
243 { prop_handleW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
244 { prop_pprocessidW
, CIM_UINT32
, VT_I4
},
245 { prop_processidW
, CIM_UINT32
, VT_I4
},
246 { prop_threadcountW
, CIM_UINT32
, VT_I4
}
248 static const struct column col_processor
[] =
250 { prop_cpustatusW
, CIM_UINT16
},
251 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
252 { prop_manufacturerW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
253 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
254 { prop_processoridW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
256 static const struct column col_service
[] =
258 { prop_acceptpauseW
, CIM_BOOLEAN
},
259 { prop_acceptstopW
, CIM_BOOLEAN
},
260 { prop_displaynameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
261 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
262 { prop_processidW
, CIM_UINT32
},
263 { prop_servicetypeW
, CIM_STRING
},
264 { prop_startmodeW
, CIM_STRING
},
265 { prop_stateW
, CIM_STRING
}
267 static const struct column col_stdregprov
[] =
269 { method_enumkeyW
, CIM_OBJECT
|COL_FLAG_METHOD
},
270 { method_enumvaluesW
, CIM_OBJECT
|COL_FLAG_METHOD
}
272 static const struct column col_videocontroller
[] =
274 { prop_adapterramW
, CIM_UINT32
},
275 { prop_currentbitsperpixelW
, CIM_UINT32
},
276 { prop_currenthorizontalresW
, CIM_UINT32
},
277 { prop_currentverticalresW
, CIM_UINT32
},
278 { prop_deviceidW
, CIM_STRING
|COL_FLAG_KEY
},
279 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
282 static const WCHAR baseboard_manufacturerW
[] =
283 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
284 static const WCHAR baseboard_serialnumberW
[] =
286 static const WCHAR baseboard_tagW
[] =
287 {'B','a','s','e',' ','B','o','a','r','d',0};
288 static const WCHAR bios_descriptionW
[] =
289 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
290 static const WCHAR bios_manufacturerW
[] =
291 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
292 static const WCHAR bios_releasedateW
[] =
293 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
294 static const WCHAR bios_serialnumberW
[] =
296 static const WCHAR compsys_descriptionW
[] =
297 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
298 static const WCHAR compsys_manufacturerW
[] =
299 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
300 static const WCHAR compsys_modelW
[] =
302 static const WCHAR networkadapter_pnpdeviceidW
[]=
303 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
304 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
305 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
306 static const WCHAR os_captionW
[] =
307 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
308 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
309 static const WCHAR os_csdversionW
[] =
310 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
311 static const WCHAR os_32bitW
[] =
312 {'3','2','-','b','i','t',0};
313 static const WCHAR os_64bitW
[] =
314 {'6','4','-','b','i','t',0};
315 static const WCHAR videocontroller_deviceidW
[] =
316 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
318 #include "pshpack1.h"
319 struct record_baseboard
321 const WCHAR
*manufacturer
;
322 const WCHAR
*serialnumber
;
327 const WCHAR
*description
;
328 const WCHAR
*manufacturer
;
329 const WCHAR
*releasedate
;
330 const WCHAR
*serialnumber
;
332 struct record_computersystem
334 const WCHAR
*description
;
335 const WCHAR
*manufacturer
;
337 UINT32 num_logical_processors
;
338 UINT32 num_processors
;
339 UINT64 total_physical_memory
;
341 struct record_logicaldisk
343 const WCHAR
*device_id
;
345 const WCHAR
*filesystem
;
349 struct record_networkadapter
351 const WCHAR
*device_id
;
352 INT32 interface_index
;
353 const WCHAR
*mac_address
;
354 UINT16 netconnection_status
;
355 const WCHAR
*pnpdevice_id
;
358 struct record_operatingsystem
360 const WCHAR
*caption
;
361 const WCHAR
*csdversion
;
362 const WCHAR
*osarchitecture
;
364 const WCHAR
*systemdirectory
;
371 const WCHAR
*parameter
;
375 struct record_process
377 const WCHAR
*caption
;
378 const WCHAR
*commandline
;
379 const WCHAR
*description
;
385 struct record_processor
388 const WCHAR
*device_id
;
389 const WCHAR
*manufacturer
;
391 const WCHAR
*processor_id
;
393 struct record_service
397 const WCHAR
*displayname
;
400 const WCHAR
*servicetype
;
401 const WCHAR
*startmode
;
404 struct record_stdregprov
406 class_method
*enumkey
;
407 class_method
*enumvalues
;
409 struct record_videocontroller
412 UINT32 current_bitsperpixel
;
413 UINT32 current_horizontalres
;
414 UINT32 current_verticalres
;
415 const WCHAR
*device_id
;
420 static HRESULT
reg_enumkey( IWbemClassObject
*in
, IWbemClassObject
**out
)
425 static HRESULT
reg_enumvalues( IWbemClassObject
*in
, IWbemClassObject
**out
)
431 static const struct record_baseboard data_baseboard
[] =
433 { baseboard_manufacturerW
, baseboard_serialnumberW
, baseboard_tagW
}
435 static const struct record_bios data_bios
[] =
437 { bios_descriptionW
, bios_manufacturerW
, bios_releasedateW
, bios_serialnumberW
}
439 static const struct record_params data_params
[] =
441 { class_stdregprovW
, method_enumkeyW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
442 { class_stdregprovW
, method_enumkeyW
, 1, param_subkeynameW
, CIM_STRING
},
443 { class_stdregprovW
, method_enumkeyW
, -1, param_returnvalueW
, CIM_UINT32
},
444 { class_stdregprovW
, method_enumkeyW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
445 { class_stdregprovW
, method_enumvaluesW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
446 { class_stdregprovW
, method_enumvaluesW
, 1, param_subkeynameW
, CIM_STRING
},
447 { class_stdregprovW
, method_enumvaluesW
, -1, param_returnvalueW
, CIM_UINT32
},
448 { class_stdregprovW
, method_enumvaluesW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
449 { class_stdregprovW
, method_enumvaluesW
, -1, param_typesW
, CIM_SINT32
|CIM_FLAG_ARRAY
}
451 static const struct record_stdregprov data_stdregprov
[] =
453 { reg_enumkey
, reg_enumvalues
}
456 static UINT
get_processor_count(void)
458 SYSTEM_BASIC_INFORMATION info
;
460 if (NtQuerySystemInformation( SystemBasicInformation
, &info
, sizeof(info
), NULL
)) return 1;
461 return info
.NumberOfProcessors
;
464 static UINT64
get_total_physical_memory(void)
466 MEMORYSTATUSEX status
;
468 status
.dwLength
= sizeof(status
);
469 if (!GlobalMemoryStatusEx( &status
)) return 1024 * 1024 * 1024;
470 return status
.ullTotalPhys
;
473 static void fill_compsys( struct table
*table
)
475 struct record_computersystem
*rec
;
477 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
479 rec
= (struct record_computersystem
*)table
->data
;
480 rec
->description
= compsys_descriptionW
;
481 rec
->manufacturer
= compsys_manufacturerW
;
482 rec
->model
= compsys_modelW
;
483 rec
->num_logical_processors
= get_processor_count();
484 rec
->num_processors
= rec
->num_logical_processors
;
485 rec
->total_physical_memory
= get_total_physical_memory();
487 TRACE("created 1 row\n");
491 static WCHAR
*get_filesystem( const WCHAR
*root
)
493 static const WCHAR ntfsW
[] = {'N','T','F','S',0};
494 WCHAR buffer
[MAX_PATH
+ 1];
496 if (GetVolumeInformationW( root
, NULL
, 0, NULL
, NULL
, NULL
, buffer
, MAX_PATH
+ 1 ))
497 return heap_strdupW( buffer
);
498 return heap_strdupW( ntfsW
);
501 static UINT64
get_freespace( const WCHAR
*dir
, UINT64
*disksize
)
503 WCHAR root
[] = {'\\','\\','.','\\','A',':',0};
505 DISK_GEOMETRY_EX info
;
508 free
.QuadPart
= 512 * 1024 * 1024;
509 GetDiskFreeSpaceExW( dir
, NULL
, NULL
, &free
);
512 handle
= CreateFileW( root
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
513 if (handle
!= INVALID_HANDLE_VALUE
)
515 if (DeviceIoControl( handle
, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
))
516 *disksize
= info
.DiskSize
.QuadPart
;
517 CloseHandle( handle
);
519 return free
.QuadPart
;
522 static void fill_logicaldisk( struct table
*table
)
524 static const WCHAR fmtW
[] = {'%','c',':',0};
525 WCHAR device_id
[3], root
[] = {'A',':','\\',0};
526 struct record_logicaldisk
*rec
;
527 UINT i
, num_rows
= 0, offset
= 0, count
= 4, type
;
528 UINT64 size
= 1024 * 1024 * 1024;
529 DWORD drives
= GetLogicalDrives();
531 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) return;
533 for (i
= 0; i
< sizeof(drives
); i
++)
535 if (drives
& (1 << i
))
538 type
= GetDriveTypeW( root
);
539 if (type
!= DRIVE_FIXED
&& type
!= DRIVE_CDROM
&& type
!= DRIVE_REMOVABLE
)
542 if (num_rows
> count
)
546 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) return;
549 rec
= (struct record_logicaldisk
*)(table
->data
+ offset
);
550 sprintfW( device_id
, fmtW
, 'A' + i
);
551 rec
->device_id
= heap_strdupW( device_id
);
552 rec
->drivetype
= type
;
553 rec
->filesystem
= get_filesystem( root
);
554 rec
->freespace
= get_freespace( root
, &size
);
556 offset
+= sizeof(*rec
);
560 TRACE("created %u rows\n", num_rows
);
561 table
->num_rows
= num_rows
;
564 static UINT16
get_connection_status( IF_OPER_STATUS status
)
568 case IfOperStatusDown
:
569 return 0; /* Disconnected */
571 return 2; /* Connected */
573 ERR("unhandled status %u\n", status
);
578 static WCHAR
*get_mac_address( const BYTE
*addr
, DWORD len
)
580 static const WCHAR fmtW
[] =
581 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
582 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
585 if (len
!= 6 || !(ret
= heap_alloc( 18 * sizeof(WCHAR
) ))) return NULL
;
586 sprintfW( ret
, fmtW
, addr
[0], addr
[1], addr
[2], addr
[3], addr
[4], addr
[5] );
590 static void fill_networkadapter( struct table
*table
)
592 static const WCHAR fmtW
[] = {'%','u',0};
594 struct record_networkadapter
*rec
;
595 IP_ADAPTER_ADDRESSES
*aa
, *buffer
;
596 UINT num_rows
= 0, offset
= 0;
599 ret
= GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, NULL
, &size
);
600 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
602 if (!(buffer
= heap_alloc( size
))) return;
603 if (GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, buffer
, &size
))
608 for (aa
= buffer
; aa
; aa
= aa
->Next
) num_rows
++;
609 if (!(table
->data
= heap_alloc( sizeof(*rec
) * num_rows
)))
614 for (aa
= buffer
; aa
; aa
= aa
->Next
)
616 rec
= (struct record_networkadapter
*)(table
->data
+ offset
);
617 sprintfW( device_id
, fmtW
, aa
->u
.s
.IfIndex
);
618 rec
->device_id
= heap_strdupW( device_id
);
619 rec
->interface_index
= aa
->u
.s
.IfIndex
;
620 rec
->mac_address
= get_mac_address( aa
->PhysicalAddress
, aa
->PhysicalAddressLength
);
621 rec
->netconnection_status
= get_connection_status( aa
->OperStatus
);
622 rec
->pnpdevice_id
= networkadapter_pnpdeviceidW
;
623 rec
->speed
= 1000000;
624 offset
+= sizeof(*rec
);
626 TRACE("created %u rows\n", num_rows
);
627 table
->num_rows
= num_rows
;
632 static WCHAR
*get_cmdline( DWORD process_id
)
634 if (process_id
== GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
635 return NULL
; /* FIXME handle different process case */
638 static void fill_process( struct table
*table
)
640 static const WCHAR fmtW
[] = {'%','u',0};
642 struct record_process
*rec
;
643 PROCESSENTRY32W entry
;
645 UINT num_rows
= 0, offset
= 0, count
= 8;
647 snap
= CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
648 if (snap
== INVALID_HANDLE_VALUE
) return;
650 entry
.dwSize
= sizeof(entry
);
651 if (!Process32FirstW( snap
, &entry
)) goto done
;
652 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) goto done
;
656 if (num_rows
> count
)
660 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) goto done
;
663 rec
= (struct record_process
*)(table
->data
+ offset
);
664 rec
->caption
= heap_strdupW( entry
.szExeFile
);
665 rec
->commandline
= get_cmdline( entry
.th32ProcessID
);
666 rec
->description
= heap_strdupW( entry
.szExeFile
);
667 sprintfW( handle
, fmtW
, entry
.th32ProcessID
);
668 rec
->handle
= heap_strdupW( handle
);
669 rec
->process_id
= entry
.th32ProcessID
;
670 rec
->pprocess_id
= entry
.th32ParentProcessID
;
671 rec
->thread_count
= entry
.cntThreads
;
672 offset
+= sizeof(*rec
);
674 } while (Process32NextW( snap
, &entry
));
676 TRACE("created %u rows\n", num_rows
);
677 table
->num_rows
= num_rows
;
683 static inline void do_cpuid( unsigned int ax
, unsigned int *p
)
686 __asm__("pushl %%ebx\n\t"
688 "movl %%ebx, %%esi\n\t"
690 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
695 static void get_processor_id( WCHAR
*processor_id
)
697 static const WCHAR fmtW
[] = {'%','0','8','X','%','0','8','X',0};
698 unsigned int regs
[4] = {0, 0, 0, 0};
701 sprintfW( processor_id
, fmtW
, regs
[3], regs
[0] );
703 static void regs_to_str( unsigned int *regs
, unsigned int len
, WCHAR
*buffer
)
706 unsigned char *p
= (unsigned char *)regs
;
708 for (i
= 0; i
< len
; i
++)
714 static void get_processor_manufacturer( WCHAR
*manufacturer
)
716 unsigned int tmp
, regs
[4] = {0, 0, 0, 0};
719 tmp
= regs
[2]; /* swap edx and ecx */
723 regs_to_str( regs
+ 1, 12, manufacturer
);
725 static void get_processor_name( WCHAR
*name
)
727 unsigned int regs
[4] = {0, 0, 0, 0};
729 do_cpuid( 0x80000000, regs
);
730 if (regs
[0] >= 0x80000004)
732 do_cpuid( 0x80000002, regs
);
733 regs_to_str( regs
, 16, name
);
734 do_cpuid( 0x80000003, regs
);
735 regs_to_str( regs
, 16, name
+ 16 );
736 do_cpuid( 0x80000004, regs
);
737 regs_to_str( regs
, 16, name
+ 32 );
741 static void fill_processor( struct table
*table
)
743 static const WCHAR fmtW
[] = {'C','P','U','%','u',0};
744 WCHAR device_id
[14], processor_id
[17], manufacturer
[13], name
[49] = {0};
745 struct record_processor
*rec
;
746 UINT i
, offset
= 0, count
= get_processor_count();
748 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) return;
750 get_processor_id( processor_id
);
751 get_processor_manufacturer( manufacturer
);
752 get_processor_name( name
);
754 for (i
= 0; i
< count
; i
++)
756 rec
= (struct record_processor
*)(table
->data
+ offset
);
757 rec
->cpu_status
= 1; /* CPU Enabled */
758 sprintfW( device_id
, fmtW
, i
);
759 rec
->device_id
= heap_strdupW( device_id
);
760 rec
->manufacturer
= heap_strdupW( manufacturer
);
761 rec
->name
= heap_strdupW( name
);
762 rec
->processor_id
= heap_strdupW( processor_id
);
763 offset
+= sizeof(*rec
);
766 TRACE("created %u rows\n", count
);
767 table
->num_rows
= count
;
770 static void fill_os( struct table
*table
)
772 struct record_operatingsystem
*rec
;
773 WCHAR path
[MAX_PATH
];
777 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
779 rec
= (struct record_operatingsystem
*)table
->data
;
780 rec
->caption
= os_captionW
;
781 rec
->csdversion
= os_csdversionW
;
783 GetNativeSystemInfo( &info
);
784 if (info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
785 rec
->osarchitecture
= os_64bitW
;
787 rec
->osarchitecture
= os_32bitW
;
789 rec
->oslanguage
= MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
791 Wow64DisableWow64FsRedirection( &redir
);
792 GetSystemDirectoryW( path
, MAX_PATH
);
793 Wow64RevertWow64FsRedirection( redir
);
794 rec
->systemdirectory
= heap_strdupW( path
);
796 TRACE("created 1 row\n");
800 static const WCHAR
*get_service_type( DWORD type
)
802 static const WCHAR filesystem_driverW
[] =
803 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
804 static const WCHAR kernel_driverW
[] =
805 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
806 static const WCHAR own_processW
[] =
807 {'O','w','n',' ','P','r','o','c','e','s','s',0};
808 static const WCHAR share_processW
[] =
809 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
811 if (type
& SERVICE_KERNEL_DRIVER
) return kernel_driverW
;
812 else if (type
& SERVICE_FILE_SYSTEM_DRIVER
) return filesystem_driverW
;
813 else if (type
& SERVICE_WIN32_OWN_PROCESS
) return own_processW
;
814 else if (type
& SERVICE_WIN32_SHARE_PROCESS
) return share_processW
;
815 else ERR("unhandled type 0x%08x\n", type
);
818 static const WCHAR
*get_service_state( DWORD state
)
820 static const WCHAR runningW
[] =
821 {'R','u','n','n','i','n','g',0};
822 static const WCHAR start_pendingW
[] =
823 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
824 static const WCHAR stop_pendingW
[] =
825 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
826 static const WCHAR stoppedW
[] =
827 {'S','t','o','p','p','e','d',0};
828 static const WCHAR unknownW
[] =
829 {'U','n','k','n','o','w','n',0};
833 case SERVICE_STOPPED
: return stoppedW
;
834 case SERVICE_START_PENDING
: return start_pendingW
;
835 case SERVICE_STOP_PENDING
: return stop_pendingW
;
836 case SERVICE_RUNNING
: return runningW
;
838 ERR("unknown state %u\n", state
);
843 static const WCHAR
*get_service_startmode( DWORD mode
)
845 static const WCHAR bootW
[] = {'B','o','o','t',0};
846 static const WCHAR systemW
[] = {'S','y','s','t','e','m',0};
847 static const WCHAR autoW
[] = {'A','u','t','o',0};
848 static const WCHAR manualW
[] = {'M','a','n','u','a','l',0};
849 static const WCHAR disabledW
[] = {'D','i','s','a','b','l','e','d',0};
850 static const WCHAR unknownW
[] = {'U','n','k','n','o','w','n',0};
854 case SERVICE_BOOT_START
: return bootW
;
855 case SERVICE_SYSTEM_START
: return systemW
;
856 case SERVICE_AUTO_START
: return autoW
;
857 case SERVICE_DEMAND_START
: return manualW
;
858 case SERVICE_DISABLED
: return disabledW
;
860 ERR("unknown mode 0x%x\n", mode
);
865 static void fill_service( struct table
*table
)
867 struct record_service
*rec
;
869 ENUM_SERVICE_STATUS_PROCESSW
*tmp
, *services
= NULL
;
870 SERVICE_STATUS_PROCESS
*status
;
871 UINT i
, num_rows
= 0, offset
= 0, size
= 256, needed
, count
;
874 if (!(manager
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
))) return;
875 if (!(services
= heap_alloc( size
))) goto done
;
877 ret
= EnumServicesStatusExW( manager
, SC_ENUM_PROCESS_INFO
, SERVICE_TYPE_ALL
,
878 SERVICE_STATE_ALL
, (BYTE
*)services
, size
, &needed
,
879 &count
, NULL
, NULL
);
882 if (GetLastError() != ERROR_MORE_DATA
) goto done
;
884 if (!(tmp
= heap_realloc( services
, size
))) goto done
;
886 ret
= EnumServicesStatusExW( manager
, SC_ENUM_PROCESS_INFO
, SERVICE_TYPE_ALL
,
887 SERVICE_STATE_ALL
, (BYTE
*)services
, size
, &needed
,
888 &count
, NULL
, NULL
);
891 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) goto done
;
893 for (i
= 0; i
< count
; i
++)
895 QUERY_SERVICE_CONFIGW
*config
;
900 service
= OpenServiceW(manager
, services
[i
].lpServiceName
, GENERIC_READ
);
901 QueryServiceConfigW(service
, NULL
, 0, &size
);
902 config
= heap_alloc(size
);
903 if (QueryServiceConfigW(service
, config
, size
, &size
))
904 startmode
= config
->dwStartType
;
907 ERR("failed to get %s service config data\n", debugstr_w(services
[i
].lpServiceName
));
908 startmode
= SERVICE_DISABLED
;
910 CloseServiceHandle(service
);
913 status
= &services
[i
].ServiceStatusProcess
;
914 rec
= (struct record_service
*)(table
->data
+ offset
);
915 rec
->accept_pause
= (status
->dwControlsAccepted
& SERVICE_ACCEPT_PAUSE_CONTINUE
) ? -1 : 0;
916 rec
->accept_stop
= (status
->dwControlsAccepted
& SERVICE_ACCEPT_STOP
) ? -1 : 0;
917 rec
->displayname
= heap_strdupW( services
[i
].lpDisplayName
);
918 rec
->name
= heap_strdupW( services
[i
].lpServiceName
);
919 rec
->process_id
= status
->dwProcessId
;
920 rec
->servicetype
= get_service_type( status
->dwServiceType
);
921 rec
->startmode
= get_service_startmode( startmode
);
922 rec
->state
= get_service_state( status
->dwCurrentState
);
923 offset
+= sizeof(*rec
);
927 TRACE("created %u rows\n", num_rows
);
928 table
->num_rows
= num_rows
;
931 CloseServiceHandle( manager
);
932 heap_free( services
);
935 static UINT32
get_bits_per_pixel( UINT
*hres
, UINT
*vres
)
937 HDC hdc
= GetDC( NULL
);
941 ret
= GetDeviceCaps( hdc
, BITSPIXEL
);
942 *hres
= GetDeviceCaps( hdc
, HORZRES
);
943 *vres
= GetDeviceCaps( hdc
, VERTRES
);
944 ReleaseDC( NULL
, hdc
);
948 static void fill_videocontroller( struct table
*table
)
951 struct record_videocontroller
*rec
;
953 IDXGIFactory
*factory
= NULL
;
954 IDXGIAdapter
*adapter
= NULL
;
955 DXGI_ADAPTER_DESC desc
;
956 UINT hres
= 1024, vres
= 768, vidmem
= 512 * 1024 * 1024;
957 const WCHAR
*name
= videocontroller_deviceidW
;
959 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
961 hr
= CreateDXGIFactory( &IID_IDXGIFactory
, (void **)&factory
);
962 if (FAILED(hr
)) goto done
;
964 hr
= IDXGIFactory_EnumAdapters( factory
, 0, &adapter
);
965 if (FAILED(hr
)) goto done
;
967 hr
= IDXGIAdapter_GetDesc( adapter
, &desc
);
970 vidmem
= desc
.DedicatedVideoMemory
;
971 name
= desc
.Description
;
975 rec
= (struct record_videocontroller
*)table
->data
;
976 rec
->adapter_ram
= vidmem
;
977 rec
->current_bitsperpixel
= get_bits_per_pixel( &hres
, &vres
);
978 rec
->current_horizontalres
= hres
;
979 rec
->current_verticalres
= vres
;
980 rec
->device_id
= videocontroller_deviceidW
;
981 rec
->name
= heap_strdupW( name
);
983 TRACE("created 1 row\n");
986 if (adapter
) IDXGIAdapter_Release( adapter
);
987 if (factory
) IDXGIFactory_Release( factory
);
990 static struct table builtin_classes
[] =
992 { class_baseboardW
, SIZEOF(col_baseboard
), col_baseboard
, SIZEOF(data_baseboard
), (BYTE
*)data_baseboard
},
993 { class_biosW
, SIZEOF(col_bios
), col_bios
, SIZEOF(data_bios
), (BYTE
*)data_bios
},
994 { class_compsysW
, SIZEOF(col_compsys
), col_compsys
, 0, NULL
, fill_compsys
},
995 { class_logicaldiskW
, SIZEOF(col_logicaldisk
), col_logicaldisk
, 0, NULL
, fill_logicaldisk
},
996 { class_networkadapterW
, SIZEOF(col_networkadapter
), col_networkadapter
, 0, NULL
, fill_networkadapter
},
997 { class_osW
, SIZEOF(col_os
), col_os
, 0, NULL
, fill_os
},
998 { class_paramsW
, SIZEOF(col_params
), col_params
, SIZEOF(data_params
), (BYTE
*)data_params
},
999 { class_processW
, SIZEOF(col_process
), col_process
, 0, NULL
, fill_process
},
1000 { class_processorW
, SIZEOF(col_processor
), col_processor
, 0, NULL
, fill_processor
},
1001 { class_serviceW
, SIZEOF(col_service
), col_service
, 0, NULL
, fill_service
},
1002 { class_stdregprovW
, SIZEOF(col_stdregprov
), col_stdregprov
, SIZEOF(data_stdregprov
), (BYTE
*)data_stdregprov
},
1003 { class_videocontrollerW
, SIZEOF(col_videocontroller
), col_videocontroller
, 0, NULL
, fill_videocontroller
}
1006 void init_table_list( void )
1008 static struct list tables
= LIST_INIT( tables
);
1011 for (i
= 0; i
< SIZEOF(builtin_classes
); i
++)
1013 list_add_tail( &tables
, &builtin_classes
[i
].entry
);
1015 table_list
= &tables
;