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
41 #include "wine/debug.h"
42 #include "wbemprox_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
46 static const WCHAR class_baseboardW
[] =
47 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
48 static const WCHAR class_biosW
[] =
49 {'W','i','n','3','2','_','B','I','O','S',0};
50 static const WCHAR class_compsysW
[] =
51 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
52 static const WCHAR class_logicaldiskW
[] =
53 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
54 static const WCHAR class_networkadapterW
[] =
55 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
56 static const WCHAR class_osW
[] =
57 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
58 static const WCHAR class_paramsW
[] =
59 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
60 static const WCHAR class_processW
[] =
61 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
62 static const WCHAR class_processorW
[] =
63 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
64 static const WCHAR class_serviceW
[] =
65 {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
66 static const WCHAR class_stdregprovW
[] =
67 {'S','t','d','R','e','g','P','r','o','v',0};
68 static const WCHAR class_videocontrollerW
[] =
69 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
71 static const WCHAR prop_acceptpauseW
[] =
72 {'A','c','c','e','p','t','P','a','u','s','e',0};
73 static const WCHAR prop_acceptstopW
[] =
74 {'A','c','c','e','p','t','S','t','o','p',0};
75 static const WCHAR prop_adapterramW
[] =
76 {'A','d','a','p','t','e','r','R','A','M',0};
77 static const WCHAR prop_captionW
[] =
78 {'C','a','p','t','i','o','n',0};
79 static const WCHAR prop_classW
[] =
80 {'C','l','a','s','s',0};
81 static const WCHAR prop_commandlineW
[] =
82 {'C','o','m','m','a','n','d','L','i','n','e',0};
83 static const WCHAR prop_cpustatusW
[] =
84 {'C','p','u','S','t','a','t','u','s',0};
85 static const WCHAR prop_csdversionW
[] =
86 {'C','S','D','V','e','r','s','i','o','n',0};
87 static const WCHAR prop_currentbitsperpixelW
[] =
88 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
89 static const WCHAR prop_currenthorizontalresW
[] =
90 {'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};
91 static const WCHAR prop_currentverticalresW
[] =
92 {'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};
93 static const WCHAR prop_defaultvalueW
[] =
94 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
95 static const WCHAR prop_descriptionW
[] =
96 {'D','e','s','c','r','i','p','t','i','o','n',0};
97 static const WCHAR prop_deviceidW
[] =
98 {'D','e','v','i','c','e','I','d',0};
99 static const WCHAR prop_directionW
[] =
100 {'D','i','r','e','c','t','i','o','n',0};
101 static const WCHAR prop_displaynameW
[] =
102 {'D','i','s','p','l','a','y','N','a','m','e',0};
103 static const WCHAR prop_domainroleW
[] =
104 {'D','o','m','a','i','n','R','o','l','e',0};
105 static const WCHAR prop_drivetypeW
[] =
106 {'D','r','i','v','e','T','y','p','e',0};
107 static const WCHAR prop_filesystemW
[] =
108 {'F','i','l','e','S','y','s','t','e','m',0};
109 static const WCHAR prop_freespaceW
[] =
110 {'F','r','e','e','S','p','a','c','e',0};
111 static const WCHAR prop_handleW
[] =
112 {'H','a','n','d','l','e',0};
113 static const WCHAR prop_interfaceindexW
[] =
114 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
115 static const WCHAR prop_lastbootuptimeW
[] =
116 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
117 static const WCHAR prop_macaddressW
[] =
118 {'M','A','C','A','d','d','r','e','s','s',0};
119 static const WCHAR prop_manufacturerW
[] =
120 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
121 static const WCHAR prop_maxclockspeedW
[] =
122 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
123 static const WCHAR prop_methodW
[] =
124 {'M','e','t','h','o','d',0};
125 static const WCHAR prop_modelW
[] =
126 {'M','o','d','e','l',0};
127 static const WCHAR prop_nameW
[] =
129 static const WCHAR prop_netconnectionstatusW
[] =
130 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
131 static const WCHAR prop_numlogicalprocessorsW
[] =
132 {'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};
133 static const WCHAR prop_numprocessorsW
[] =
134 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
135 static const WCHAR prop_osarchitectureW
[] =
136 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
137 static const WCHAR prop_oslanguageW
[] =
138 {'O','S','L','a','n','g','u','a','g','e',0};
139 static const WCHAR prop_parameterW
[] =
140 {'P','a','r','a','m','e','t','e','r',0};
141 static const WCHAR prop_pnpdeviceidW
[] =
142 {'P','N','P','D','e','v','i','c','e','I','D',0};
143 static const WCHAR prop_pprocessidW
[] =
144 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
145 static const WCHAR prop_processidW
[] =
146 {'P','r','o','c','e','s','s','I','D',0};
147 static const WCHAR prop_processoridW
[] =
148 {'P','r','o','c','e','s','s','o','r','I','d',0};
149 static const WCHAR prop_releasedateW
[] =
150 {'R','e','l','e','a','s','e','D','a','t','e',0};
151 static const WCHAR prop_serialnumberW
[] =
152 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
153 static const WCHAR prop_servicetypeW
[] =
154 {'S','e','r','v','i','c','e','T','y','p','e',0};
155 static const WCHAR prop_startmodeW
[] =
156 {'S','t','a','r','t','M','o','d','e',0};
157 static const WCHAR prop_sizeW
[] =
159 static const WCHAR prop_speedW
[] =
160 {'S','p','e','e','d',0};
161 static const WCHAR prop_stateW
[] =
162 {'S','t','a','t','e',0};
163 static const WCHAR prop_systemdirectoryW
[] =
164 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
165 static const WCHAR prop_systemnameW
[] =
166 {'S','y','s','t','e','m','N','a','m','e',0};
167 static const WCHAR prop_tagW
[] =
169 static const WCHAR prop_threadcountW
[] =
170 {'T','h','r','e','a','d','C','o','u','n','t',0};
171 static const WCHAR prop_totalphysicalmemoryW
[] =
172 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
173 static const WCHAR prop_typeW
[] =
176 static const WCHAR method_enumkeyW
[] =
177 {'E','n','u','m','K','e','y',0};
178 static const WCHAR method_enumvaluesW
[] =
179 {'E','n','u','m','V','a','l','u','e','s',0};
181 static const WCHAR param_defkeyW
[] =
182 {'h','D','e','f','K','e','y',0};
183 static const WCHAR param_namesW
[] =
184 {'N','a','m','e','s',0};
185 static const WCHAR param_returnvalueW
[] =
186 {'R','e','t','u','r','n','V','a','l','u','e',0};
187 static const WCHAR param_subkeynameW
[] =
188 {'s','S','u','b','K','e','y','N','a','m','e',0};
189 static const WCHAR param_typesW
[] =
190 {'T','y','p','e','s',0};
192 /* column definitions must be kept in sync with record structures below */
193 static const struct column col_baseboard
[] =
195 { prop_manufacturerW
, CIM_STRING
},
196 { prop_serialnumberW
, CIM_STRING
},
197 { prop_tagW
, CIM_STRING
|COL_FLAG_KEY
}
199 static const struct column col_bios
[] =
201 { prop_descriptionW
, CIM_STRING
},
202 { prop_manufacturerW
, CIM_STRING
},
203 { prop_releasedateW
, CIM_DATETIME
},
204 { prop_serialnumberW
, CIM_STRING
}
206 static const struct column col_compsys
[] =
208 { prop_descriptionW
, CIM_STRING
},
209 { prop_domainroleW
, CIM_UINT16
},
210 { prop_manufacturerW
, CIM_STRING
},
211 { prop_modelW
, CIM_STRING
},
212 { prop_numlogicalprocessorsW
, CIM_UINT32
, VT_I4
},
213 { prop_numprocessorsW
, CIM_UINT32
, VT_I4
},
214 { prop_totalphysicalmemoryW
, CIM_UINT64
}
216 static const struct column col_logicaldisk
[] =
218 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
219 { prop_drivetypeW
, CIM_UINT32
, VT_I4
},
220 { prop_filesystemW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
221 { prop_freespaceW
, CIM_UINT64
},
222 { prop_sizeW
, CIM_UINT64
}
224 static const struct column col_networkadapter
[] =
226 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
227 { prop_interfaceindexW
, CIM_UINT32
, VT_I4
},
228 { prop_macaddressW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
229 { prop_netconnectionstatusW
, CIM_UINT16
, VT_I4
},
230 { prop_pnpdeviceidW
, CIM_STRING
},
231 { prop_speedW
, CIM_UINT64
}
233 static const struct column col_os
[] =
235 { prop_captionW
, CIM_STRING
},
236 { prop_csdversionW
, CIM_STRING
},
237 { prop_lastbootuptimeW
, CIM_DATETIME
|COL_FLAG_DYNAMIC
},
238 { prop_osarchitectureW
, CIM_STRING
},
239 { prop_oslanguageW
, CIM_UINT32
, VT_I4
},
240 { prop_systemdirectoryW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
242 static const struct column col_params
[] =
244 { prop_classW
, CIM_STRING
},
245 { prop_methodW
, CIM_STRING
},
246 { prop_directionW
, CIM_SINT32
},
247 { prop_parameterW
, CIM_STRING
},
248 { prop_typeW
, CIM_UINT32
},
249 { prop_defaultvalueW
, CIM_UINT32
}
251 static const struct column col_process
[] =
253 { prop_captionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
254 { prop_commandlineW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
255 { prop_descriptionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
256 { prop_handleW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
257 { prop_pprocessidW
, CIM_UINT32
, VT_I4
},
258 { prop_processidW
, CIM_UINT32
, VT_I4
},
259 { prop_threadcountW
, CIM_UINT32
, VT_I4
}
261 static const struct column col_processor
[] =
263 { prop_cpustatusW
, CIM_UINT16
},
264 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
265 { prop_manufacturerW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
266 { prop_maxclockspeedW
, CIM_UINT32
, VT_I4
},
267 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
268 { prop_numlogicalprocessorsW
, CIM_UINT32
, VT_I4
},
269 { prop_processoridW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
271 static const struct column col_service
[] =
273 { prop_acceptpauseW
, CIM_BOOLEAN
},
274 { prop_acceptstopW
, CIM_BOOLEAN
},
275 { prop_displaynameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
276 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
277 { prop_processidW
, CIM_UINT32
},
278 { prop_servicetypeW
, CIM_STRING
},
279 { prop_startmodeW
, CIM_STRING
},
280 { prop_stateW
, CIM_STRING
},
281 { prop_systemnameW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
283 static const struct column col_stdregprov
[] =
285 { method_enumkeyW
, CIM_OBJECT
|COL_FLAG_METHOD
},
286 { method_enumvaluesW
, CIM_OBJECT
|COL_FLAG_METHOD
}
288 static const struct column col_videocontroller
[] =
290 { prop_adapterramW
, CIM_UINT32
},
291 { prop_currentbitsperpixelW
, CIM_UINT32
},
292 { prop_currenthorizontalresW
, CIM_UINT32
},
293 { prop_currentverticalresW
, CIM_UINT32
},
294 { prop_descriptionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
295 { prop_deviceidW
, CIM_STRING
|COL_FLAG_KEY
},
296 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
299 static const WCHAR baseboard_manufacturerW
[] =
300 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
301 static const WCHAR baseboard_serialnumberW
[] =
303 static const WCHAR baseboard_tagW
[] =
304 {'B','a','s','e',' ','B','o','a','r','d',0};
305 static const WCHAR bios_descriptionW
[] =
306 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
307 static const WCHAR bios_manufacturerW
[] =
308 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
309 static const WCHAR bios_releasedateW
[] =
310 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
311 static const WCHAR bios_serialnumberW
[] =
313 static const WCHAR compsys_descriptionW
[] =
314 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
315 static const WCHAR compsys_manufacturerW
[] =
316 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
317 static const WCHAR compsys_modelW
[] =
319 static const WCHAR networkadapter_pnpdeviceidW
[]=
320 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
321 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
322 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
323 static const WCHAR os_captionW
[] =
324 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
325 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
326 static const WCHAR os_csdversionW
[] =
327 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
328 static const WCHAR os_32bitW
[] =
329 {'3','2','-','b','i','t',0};
330 static const WCHAR os_64bitW
[] =
331 {'6','4','-','b','i','t',0};
332 static const WCHAR videocontroller_deviceidW
[] =
333 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
335 #include "pshpack1.h"
336 struct record_baseboard
338 const WCHAR
*manufacturer
;
339 const WCHAR
*serialnumber
;
344 const WCHAR
*description
;
345 const WCHAR
*manufacturer
;
346 const WCHAR
*releasedate
;
347 const WCHAR
*serialnumber
;
349 struct record_computersystem
351 const WCHAR
*description
;
353 const WCHAR
*manufacturer
;
355 UINT32 num_logical_processors
;
356 UINT32 num_processors
;
357 UINT64 total_physical_memory
;
359 struct record_logicaldisk
361 const WCHAR
*device_id
;
363 const WCHAR
*filesystem
;
367 struct record_networkadapter
369 const WCHAR
*device_id
;
370 INT32 interface_index
;
371 const WCHAR
*mac_address
;
372 UINT16 netconnection_status
;
373 const WCHAR
*pnpdevice_id
;
376 struct record_operatingsystem
378 const WCHAR
*caption
;
379 const WCHAR
*csdversion
;
380 const WCHAR
*lastbootuptime
;
381 const WCHAR
*osarchitecture
;
383 const WCHAR
*systemdirectory
;
390 const WCHAR
*parameter
;
394 struct record_process
396 const WCHAR
*caption
;
397 const WCHAR
*commandline
;
398 const WCHAR
*description
;
404 struct record_processor
407 const WCHAR
*device_id
;
408 const WCHAR
*manufacturer
;
409 UINT32 maxclockspeed
;
411 UINT32 num_logical_processors
;
412 const WCHAR
*processor_id
;
414 struct record_service
418 const WCHAR
*displayname
;
421 const WCHAR
*servicetype
;
422 const WCHAR
*startmode
;
424 const WCHAR
*systemname
;
426 struct record_stdregprov
428 class_method
*enumkey
;
429 class_method
*enumvalues
;
431 struct record_videocontroller
434 UINT32 current_bitsperpixel
;
435 UINT32 current_horizontalres
;
436 UINT32 current_verticalres
;
437 const WCHAR
*description
;
438 const WCHAR
*device_id
;
443 static HRESULT
reg_enumkey( IWbemClassObject
*in
, IWbemClassObject
**out
)
448 static HRESULT
reg_enumvalues( IWbemClassObject
*in
, IWbemClassObject
**out
)
454 static const struct record_baseboard data_baseboard
[] =
456 { baseboard_manufacturerW
, baseboard_serialnumberW
, baseboard_tagW
}
458 static const struct record_bios data_bios
[] =
460 { bios_descriptionW
, bios_manufacturerW
, bios_releasedateW
, bios_serialnumberW
}
462 static const struct record_params data_params
[] =
464 { class_stdregprovW
, method_enumkeyW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
465 { class_stdregprovW
, method_enumkeyW
, 1, param_subkeynameW
, CIM_STRING
},
466 { class_stdregprovW
, method_enumkeyW
, -1, param_returnvalueW
, CIM_UINT32
},
467 { class_stdregprovW
, method_enumkeyW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
468 { class_stdregprovW
, method_enumvaluesW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
469 { class_stdregprovW
, method_enumvaluesW
, 1, param_subkeynameW
, CIM_STRING
},
470 { class_stdregprovW
, method_enumvaluesW
, -1, param_returnvalueW
, CIM_UINT32
},
471 { class_stdregprovW
, method_enumvaluesW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
472 { class_stdregprovW
, method_enumvaluesW
, -1, param_typesW
, CIM_SINT32
|CIM_FLAG_ARRAY
}
474 static const struct record_stdregprov data_stdregprov
[] =
476 { reg_enumkey
, reg_enumvalues
}
479 static UINT
get_processor_count(void)
481 SYSTEM_BASIC_INFORMATION info
;
483 if (NtQuerySystemInformation( SystemBasicInformation
, &info
, sizeof(info
), NULL
)) return 1;
484 return info
.NumberOfProcessors
;
487 static UINT
get_logical_processor_count(void)
489 SYSTEM_LOGICAL_PROCESSOR_INFORMATION
*info
;
490 UINT i
, j
, count
= 0;
494 status
= NtQuerySystemInformation( SystemLogicalProcessorInformation
, NULL
, 0, &len
);
495 if (status
!= STATUS_INFO_LENGTH_MISMATCH
) return get_processor_count();
497 if (!(info
= heap_alloc( len
))) return get_processor_count();
498 status
= NtQuerySystemInformation( SystemLogicalProcessorInformation
, info
, len
, &len
);
499 if (status
!= STATUS_SUCCESS
)
502 return get_processor_count();
504 for (i
= 0; i
< len
/ sizeof(*info
); i
++)
506 if (info
[i
].Relationship
!= RelationProcessorCore
) continue;
507 for (j
= 0; j
< sizeof(ULONG_PTR
); j
++) if (info
[i
].ProcessorMask
& (1 << j
)) count
++;
513 static UINT64
get_total_physical_memory(void)
515 MEMORYSTATUSEX status
;
517 status
.dwLength
= sizeof(status
);
518 if (!GlobalMemoryStatusEx( &status
)) return 1024 * 1024 * 1024;
519 return status
.ullTotalPhys
;
522 static void fill_compsys( struct table
*table
)
524 struct record_computersystem
*rec
;
526 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
528 rec
= (struct record_computersystem
*)table
->data
;
529 rec
->description
= compsys_descriptionW
;
530 rec
->domainrole
= 0; /* standalone workstation */
531 rec
->manufacturer
= compsys_manufacturerW
;
532 rec
->model
= compsys_modelW
;
533 rec
->num_logical_processors
= get_logical_processor_count();
534 rec
->num_processors
= get_processor_count();
535 rec
->total_physical_memory
= get_total_physical_memory();
537 TRACE("created 1 row\n");
541 static WCHAR
*get_filesystem( const WCHAR
*root
)
543 static const WCHAR ntfsW
[] = {'N','T','F','S',0};
544 WCHAR buffer
[MAX_PATH
+ 1];
546 if (GetVolumeInformationW( root
, NULL
, 0, NULL
, NULL
, NULL
, buffer
, MAX_PATH
+ 1 ))
547 return heap_strdupW( buffer
);
548 return heap_strdupW( ntfsW
);
551 static UINT64
get_freespace( const WCHAR
*dir
, UINT64
*disksize
)
553 WCHAR root
[] = {'\\','\\','.','\\','A',':',0};
555 DISK_GEOMETRY_EX info
;
558 free
.QuadPart
= 512 * 1024 * 1024;
559 GetDiskFreeSpaceExW( dir
, NULL
, NULL
, &free
);
562 handle
= CreateFileW( root
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
563 if (handle
!= INVALID_HANDLE_VALUE
)
565 if (DeviceIoControl( handle
, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
))
566 *disksize
= info
.DiskSize
.QuadPart
;
567 CloseHandle( handle
);
569 return free
.QuadPart
;
572 static void fill_logicaldisk( struct table
*table
)
574 static const WCHAR fmtW
[] = {'%','c',':',0};
575 WCHAR device_id
[3], root
[] = {'A',':','\\',0};
576 struct record_logicaldisk
*rec
;
577 UINT i
, num_rows
= 0, offset
= 0, count
= 4, type
;
578 UINT64 size
= 1024 * 1024 * 1024;
579 DWORD drives
= GetLogicalDrives();
581 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) return;
583 for (i
= 0; i
< sizeof(drives
); i
++)
585 if (drives
& (1 << i
))
588 type
= GetDriveTypeW( root
);
589 if (type
!= DRIVE_FIXED
&& type
!= DRIVE_CDROM
&& type
!= DRIVE_REMOVABLE
)
592 if (num_rows
> count
)
596 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) return;
599 rec
= (struct record_logicaldisk
*)(table
->data
+ offset
);
600 sprintfW( device_id
, fmtW
, 'A' + i
);
601 rec
->device_id
= heap_strdupW( device_id
);
602 rec
->drivetype
= type
;
603 rec
->filesystem
= get_filesystem( root
);
604 rec
->freespace
= get_freespace( root
, &size
);
606 offset
+= sizeof(*rec
);
610 TRACE("created %u rows\n", num_rows
);
611 table
->num_rows
= num_rows
;
614 static UINT16
get_connection_status( IF_OPER_STATUS status
)
618 case IfOperStatusDown
:
619 return 0; /* Disconnected */
621 return 2; /* Connected */
623 ERR("unhandled status %u\n", status
);
628 static WCHAR
*get_mac_address( const BYTE
*addr
, DWORD len
)
630 static const WCHAR fmtW
[] =
631 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
632 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
635 if (len
!= 6 || !(ret
= heap_alloc( 18 * sizeof(WCHAR
) ))) return NULL
;
636 sprintfW( ret
, fmtW
, addr
[0], addr
[1], addr
[2], addr
[3], addr
[4], addr
[5] );
640 static void fill_networkadapter( struct table
*table
)
642 static const WCHAR fmtW
[] = {'%','u',0};
644 struct record_networkadapter
*rec
;
645 IP_ADAPTER_ADDRESSES
*aa
, *buffer
;
646 UINT num_rows
= 0, offset
= 0;
649 ret
= GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, NULL
, &size
);
650 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
652 if (!(buffer
= heap_alloc( size
))) return;
653 if (GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, buffer
, &size
))
658 for (aa
= buffer
; aa
; aa
= aa
->Next
) num_rows
++;
659 if (!(table
->data
= heap_alloc( sizeof(*rec
) * num_rows
)))
664 for (aa
= buffer
; aa
; aa
= aa
->Next
)
666 rec
= (struct record_networkadapter
*)(table
->data
+ offset
);
667 sprintfW( device_id
, fmtW
, aa
->u
.s
.IfIndex
);
668 rec
->device_id
= heap_strdupW( device_id
);
669 rec
->interface_index
= aa
->u
.s
.IfIndex
;
670 rec
->mac_address
= get_mac_address( aa
->PhysicalAddress
, aa
->PhysicalAddressLength
);
671 rec
->netconnection_status
= get_connection_status( aa
->OperStatus
);
672 rec
->pnpdevice_id
= networkadapter_pnpdeviceidW
;
673 rec
->speed
= 1000000;
674 offset
+= sizeof(*rec
);
676 TRACE("created %u rows\n", num_rows
);
677 table
->num_rows
= num_rows
;
682 static WCHAR
*get_cmdline( DWORD process_id
)
684 if (process_id
== GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
685 return NULL
; /* FIXME handle different process case */
688 static void fill_process( struct table
*table
)
690 static const WCHAR fmtW
[] = {'%','u',0};
692 struct record_process
*rec
;
693 PROCESSENTRY32W entry
;
695 UINT num_rows
= 0, offset
= 0, count
= 8;
697 snap
= CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
698 if (snap
== INVALID_HANDLE_VALUE
) return;
700 entry
.dwSize
= sizeof(entry
);
701 if (!Process32FirstW( snap
, &entry
)) goto done
;
702 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) goto done
;
706 if (num_rows
> count
)
710 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) goto done
;
713 rec
= (struct record_process
*)(table
->data
+ offset
);
714 rec
->caption
= heap_strdupW( entry
.szExeFile
);
715 rec
->commandline
= get_cmdline( entry
.th32ProcessID
);
716 rec
->description
= heap_strdupW( entry
.szExeFile
);
717 sprintfW( handle
, fmtW
, entry
.th32ProcessID
);
718 rec
->handle
= heap_strdupW( handle
);
719 rec
->process_id
= entry
.th32ProcessID
;
720 rec
->pprocess_id
= entry
.th32ParentProcessID
;
721 rec
->thread_count
= entry
.cntThreads
;
722 offset
+= sizeof(*rec
);
724 } while (Process32NextW( snap
, &entry
));
726 TRACE("created %u rows\n", num_rows
);
727 table
->num_rows
= num_rows
;
733 static inline void do_cpuid( unsigned int ax
, unsigned int *p
)
736 __asm__("pushl %%ebx\n\t"
738 "movl %%ebx, %%esi\n\t"
740 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
745 static void get_processor_id( WCHAR
*processor_id
)
747 static const WCHAR fmtW
[] = {'%','0','8','X','%','0','8','X',0};
748 unsigned int regs
[4] = {0, 0, 0, 0};
751 sprintfW( processor_id
, fmtW
, regs
[3], regs
[0] );
753 static void regs_to_str( unsigned int *regs
, unsigned int len
, WCHAR
*buffer
)
756 unsigned char *p
= (unsigned char *)regs
;
758 for (i
= 0; i
< len
; i
++)
764 static void get_processor_manufacturer( WCHAR
*manufacturer
)
766 unsigned int tmp
, regs
[4] = {0, 0, 0, 0};
769 tmp
= regs
[2]; /* swap edx and ecx */
773 regs_to_str( regs
+ 1, 12, manufacturer
);
775 static void get_processor_name( WCHAR
*name
)
777 unsigned int regs
[4] = {0, 0, 0, 0};
779 do_cpuid( 0x80000000, regs
);
780 if (regs
[0] >= 0x80000004)
782 do_cpuid( 0x80000002, regs
);
783 regs_to_str( regs
, 16, name
);
784 do_cpuid( 0x80000003, regs
);
785 regs_to_str( regs
, 16, name
+ 16 );
786 do_cpuid( 0x80000004, regs
);
787 regs_to_str( regs
, 16, name
+ 32 );
790 static UINT
get_processor_maxclockspeed( void )
792 PROCESSOR_POWER_INFORMATION
*info
;
793 UINT ret
= 1000, size
= get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION
);
796 if ((info
= heap_alloc( size
)))
798 status
= NtPowerInformation( ProcessorInformation
, NULL
, 0, info
, size
);
799 if (!status
) ret
= info
[0].MaxMhz
;
805 static void fill_processor( struct table
*table
)
807 static const WCHAR fmtW
[] = {'C','P','U','%','u',0};
808 WCHAR device_id
[14], processor_id
[17], manufacturer
[13], name
[49] = {0};
809 struct record_processor
*rec
;
810 UINT i
, offset
= 0, maxclockspeed
, num_logical_processors
, count
= get_processor_count();
812 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) return;
814 get_processor_id( processor_id
);
815 get_processor_manufacturer( manufacturer
);
816 get_processor_name( name
);
818 maxclockspeed
= get_processor_maxclockspeed();
819 num_logical_processors
= get_logical_processor_count() / count
;
821 for (i
= 0; i
< count
; i
++)
823 rec
= (struct record_processor
*)(table
->data
+ offset
);
824 rec
->cpu_status
= 1; /* CPU Enabled */
825 sprintfW( device_id
, fmtW
, i
);
826 rec
->device_id
= heap_strdupW( device_id
);
827 rec
->manufacturer
= heap_strdupW( manufacturer
);
828 rec
->maxclockspeed
= maxclockspeed
;
829 rec
->name
= heap_strdupW( name
);
830 rec
->num_logical_processors
= num_logical_processors
;
831 rec
->processor_id
= heap_strdupW( processor_id
);
832 offset
+= sizeof(*rec
);
835 TRACE("created %u rows\n", count
);
836 table
->num_rows
= count
;
839 static WCHAR
*get_lastbootuptime(void)
841 static const WCHAR fmtW
[] =
842 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
843 '.','%','0','6','u','+','0','0','0',0};
846 ULARGE_INTEGER ticks
;
849 if (!(ret
= heap_alloc( 26 * sizeof(WCHAR
) ))) return NULL
;
850 GetSystemTime( &st
);
851 SystemTimeToFileTime( &st
, &ft
);
852 ticks
.u
.LowPart
= ft
.dwLowDateTime
;
853 ticks
.u
.HighPart
= ft
.dwHighDateTime
;
854 ticks
.QuadPart
-= GetTickCount64() * 10000;
855 ft
.dwLowDateTime
= ticks
.u
.LowPart
;
856 ft
.dwHighDateTime
= ticks
.u
.HighPart
;
857 FileTimeToSystemTime( &ft
, &st
);
858 sprintfW( ret
, fmtW
, st
.wYear
, st
.wMonth
, st
.wDay
, st
.wHour
, st
.wMinute
, st
.wSecond
, st
.wMilliseconds
* 1000 );
861 static const WCHAR
*get_osarchitecture(void)
864 GetNativeSystemInfo( &info
);
865 if (info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
) return os_64bitW
;
868 static WCHAR
*get_systemdirectory(void)
873 if (!(ret
= heap_alloc( MAX_PATH
* sizeof(WCHAR
) ))) return NULL
;
874 Wow64DisableWow64FsRedirection( &redir
);
875 GetSystemDirectoryW( ret
, MAX_PATH
);
876 Wow64RevertWow64FsRedirection( redir
);
880 static void fill_os( struct table
*table
)
882 struct record_operatingsystem
*rec
;
884 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
886 rec
= (struct record_operatingsystem
*)table
->data
;
887 rec
->caption
= os_captionW
;
888 rec
->csdversion
= os_csdversionW
;
889 rec
->lastbootuptime
= get_lastbootuptime();
890 rec
->osarchitecture
= get_osarchitecture();
891 rec
->oslanguage
= MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
892 rec
->systemdirectory
= get_systemdirectory();
894 TRACE("created 1 row\n");
898 static const WCHAR
*get_service_type( DWORD type
)
900 static const WCHAR filesystem_driverW
[] =
901 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
902 static const WCHAR kernel_driverW
[] =
903 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
904 static const WCHAR own_processW
[] =
905 {'O','w','n',' ','P','r','o','c','e','s','s',0};
906 static const WCHAR share_processW
[] =
907 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
909 if (type
& SERVICE_KERNEL_DRIVER
) return kernel_driverW
;
910 else if (type
& SERVICE_FILE_SYSTEM_DRIVER
) return filesystem_driverW
;
911 else if (type
& SERVICE_WIN32_OWN_PROCESS
) return own_processW
;
912 else if (type
& SERVICE_WIN32_SHARE_PROCESS
) return share_processW
;
913 else ERR("unhandled type 0x%08x\n", type
);
916 static const WCHAR
*get_service_state( DWORD state
)
918 static const WCHAR runningW
[] =
919 {'R','u','n','n','i','n','g',0};
920 static const WCHAR start_pendingW
[] =
921 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
922 static const WCHAR stop_pendingW
[] =
923 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
924 static const WCHAR stoppedW
[] =
925 {'S','t','o','p','p','e','d',0};
926 static const WCHAR unknownW
[] =
927 {'U','n','k','n','o','w','n',0};
931 case SERVICE_STOPPED
: return stoppedW
;
932 case SERVICE_START_PENDING
: return start_pendingW
;
933 case SERVICE_STOP_PENDING
: return stop_pendingW
;
934 case SERVICE_RUNNING
: return runningW
;
936 ERR("unknown state %u\n", state
);
941 static const WCHAR
*get_service_startmode( DWORD mode
)
943 static const WCHAR bootW
[] = {'B','o','o','t',0};
944 static const WCHAR systemW
[] = {'S','y','s','t','e','m',0};
945 static const WCHAR autoW
[] = {'A','u','t','o',0};
946 static const WCHAR manualW
[] = {'M','a','n','u','a','l',0};
947 static const WCHAR disabledW
[] = {'D','i','s','a','b','l','e','d',0};
948 static const WCHAR unknownW
[] = {'U','n','k','n','o','w','n',0};
952 case SERVICE_BOOT_START
: return bootW
;
953 case SERVICE_SYSTEM_START
: return systemW
;
954 case SERVICE_AUTO_START
: return autoW
;
955 case SERVICE_DEMAND_START
: return manualW
;
956 case SERVICE_DISABLED
: return disabledW
;
958 ERR("unknown mode 0x%x\n", mode
);
963 static QUERY_SERVICE_CONFIGW
*query_service_config( SC_HANDLE manager
, const WCHAR
*name
)
965 QUERY_SERVICE_CONFIGW
*config
= NULL
;
969 if (!(service
= OpenServiceW( manager
, name
, SERVICE_QUERY_CONFIG
))) return NULL
;
970 QueryServiceConfigW( service
, NULL
, 0, &size
);
971 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) goto done
;
972 if (!(config
= heap_alloc( size
))) goto done
;
973 if (QueryServiceConfigW( service
, config
, size
, &size
)) goto done
;
978 CloseServiceHandle( service
);
982 static void fill_service( struct table
*table
)
984 struct record_service
*rec
;
986 ENUM_SERVICE_STATUS_PROCESSW
*tmp
, *services
= NULL
;
987 SERVICE_STATUS_PROCESS
*status
;
988 WCHAR sysnameW
[MAX_COMPUTERNAME_LENGTH
+ 1];
989 DWORD len
= sizeof(sysnameW
) / sizeof(sysnameW
[0]);
990 UINT i
, num_rows
= 0, offset
= 0, size
= 256, needed
, count
;
993 if (!(manager
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
))) return;
994 if (!(services
= heap_alloc( size
))) goto done
;
996 ret
= EnumServicesStatusExW( manager
, SC_ENUM_PROCESS_INFO
, SERVICE_TYPE_ALL
,
997 SERVICE_STATE_ALL
, (BYTE
*)services
, size
, &needed
,
998 &count
, NULL
, NULL
);
1001 if (GetLastError() != ERROR_MORE_DATA
) goto done
;
1003 if (!(tmp
= heap_realloc( services
, size
))) goto done
;
1005 ret
= EnumServicesStatusExW( manager
, SC_ENUM_PROCESS_INFO
, SERVICE_TYPE_ALL
,
1006 SERVICE_STATE_ALL
, (BYTE
*)services
, size
, &needed
,
1007 &count
, NULL
, NULL
);
1008 if (!ret
) goto done
;
1010 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) goto done
;
1012 GetComputerNameW( sysnameW
, &len
);
1014 for (i
= 0; i
< count
; i
++)
1016 QUERY_SERVICE_CONFIGW
*config
;
1018 if (!(config
= query_service_config( manager
, services
[i
].lpServiceName
))) continue;
1020 status
= &services
[i
].ServiceStatusProcess
;
1021 rec
= (struct record_service
*)(table
->data
+ offset
);
1022 rec
->accept_pause
= (status
->dwControlsAccepted
& SERVICE_ACCEPT_PAUSE_CONTINUE
) ? -1 : 0;
1023 rec
->accept_stop
= (status
->dwControlsAccepted
& SERVICE_ACCEPT_STOP
) ? -1 : 0;
1024 rec
->displayname
= heap_strdupW( services
[i
].lpDisplayName
);
1025 rec
->name
= heap_strdupW( services
[i
].lpServiceName
);
1026 rec
->process_id
= status
->dwProcessId
;
1027 rec
->servicetype
= get_service_type( status
->dwServiceType
);
1028 rec
->startmode
= get_service_startmode( config
->dwStartType
);
1029 rec
->state
= get_service_state( status
->dwCurrentState
);
1030 rec
->systemname
= heap_strdupW( sysnameW
);
1031 heap_free( config
);
1032 offset
+= sizeof(*rec
);
1036 TRACE("created %u rows\n", num_rows
);
1037 table
->num_rows
= num_rows
;
1040 CloseServiceHandle( manager
);
1041 heap_free( services
);
1044 static UINT32
get_bits_per_pixel( UINT
*hres
, UINT
*vres
)
1046 HDC hdc
= GetDC( NULL
);
1049 if (!hdc
) return 32;
1050 ret
= GetDeviceCaps( hdc
, BITSPIXEL
);
1051 *hres
= GetDeviceCaps( hdc
, HORZRES
);
1052 *vres
= GetDeviceCaps( hdc
, VERTRES
);
1053 ReleaseDC( NULL
, hdc
);
1057 static void fill_videocontroller( struct table
*table
)
1060 struct record_videocontroller
*rec
;
1062 IDXGIFactory
*factory
= NULL
;
1063 IDXGIAdapter
*adapter
= NULL
;
1064 DXGI_ADAPTER_DESC desc
;
1065 UINT hres
= 1024, vres
= 768, vidmem
= 512 * 1024 * 1024;
1066 const WCHAR
*name
= videocontroller_deviceidW
;
1068 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
1070 hr
= CreateDXGIFactory( &IID_IDXGIFactory
, (void **)&factory
);
1071 if (FAILED(hr
)) goto done
;
1073 hr
= IDXGIFactory_EnumAdapters( factory
, 0, &adapter
);
1074 if (FAILED(hr
)) goto done
;
1076 hr
= IDXGIAdapter_GetDesc( adapter
, &desc
);
1079 vidmem
= desc
.DedicatedVideoMemory
;
1080 name
= desc
.Description
;
1084 rec
= (struct record_videocontroller
*)table
->data
;
1085 rec
->adapter_ram
= vidmem
;
1086 rec
->current_bitsperpixel
= get_bits_per_pixel( &hres
, &vres
);
1087 rec
->current_horizontalres
= hres
;
1088 rec
->current_verticalres
= vres
;
1089 rec
->description
= heap_strdupW( name
);
1090 rec
->device_id
= videocontroller_deviceidW
;
1091 rec
->name
= heap_strdupW( name
);
1093 TRACE("created 1 row\n");
1094 table
->num_rows
= 1;
1096 if (adapter
) IDXGIAdapter_Release( adapter
);
1097 if (factory
) IDXGIFactory_Release( factory
);
1100 static struct table builtin_classes
[] =
1102 { class_baseboardW
, SIZEOF(col_baseboard
), col_baseboard
, SIZEOF(data_baseboard
), (BYTE
*)data_baseboard
},
1103 { class_biosW
, SIZEOF(col_bios
), col_bios
, SIZEOF(data_bios
), (BYTE
*)data_bios
},
1104 { class_compsysW
, SIZEOF(col_compsys
), col_compsys
, 0, NULL
, fill_compsys
},
1105 { class_logicaldiskW
, SIZEOF(col_logicaldisk
), col_logicaldisk
, 0, NULL
, fill_logicaldisk
},
1106 { class_networkadapterW
, SIZEOF(col_networkadapter
), col_networkadapter
, 0, NULL
, fill_networkadapter
},
1107 { class_osW
, SIZEOF(col_os
), col_os
, 0, NULL
, fill_os
},
1108 { class_paramsW
, SIZEOF(col_params
), col_params
, SIZEOF(data_params
), (BYTE
*)data_params
},
1109 { class_processW
, SIZEOF(col_process
), col_process
, 0, NULL
, fill_process
},
1110 { class_processorW
, SIZEOF(col_processor
), col_processor
, 0, NULL
, fill_processor
},
1111 { class_serviceW
, SIZEOF(col_service
), col_service
, 0, NULL
, fill_service
},
1112 { class_stdregprovW
, SIZEOF(col_stdregprov
), col_stdregprov
, SIZEOF(data_stdregprov
), (BYTE
*)data_stdregprov
},
1113 { class_videocontrollerW
, SIZEOF(col_videocontroller
), col_videocontroller
, 0, NULL
, fill_videocontroller
}
1116 void init_table_list( void )
1118 static struct list tables
= LIST_INIT( tables
);
1121 for (i
= 0; i
< SIZEOF(builtin_classes
); i
++)
1123 list_add_tail( &tables
, &builtin_classes
[i
].entry
);
1125 table_list
= &tables
;