ntoskrnl.exe: Implement ExAcquireFastMutex and ExReleaseFastMutex.
[wine.git] / dlls / wbemprox / builtin.c
blob6c56d0d70aefba1de01b84d60d10a679bacd2811
1 /*
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
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
25 #include <fcntl.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #ifdef HAVE_ARPA_INET_H
30 # include <arpa/inet.h>
31 #endif
33 #include "ntstatus.h"
34 #define WIN32_NO_STATUS
35 #include "windef.h"
36 #include "winbase.h"
37 #ifdef __MINGW32__
38 # include "winsock2.h"
39 # include "ws2tcpip.h"
40 # define WS_AF_INET AF_INET
41 # define WS_AF_UNSPEC AF_UNSPEC
42 # define WS_NI_MAXHOST NI_MAXHOST
43 # define WS_NI_NAMEREQD NI_NAMEREQD
44 #else
45 # define USE_WS_PREFIX
46 # include "winsock2.h"
47 # include "ws2tcpip.h"
48 #endif
49 #include "initguid.h"
50 #include "wbemcli.h"
51 #include "wbemprov.h"
52 #include "iphlpapi.h"
53 #include "netioapi.h"
54 #include "tlhelp32.h"
55 #include "d3d10.h"
56 #include "winternl.h"
57 #include "winioctl.h"
58 #include "winsvc.h"
59 #include "winver.h"
60 #include "sddl.h"
61 #include "ntsecapi.h"
62 #include "winspool.h"
63 #include "setupapi.h"
65 #include "wine/asm.h"
66 #include "wine/debug.h"
67 #include "wbemprox_private.h"
69 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
71 static const WCHAR class_baseboardW[] =
72 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
73 static const WCHAR class_biosW[] =
74 {'W','i','n','3','2','_','B','I','O','S',0};
75 static const WCHAR class_cdromdriveW[] =
76 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
77 static const WCHAR class_compsysW[] =
78 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
79 static const WCHAR class_compsysproductW[] =
80 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
81 static const WCHAR class_datafileW[] =
82 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
83 static const WCHAR class_desktopmonitorW[] =
84 {'W','i','n','3','2','_','D','e','s','k','t','o','p','M','o','n','i','t','o','r',0};
85 static const WCHAR class_directoryW[] =
86 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
87 static const WCHAR class_diskdriveW[] =
88 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
89 static const WCHAR class_diskpartitionW[] =
90 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
91 static const WCHAR class_ip4routetableW[] =
92 {'W','i','n','3','2','_','I','P','4','R','o','u','t','e','T','a','b','l','e',0};
93 static const WCHAR class_logicaldiskW[] =
94 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
95 static const WCHAR class_logicaldisk2W[] =
96 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
97 static const WCHAR class_networkadapterW[] =
98 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
99 static const WCHAR class_networkadapterconfigW[] =
100 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
101 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
102 static const WCHAR class_osW[] =
103 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
104 static const WCHAR class_paramsW[] =
105 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
106 static const WCHAR class_physicalmediaW[] =
107 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
108 static const WCHAR class_physicalmemoryW[] =
109 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
110 static const WCHAR class_pnpentityW[] =
111 {'W','i','n','3','2','_','P','n','P','E','n','t','i','t','y',0};
112 static const WCHAR class_printerW[] =
113 {'W','i','n','3','2','_','P','r','i','n','t','e','r',0};
114 static const WCHAR class_process_getowner_outW[] =
115 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
116 'N','E','R','_','O','U','T',0};
117 static const WCHAR class_processorW[] =
118 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
119 static const WCHAR class_processor2W[] =
120 {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
121 static const WCHAR class_qualifiersW[] =
122 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
123 static const WCHAR class_sidW[] =
124 {'W','i','n','3','2','_','S','I','D',0};
125 static const WCHAR class_sounddeviceW[] =
126 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
127 static const WCHAR class_systemenclosureW[] =
128 {'W','i','n','3','2','_','S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
129 static const WCHAR class_videocontrollerW[] =
130 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
132 static const WCHAR prop_accountnameW[] =
133 {'A','c','c','o','u','n','t','N','a','m','e',0};
134 static const WCHAR prop_acceptpauseW[] =
135 {'A','c','c','e','p','t','P','a','u','s','e',0};
136 static const WCHAR prop_acceptstopW[] =
137 {'A','c','c','e','p','t','S','t','o','p',0};
138 static const WCHAR prop_accessmaskW[] =
139 {'A','c','c','e','s','s','M','a','s','k',0};
140 static const WCHAR prop_adapterdactypeW[] =
141 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
142 static const WCHAR prop_adapterramW[] =
143 {'A','d','a','p','t','e','r','R','A','M',0};
144 static const WCHAR prop_adaptertypeW[] =
145 {'A','d','a','p','t','e','r','T','y','p','e',0};
146 static const WCHAR prop_adaptertypeidW[] =
147 {'A','d','a','p','t','e','r','T','y','p','e','I','D',0};
148 static const WCHAR prop_addresswidthW[] =
149 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
150 static const WCHAR prop_architectureW[] =
151 {'A','r','c','h','i','t','e','c','t','u','r','e',0};
152 static const WCHAR prop_attributesW[] =
153 {'A','t','t','r','i','b','u','t','e','s',0};
154 static const WCHAR prop_availabilityW[] =
155 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
156 static const WCHAR prop_binaryrepresentationW[] =
157 {'B','i','n','a','r','y','R','e','p','r','e','s','e','n','t','a','t','i','o','n',0};
158 static const WCHAR prop_bootableW[] =
159 {'B','o','o','t','a','b','l','e',0};
160 static const WCHAR prop_bootpartitionW[] =
161 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
162 static const WCHAR prop_buildnumberW[] =
163 {'B','u','i','l','d','N','u','m','b','e','r',0};
164 static const WCHAR prop_capacityW[] =
165 {'C','a','p','a','c','i','t','y',0};
166 static const WCHAR prop_captionW[] =
167 {'C','a','p','t','i','o','n',0};
168 static const WCHAR prop_chassistypesW[] =
169 {'C','h','a','s','s','i','s','T','y','p','e','s',0};
170 static const WCHAR prop_classW[] =
171 {'C','l','a','s','s',0};
172 static const WCHAR prop_codesetW[] =
173 {'C','o','d','e','S','e','t',0};
174 static const WCHAR prop_commandlineW[] =
175 {'C','o','m','m','a','n','d','L','i','n','e',0};
176 static const WCHAR prop_configmanagererrorcodeW[] =
177 {'C','o','n','f','i','g','M','a','n','a','g','e','r','E','r','r','o','r','C','o','d','e',0};
178 static const WCHAR prop_countrycodeW[] =
179 {'C','o','u','n','t','r','y','C','o','d','e',0};
180 static const WCHAR prop_cpustatusW[] =
181 {'C','p','u','S','t','a','t','u','s',0};
182 static const WCHAR prop_csdversionW[] =
183 {'C','S','D','V','e','r','s','i','o','n',0};
184 static const WCHAR prop_currentbitsperpixelW[] =
185 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
186 static const WCHAR prop_currentclockspeedW[] =
187 {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
188 static const WCHAR prop_currenthorizontalresW[] =
189 {'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};
190 static const WCHAR prop_currentrefreshrateW[] =
191 {'C','u','r','r','e','n','t','R','e','f','r','e','s','h','R','a','t','e',0};
192 static const WCHAR prop_currentscanmodeW[] =
193 {'C','u','r','r','e','n','t','S','c','a','n','M','o','d','e',0};
194 static const WCHAR prop_currentverticalresW[] =
195 {'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};
196 static const WCHAR prop_datawidthW[] =
197 {'D','a','t','a','W','i','d','t','h',0};
198 static const WCHAR prop_defaultipgatewayW[] =
199 {'D','e','f','a','u','l','t','I','P','G','a','t','e','w','a','y',0};
200 static const WCHAR prop_defaultvalueW[] =
201 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
202 static const WCHAR prop_descriptionW[] =
203 {'D','e','s','c','r','i','p','t','i','o','n',0};
204 static const WCHAR prop_destinationW[] =
205 {'D','e','s','t','i','n','a','t','i','o','n',0};
206 static const WCHAR prop_deviceidW[] =
207 {'D','e','v','i','c','e','I','d',0};
208 static const WCHAR prop_devicelocatorW[] =
209 {'D','e','v','i','c','e','L','o','c','a','t','o','r',0};
210 static const WCHAR prop_dhcpenabledW[] =
211 {'D','H','C','P','E','n','a','b','l','e','d',0};
212 static const WCHAR prop_directionW[] =
213 {'D','i','r','e','c','t','i','o','n',0};
214 static const WCHAR prop_displaynameW[] =
215 {'D','i','s','p','l','a','y','N','a','m','e',0};
216 static const WCHAR prop_diskindexW[] =
217 {'D','i','s','k','I','n','d','e','x',0};
218 static const WCHAR prop_dnshostnameW[] =
219 {'D','N','S','H','o','s','t','N','a','m','e',0};
220 static const WCHAR prop_dnsserversearchorderW[] =
221 {'D','N','S','S','e','r','v','e','r','S','e','a','r','c','h','O','r','d','e','r',0};
222 static const WCHAR prop_domainW[] =
223 {'D','o','m','a','i','n',0};
224 static const WCHAR prop_domainroleW[] =
225 {'D','o','m','a','i','n','R','o','l','e',0};
226 static const WCHAR prop_driveW[] =
227 {'D','r','i','v','e',0};
228 static const WCHAR prop_driverdateW[] =
229 {'D','r','i','v','e','r','D','a','t','e',0};
230 static const WCHAR prop_drivernameW[] =
231 {'D','r','i','v','e','r','N','a','m','e',0};
232 static const WCHAR prop_driverversionW[] =
233 {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
234 static const WCHAR prop_drivetypeW[] =
235 {'D','r','i','v','e','T','y','p','e',0};
236 static const WCHAR prop_familyW[] =
237 {'F','a','m','i','l','y',0};
238 static const WCHAR prop_filesystemW[] =
239 {'F','i','l','e','S','y','s','t','e','m',0};
240 static const WCHAR prop_flavorW[] =
241 {'F','l','a','v','o','r',0};
242 static const WCHAR prop_freespaceW[] =
243 {'F','r','e','e','S','p','a','c','e',0};
244 static const WCHAR prop_freephysicalmemoryW[] =
245 {'F','r','e','e','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
246 static const WCHAR prop_handleW[] =
247 {'H','a','n','d','l','e',0};
248 static const WCHAR prop_horizontalresolutionW[] =
249 {'H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
250 static const WCHAR prop_idW[] =
251 {'I','D',0};
252 static const WCHAR prop_identificationcodeW[] =
253 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
254 static const WCHAR prop_identifyingnumberW[] =
255 {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
256 static const WCHAR prop_indexW[] =
257 {'I','n','d','e','x',0};
258 static const WCHAR prop_installdateW[] =
259 {'I','n','s','t','a','l','l','D','a','t','e',0};
260 static const WCHAR prop_installeddisplaydriversW[]=
261 {'I','n','s','t','a','l','l','e','d','D','i','s','p','l','a','y','D','r','i','v','e','r','s',0};
262 static const WCHAR prop_interfaceindexW[] =
263 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
264 static const WCHAR prop_interfacetypeW[] =
265 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
266 static const WCHAR prop_intvalueW[] =
267 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
268 static const WCHAR prop_ipaddressW[] =
269 {'I','P','A','d','d','r','e','s','s',0};
270 static const WCHAR prop_ipconnectionmetricW[] =
271 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
272 static const WCHAR prop_ipenabledW[] =
273 {'I','P','E','n','a','b','l','e','d',0};
274 static const WCHAR prop_ipsubnet[] =
275 {'I','P','S','u','b','n','e','t',0};
276 static const WCHAR prop_lastbootuptimeW[] =
277 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
278 static const WCHAR prop_levelW[] =
279 {'L','e','v','e','l',0};
280 static const WCHAR prop_localW[] =
281 {'L','o','c','a','l',0};
282 static const WCHAR prop_localdatetimeW[] =
283 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
284 static const WCHAR prop_localeW[] =
285 {'L','o','c','a','l','e',0};
286 static const WCHAR prop_locationW[] =
287 {'L','o','c','a','t','i','o','n',0};
288 static const WCHAR prop_lockpresentW[] =
289 {'L','o','c','k','P','r','e','s','e','n','t',0};
290 static const WCHAR prop_macaddressW[] =
291 {'M','A','C','A','d','d','r','e','s','s',0};
292 static const WCHAR prop_manufacturerW[] =
293 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
294 static const WCHAR prop_maxclockspeedW[] =
295 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
296 static const WCHAR prop_mediatypeW[] =
297 {'M','e','d','i','a','T','y','p','e',0};
298 static const WCHAR prop_memberW[] =
299 {'M','e','m','b','e','r',0};
300 static const WCHAR prop_memorytypeW[] =
301 {'M','e','m','o','r','y','T','y','p','e',0};
302 static const WCHAR prop_methodW[] =
303 {'M','e','t','h','o','d',0};
304 static const WCHAR prop_modelW[] =
305 {'M','o','d','e','l',0};
306 static const WCHAR prop_netconnectionstatusW[] =
307 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
308 static const WCHAR prop_networkW[] =
309 {'N','e','t','w','o','r','k',0};
310 static const WCHAR prop_nexthopW[] =
311 {'N','e','x','t','H','o','p',0};
312 static const WCHAR prop_numcoresW[] =
313 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
314 static const WCHAR prop_numlogicalprocessorsW[] =
315 {'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};
316 static const WCHAR prop_numprocessorsW[] =
317 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
318 static const WCHAR prop_operatingsystemskuW[] =
319 {'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m','S','K','U',0};
320 static const WCHAR prop_osarchitectureW[] =
321 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
322 static const WCHAR prop_oslanguageW[] =
323 {'O','S','L','a','n','g','u','a','g','e',0};
324 static const WCHAR prop_osproductsuiteW[] =
325 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
326 static const WCHAR prop_ostypeW[] =
327 {'O','S','T','y','p','e',0};
328 static const WCHAR prop_parameterW[] =
329 {'P','a','r','a','m','e','t','e','r',0};
330 static const WCHAR prop_physicaladapterW[] =
331 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
332 static const WCHAR prop_pixelsperxlogicalinchW[] =
333 {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0};
334 static const WCHAR prop_pnpdeviceidW[] =
335 {'P','N','P','D','e','v','i','c','e','I','D',0};
336 static const WCHAR prop_portnameW[] =
337 {'P','o','r','t','N','a','m','e',0};
338 static const WCHAR prop_pprocessidW[] =
339 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
340 static const WCHAR prop_primaryW[] =
341 {'P','r','i','m','a','r','y',0};
342 static const WCHAR prop_processidW[] =
343 {'P','r','o','c','e','s','s','I','D',0};
344 static const WCHAR prop_processoridW[] =
345 {'P','r','o','c','e','s','s','o','r','I','d',0};
346 static const WCHAR prop_processortypeW[] =
347 {'P','r','o','c','e','s','s','o','r','T','y','p','e',0};
348 static const WCHAR prop_productW[] =
349 {'P','r','o','d','u','c','t',0};
350 static const WCHAR prop_productnameW[] =
351 {'P','r','o','d','u','c','t','N','a','m','e',0};
352 static const WCHAR prop_referenceddomainnameW[] =
353 {'R','e','f','e','r','e','n','c','e','d','D','o','m','a','i','n','N','a','m','e',0};
354 static const WCHAR prop_releasedateW[] =
355 {'R','e','l','e','a','s','e','D','a','t','e',0};
356 static const WCHAR prop_revisionW[] =
357 {'R','e','v','i','s','i','o','n',0};
358 static const WCHAR prop_serialnumberW[] =
359 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
360 static const WCHAR prop_servicepackmajorW[] =
361 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
362 static const WCHAR prop_servicepackminorW[] =
363 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
364 static const WCHAR prop_servicetypeW[] =
365 {'S','e','r','v','i','c','e','T','y','p','e',0};
366 static const WCHAR prop_settingidW[] =
367 {'S','e','t','t','i','n','g','I','D',0};
368 static const WCHAR prop_skunumberW[] =
369 {'S','K','U','N','u','m','b','e','r',0};
370 static const WCHAR prop_smbiosbiosversionW[] =
371 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
372 static const WCHAR prop_smbiosmajorversionW[] =
373 {'S','M','B','I','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
374 static const WCHAR prop_smbiosminorversionW[] =
375 {'S','M','B','I','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
376 static const WCHAR prop_startmodeW[] =
377 {'S','t','a','r','t','M','o','d','e',0};
378 static const WCHAR prop_sidW[] =
379 {'S','I','D',0};
380 static const WCHAR prop_sidlengthW[] =
381 {'S','i','d','L','e','n','g','t','h',0};
382 static const WCHAR prop_sizeW[] =
383 {'S','i','z','e',0};
384 static const WCHAR prop_speedW[] =
385 {'S','p','e','e','d',0};
386 static const WCHAR prop_startingoffsetW[] =
387 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
388 static const WCHAR prop_stateW[] =
389 {'S','t','a','t','e',0};
390 static const WCHAR prop_statusW[] =
391 {'S','t','a','t','u','s',0};
392 static const WCHAR prop_statusinfoW[] =
393 {'S','t','a','t','u','s','I','n','f','o',0};
394 static const WCHAR prop_strvalueW[] =
395 {'S','t','r','i','n','g','V','a','l','u','e',0};
396 static const WCHAR prop_suitemaskW[] =
397 {'S','u','i','t','e','M','a','s','k',0};
398 static const WCHAR prop_systemdirectoryW[] =
399 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
400 static const WCHAR prop_systemdriveW[] =
401 {'S','y','s','t','e','m','D','r','i','v','e',0};
402 static const WCHAR prop_systemnameW[] =
403 {'S','y','s','t','e','m','N','a','m','e',0};
404 static const WCHAR prop_tagW[] =
405 {'T','a','g',0};
406 static const WCHAR prop_threadcountW[] =
407 {'T','h','r','e','a','d','C','o','u','n','t',0};
408 static const WCHAR prop_totalphysicalmemoryW[] =
409 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
410 static const WCHAR prop_totalvirtualmemorysizeW[] =
411 {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
412 static const WCHAR prop_totalvisiblememorysizeW[] =
413 {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
414 static const WCHAR prop_typeW[] =
415 {'T','y','p','e',0};
416 static const WCHAR prop_uniqueidW[] =
417 {'U','n','i','q','u','e','I','d',0};
418 static const WCHAR prop_usernameW[] =
419 {'U','s','e','r','N','a','m','e',0};
420 static const WCHAR prop_uuidW[] =
421 {'U','U','I','D',0};
422 static const WCHAR prop_varianttypeW[] =
423 {'V','a','r','i','a','n','t','T','y','p','e',0};
424 static const WCHAR prop_vendorW[] =
425 {'V','e','n','d','o','r',0};
426 static const WCHAR prop_versionW[] =
427 {'V','e','r','s','i','o','n',0};
428 static const WCHAR prop_videoarchitectureW[] =
429 {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0};
430 static const WCHAR prop_videomemorytypeW[] =
431 {'V','i','d','e','o','M','e','m','o','r','y','T','y','p','e',0};
432 static const WCHAR prop_videomodedescriptionW[] =
433 {'V','i','d','e','o','M','o','d','e','D','e','s','c','r','i','p','t','i','o','n',0};
434 static const WCHAR prop_videoprocessorW[] =
435 {'V','i','d','e','o','P','r','o','c','e','s','s','o','r',0};
436 static const WCHAR prop_volumenameW[] =
437 {'V','o','l','u','m','e','N','a','m','e',0};
438 static const WCHAR prop_volumeserialnumberW[] =
439 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
440 static const WCHAR prop_workingsetsizeW[] =
441 {'W','o','r','k','i','n','g','S','e','t','S','i','z','e',0};
443 /* column definitions must be kept in sync with record structures below */
444 static const struct column col_baseboard[] =
446 { prop_manufacturerW, CIM_STRING },
447 { prop_modelW, CIM_STRING },
448 { prop_nameW, CIM_STRING },
449 { prop_productW, CIM_STRING },
450 { prop_serialnumberW, CIM_STRING },
451 { prop_tagW, CIM_STRING|COL_FLAG_KEY },
452 { prop_versionW, CIM_STRING }
454 static const struct column col_bios[] =
456 { prop_descriptionW, CIM_STRING },
457 { prop_identificationcodeW, CIM_STRING },
458 { prop_manufacturerW, CIM_STRING },
459 { prop_nameW, CIM_STRING },
460 { prop_releasedateW, CIM_DATETIME },
461 { prop_serialnumberW, CIM_STRING },
462 { prop_smbiosbiosversionW, CIM_STRING },
463 { prop_smbiosmajorversionW, CIM_UINT16, VT_I4 },
464 { prop_smbiosminorversionW, CIM_UINT16, VT_I4 },
465 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
467 static const struct column col_cdromdrive[] =
469 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
470 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
471 { prop_mediatypeW, CIM_STRING },
472 { prop_nameW, CIM_STRING },
473 { prop_pnpdeviceidW, CIM_STRING }
475 static const struct column col_compsys[] =
477 { prop_descriptionW, CIM_STRING },
478 { prop_domainW, CIM_STRING },
479 { prop_domainroleW, CIM_UINT16, VT_I4 },
480 { prop_manufacturerW, CIM_STRING },
481 { prop_modelW, CIM_STRING },
482 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
483 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
484 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
485 { prop_totalphysicalmemoryW, CIM_UINT64 },
486 { prop_usernameW, CIM_STRING|COL_FLAG_DYNAMIC }
488 static const struct column col_compsysproduct[] =
490 { prop_identifyingnumberW, CIM_STRING|COL_FLAG_KEY },
491 { prop_nameW, CIM_STRING|COL_FLAG_KEY },
492 { prop_skunumberW, CIM_STRING },
493 { prop_uuidW, CIM_STRING|COL_FLAG_DYNAMIC },
494 { prop_vendorW, CIM_STRING },
495 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
497 static const struct column col_datafile[] =
499 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
500 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
502 static const struct column col_desktopmonitor[] =
504 { prop_pixelsperxlogicalinchW, CIM_UINT32 }
506 static const struct column col_directory[] =
508 { prop_accessmaskW, CIM_UINT32 },
509 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
511 static const struct column col_diskdrive[] =
513 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
514 { prop_indexW, CIM_UINT32, VT_I4 },
515 { prop_interfacetypeW, CIM_STRING },
516 { prop_manufacturerW, CIM_STRING },
517 { prop_mediatypeW, CIM_STRING },
518 { prop_modelW, CIM_STRING },
519 { prop_pnpdeviceidW, CIM_STRING },
520 { prop_serialnumberW, CIM_STRING },
521 { prop_sizeW, CIM_UINT64 }
523 static const struct column col_diskpartition[] =
525 { prop_bootableW, CIM_BOOLEAN },
526 { prop_bootpartitionW, CIM_BOOLEAN },
527 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
528 { prop_diskindexW, CIM_UINT32, VT_I4 },
529 { prop_indexW, CIM_UINT32, VT_I4 },
530 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
531 { prop_sizeW, CIM_UINT64 },
532 { prop_startingoffsetW, CIM_UINT64 },
533 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
535 static const struct column col_ip4routetable[] =
537 { prop_destinationW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
538 { prop_interfaceindexW, CIM_SINT32|COL_FLAG_KEY },
539 { prop_nexthopW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
541 static const struct column col_logicaldisk[] =
543 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
544 { prop_drivetypeW, CIM_UINT32, VT_I4 },
545 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
546 { prop_freespaceW, CIM_UINT64 },
547 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
548 { prop_sizeW, CIM_UINT64 },
549 { prop_volumenameW, CIM_STRING|COL_FLAG_DYNAMIC },
550 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
552 static const struct column col_networkadapter[] =
554 { prop_adaptertypeW, CIM_STRING },
555 { prop_adaptertypeidW, CIM_UINT16, VT_I4 },
556 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
557 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
558 { prop_indexW, CIM_UINT32, VT_I4 },
559 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
560 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
561 { prop_manufacturerW, CIM_STRING },
562 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
563 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
564 { prop_physicaladapterW, CIM_BOOLEAN },
565 { prop_pnpdeviceidW, CIM_STRING },
566 { prop_speedW, CIM_UINT64 }
568 static const struct column col_networkadapterconfig[] =
570 { prop_defaultipgatewayW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
571 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
572 { prop_dhcpenabledW, CIM_BOOLEAN },
573 { prop_dnshostnameW, CIM_STRING|COL_FLAG_DYNAMIC },
574 { prop_dnsserversearchorderW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
575 { prop_indexW, CIM_UINT32|COL_FLAG_KEY, VT_I4 },
576 { prop_ipaddressW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
577 { prop_ipconnectionmetricW, CIM_UINT32, VT_I4 },
578 { prop_ipenabledW, CIM_BOOLEAN },
579 { prop_ipsubnet, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
580 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
581 { prop_settingidW, CIM_STRING|COL_FLAG_DYNAMIC }
583 static const struct column col_os[] =
585 { prop_buildnumberW, CIM_STRING|COL_FLAG_DYNAMIC },
586 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
587 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
588 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
589 { prop_csdversionW, CIM_STRING|COL_FLAG_DYNAMIC },
590 { prop_freephysicalmemoryW, CIM_UINT64 },
591 { prop_installdateW, CIM_DATETIME },
592 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
593 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
594 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
595 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
596 { prop_operatingsystemskuW, CIM_UINT32, VT_I4 },
597 { prop_osarchitectureW, CIM_STRING },
598 { prop_oslanguageW, CIM_UINT32, VT_I4 },
599 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
600 { prop_ostypeW, CIM_UINT16, VT_I4 },
601 { prop_primaryW, CIM_BOOLEAN },
602 { prop_serialnumberW, CIM_STRING },
603 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
604 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
605 { prop_suitemaskW, CIM_UINT32, VT_I4 },
606 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
607 { prop_systemdriveW, CIM_STRING|COL_FLAG_DYNAMIC },
608 { prop_totalvirtualmemorysizeW, CIM_UINT64 },
609 { prop_totalvisiblememorysizeW, CIM_UINT64 },
610 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
612 static const struct column col_param[] =
614 { prop_classW, CIM_STRING },
615 { prop_methodW, CIM_STRING },
616 { prop_directionW, CIM_SINT32 },
617 { prop_parameterW, CIM_STRING },
618 { prop_typeW, CIM_UINT32 },
619 { prop_varianttypeW, CIM_UINT32 },
620 { prop_defaultvalueW, CIM_UINT32 }
622 static const struct column col_physicalmedia[] =
624 { prop_serialnumberW, CIM_STRING },
625 { prop_tagW, CIM_STRING }
627 static const struct column col_physicalmemory[] =
629 { prop_capacityW, CIM_UINT64 },
630 { prop_devicelocatorW, CIM_STRING },
631 { prop_memorytypeW, CIM_UINT16, VT_I4 }
633 static const struct column col_pnpentity[] =
635 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
637 static const struct column col_printer[] =
639 { prop_attributesW, CIM_UINT32 },
640 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
641 { prop_drivernameW, CIM_STRING|COL_FLAG_DYNAMIC },
642 { prop_horizontalresolutionW, CIM_UINT32 },
643 { prop_localW, CIM_BOOLEAN },
644 { prop_locationW, CIM_STRING|COL_FLAG_DYNAMIC },
645 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
646 { prop_networkW, CIM_BOOLEAN },
647 { prop_portnameW, CIM_STRING|COL_FLAG_DYNAMIC },
649 static const struct column col_process[] =
651 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
652 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
653 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
654 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
655 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
656 { prop_pprocessidW, CIM_UINT32, VT_I4 },
657 { prop_processidW, CIM_UINT32, VT_I4 },
658 { prop_threadcountW, CIM_UINT32, VT_I4 },
659 { prop_workingsetsizeW, CIM_UINT64 },
660 /* methods */
661 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
663 static const struct column col_processor[] =
665 { prop_addresswidthW, CIM_UINT16, VT_I4 },
666 { prop_architectureW, CIM_UINT16, VT_I4 },
667 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
668 { prop_cpustatusW, CIM_UINT16 },
669 { prop_currentclockspeedW, CIM_UINT32, VT_I4 },
670 { prop_datawidthW, CIM_UINT16, VT_I4 },
671 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
672 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
673 { prop_familyW, CIM_UINT16, VT_I4 },
674 { prop_levelW, CIM_UINT16, VT_I4 },
675 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
676 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
677 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
678 { prop_numcoresW, CIM_UINT32, VT_I4 },
679 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
680 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
681 { prop_processortypeW, CIM_UINT16, VT_I4 },
682 { prop_revisionW, CIM_UINT16, VT_I4 },
683 { prop_uniqueidW, CIM_STRING },
684 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
686 static const struct column col_qualifier[] =
688 { prop_classW, CIM_STRING },
689 { prop_memberW, CIM_STRING },
690 { prop_typeW, CIM_UINT32 },
691 { prop_flavorW, CIM_SINT32 },
692 { prop_nameW, CIM_STRING },
693 { prop_intvalueW, CIM_SINT32 },
694 { prop_strvalueW, CIM_STRING }
696 static const struct column col_service[] =
698 { prop_acceptpauseW, CIM_BOOLEAN },
699 { prop_acceptstopW, CIM_BOOLEAN },
700 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
701 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
702 { prop_processidW, CIM_UINT32 },
703 { prop_servicetypeW, CIM_STRING },
704 { prop_startmodeW, CIM_STRING },
705 { prop_stateW, CIM_STRING },
706 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
707 /* methods */
708 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
709 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
710 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
711 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
713 static const struct column col_sid[] =
715 { prop_accountnameW, CIM_STRING|COL_FLAG_DYNAMIC },
716 { prop_binaryrepresentationW, CIM_UINT8|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
717 { prop_referenceddomainnameW, CIM_STRING|COL_FLAG_DYNAMIC },
718 { prop_sidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
719 { prop_sidlengthW, CIM_UINT32 }
721 static const struct column col_sounddevice[] =
723 { prop_nameW, CIM_STRING },
724 { prop_productnameW, CIM_STRING },
725 { prop_statusinfoW, CIM_UINT16, VT_I4 }
727 static const struct column col_stdregprov[] =
729 { method_createkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
730 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
731 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
732 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
734 static const struct column col_systemenclosure[] =
736 { prop_captionW, CIM_STRING },
737 { prop_chassistypesW, CIM_UINT16|CIM_FLAG_ARRAY, VT_I4|VT_ARRAY },
738 { prop_descriptionW, CIM_STRING },
739 { prop_lockpresentW, CIM_BOOLEAN },
740 { prop_manufacturerW, CIM_STRING },
741 { prop_nameW, CIM_STRING },
742 { prop_tagW, CIM_STRING },
744 static const struct column col_systemsecurity[] =
746 { method_getsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
747 { method_setsdW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
749 static const struct column col_videocontroller[] =
751 { prop_adapterdactypeW, CIM_STRING },
752 { prop_adapterramW, CIM_UINT32, VT_I4 },
753 { prop_availabilityW, CIM_UINT16 },
754 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
755 { prop_configmanagererrorcodeW, CIM_UINT32, VT_I4 },
756 { prop_currentbitsperpixelW, CIM_UINT32, VT_I4 },
757 { prop_currenthorizontalresW, CIM_UINT32, VT_I4 },
758 { prop_currentrefreshrateW, CIM_UINT32, VT_I4 },
759 { prop_currentscanmodeW, CIM_UINT16, VT_I4 },
760 { prop_currentverticalresW, CIM_UINT32, VT_I4 },
761 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
762 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
763 { prop_driverdateW, CIM_DATETIME },
764 { prop_driverversionW, CIM_STRING },
765 { prop_installeddisplaydriversW,CIM_STRING },
766 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
767 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
768 { prop_statusW, CIM_STRING },
769 { prop_videoarchitectureW, CIM_UINT16, VT_I4 },
770 { prop_videomemorytypeW, CIM_UINT16, VT_I4 },
771 { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
772 { prop_videoprocessorW, CIM_STRING|COL_FLAG_DYNAMIC },
775 static const WCHAR baseboard_manufacturerW[] =
776 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
777 static const WCHAR baseboard_serialnumberW[] =
778 {'N','o','n','e',0};
779 static const WCHAR baseboard_tagW[] =
780 {'B','a','s','e',' ','B','o','a','r','d',0};
781 static const WCHAR baseboard_versionW[] =
782 {'1','.','0',0};
783 static const WCHAR bios_descriptionW[] =
784 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
785 static const WCHAR bios_manufacturerW[] =
786 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
787 static const WCHAR bios_nameW[] =
788 {'W','I','N','E',' ','B','I','O','S',0};
789 static const WCHAR bios_releasedateW[] =
790 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
791 static const WCHAR bios_serialnumberW[] =
792 {'0',0};
793 static const WCHAR bios_smbiosbiosversionW[] =
794 {'W','i','n','e',0};
795 static const WCHAR bios_versionW[] =
796 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
797 static const WCHAR cdromdrive_mediatypeW[] =
798 {'C','D','-','R','O','M',0};
799 static const WCHAR cdromdrive_nameW[] =
800 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
801 static const WCHAR cdromdrive_pnpdeviceidW[]=
802 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
803 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
804 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
805 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
806 static const WCHAR compsys_descriptionW[] =
807 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
808 static const WCHAR compsys_domainW[] =
809 {'W','O','R','K','G','R','O','U','P',0};
810 static const WCHAR compsys_manufacturerW[] =
811 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
812 static const WCHAR compsys_modelW[] =
813 {'W','i','n','e',0};
814 static const WCHAR compsysproduct_identifyingnumberW[] =
815 {'0',0};
816 static const WCHAR compsysproduct_nameW[] =
817 {'W','i','n','e',0};
818 static const WCHAR compsysproduct_uuidW[] =
819 {'d','e','a','d','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-',
820 'd','e','a','d','d','e','a','d','d','e','a','d',0};
821 static const WCHAR compsysproduct_vendorW[] =
822 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
823 static const WCHAR compsysproduct_versionW[] =
824 {'1','.','0',0};
825 static const WCHAR diskdrive_interfacetypeW[] =
826 {'I','D','E',0};
827 static const WCHAR diskdrive_manufacturerW[] =
828 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
829 static const WCHAR diskdrive_mediatype_fixedW[] =
830 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
831 static const WCHAR diskdrive_mediatype_removableW[] =
832 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
833 static const WCHAR diskdrive_modelW[] =
834 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
835 static const WCHAR diskdrive_pnpdeviceidW[] =
836 {'I','D','E','\\','D','i','s','k','\\','V','E','N','_','W','I','N','E',0};
837 static const WCHAR diskdrive_serialW[] =
838 {'W','I','N','E','H','D','I','S','K',0};
839 static const WCHAR networkadapter_pnpdeviceidW[]=
840 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
841 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
842 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
843 static const WCHAR os_32bitW[] =
844 {'3','2','-','b','i','t',0};
845 static const WCHAR os_64bitW[] =
846 {'6','4','-','b','i','t',0};
847 static const WCHAR os_installdateW[] =
848 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
849 static const WCHAR os_serialnumberW[] =
850 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
851 static const WCHAR physicalmedia_tagW[] =
852 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
853 static const WCHAR sounddevice_productnameW[] =
854 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
855 static const WCHAR systemenclosure_systemenclosureW[] =
856 {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',0};
857 static const WCHAR systemenclosure_tagW[] =
858 {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',' ','0',0};
859 static const WCHAR systemenclosure_manufacturerW[] =
860 {'W','i','n','e',0};
861 static const WCHAR videocontroller_dactypeW[] =
862 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
863 static const WCHAR videocontroller_deviceidW[] =
864 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
865 static const WCHAR videocontroller_driverdateW[] =
866 {'2','0','1','7','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
867 static const WCHAR videocontroller_driverversionW[] =
868 {'1','.','0',0};
869 static const WCHAR videocontroller_statusW[] =
870 {'O','K',0};
872 #include "pshpack1.h"
873 struct record_baseboard
875 const WCHAR *manufacturer;
876 const WCHAR *model;
877 const WCHAR *name;
878 const WCHAR *product;
879 const WCHAR *serialnumber;
880 const WCHAR *tag;
881 const WCHAR *version;
883 struct record_bios
885 const WCHAR *description;
886 const WCHAR *identificationcode;
887 const WCHAR *manufacturer;
888 const WCHAR *name;
889 const WCHAR *releasedate;
890 const WCHAR *serialnumber;
891 const WCHAR *smbiosbiosversion;
892 UINT16 smbiosmajorversion;
893 UINT16 smbiosminorversion;
894 const WCHAR *version;
896 struct record_cdromdrive
898 const WCHAR *device_id;
899 const WCHAR *drive;
900 const WCHAR *mediatype;
901 const WCHAR *name;
902 const WCHAR *pnpdevice_id;
904 struct record_computersystem
906 const WCHAR *description;
907 const WCHAR *domain;
908 UINT16 domainrole;
909 const WCHAR *manufacturer;
910 const WCHAR *model;
911 const WCHAR *name;
912 UINT32 num_logical_processors;
913 UINT32 num_processors;
914 UINT64 total_physical_memory;
915 const WCHAR *username;
917 struct record_computersystemproduct
919 const WCHAR *identifyingnumber;
920 const WCHAR *name;
921 const WCHAR *skunumber;
922 const WCHAR *uuid;
923 const WCHAR *vendor;
924 const WCHAR *version;
926 struct record_datafile
928 const WCHAR *name;
929 const WCHAR *version;
931 struct record_desktopmonitor
933 UINT32 pixelsperxlogicalinch;
935 struct record_directory
937 UINT32 accessmask;
938 const WCHAR *name;
940 struct record_diskdrive
942 const WCHAR *device_id;
943 UINT32 index;
944 const WCHAR *interfacetype;
945 const WCHAR *manufacturer;
946 const WCHAR *mediatype;
947 const WCHAR *model;
948 const WCHAR *pnpdevice_id;
949 const WCHAR *serialnumber;
950 UINT64 size;
952 struct record_diskpartition
954 int bootable;
955 int bootpartition;
956 const WCHAR *device_id;
957 UINT32 diskindex;
958 UINT32 index;
959 const WCHAR *pnpdevice_id;
960 UINT64 size;
961 UINT64 startingoffset;
962 const WCHAR *type;
964 struct record_ip4routetable
966 const WCHAR *destination;
967 INT32 interfaceindex;
968 const WCHAR *nexthop;
970 struct record_logicaldisk
972 const WCHAR *device_id;
973 UINT32 drivetype;
974 const WCHAR *filesystem;
975 UINT64 freespace;
976 const WCHAR *name;
977 UINT64 size;
978 const WCHAR *volumename;
979 const WCHAR *volumeserialnumber;
981 struct record_networkadapter
983 const WCHAR *adaptertype;
984 UINT16 adaptertypeid;
985 const WCHAR *description;
986 const WCHAR *device_id;
987 UINT32 index;
988 UINT32 interface_index;
989 const WCHAR *mac_address;
990 const WCHAR *manufacturer;
991 const WCHAR *name;
992 UINT16 netconnection_status;
993 int physicaladapter;
994 const WCHAR *pnpdevice_id;
995 UINT64 speed;
997 struct record_networkadapterconfig
999 const struct array *defaultipgateway;
1000 const WCHAR *description;
1001 int dhcpenabled;
1002 const WCHAR *dnshostname;
1003 const struct array *dnsserversearchorder;
1004 UINT32 index;
1005 const struct array *ipaddress;
1006 UINT32 ipconnectionmetric;
1007 int ipenabled;
1008 const struct array *ipsubnet;
1009 const WCHAR *mac_address;
1010 const WCHAR *settingid;
1012 struct record_operatingsystem
1014 const WCHAR *buildnumber;
1015 const WCHAR *caption;
1016 const WCHAR *codeset;
1017 const WCHAR *countrycode;
1018 const WCHAR *csdversion;
1019 UINT64 freephysicalmemory;
1020 const WCHAR *installdate;
1021 const WCHAR *lastbootuptime;
1022 const WCHAR *localdatetime;
1023 const WCHAR *locale;
1024 const WCHAR *name;
1025 UINT32 operatingsystemsku;
1026 const WCHAR *osarchitecture;
1027 UINT32 oslanguage;
1028 UINT32 osproductsuite;
1029 UINT16 ostype;
1030 int primary;
1031 const WCHAR *serialnumber;
1032 UINT16 servicepackmajor;
1033 UINT16 servicepackminor;
1034 UINT32 suitemask;
1035 const WCHAR *systemdirectory;
1036 const WCHAR *systemdrive;
1037 UINT64 totalvirtualmemorysize;
1038 UINT64 totalvisiblememorysize;
1039 const WCHAR *version;
1041 struct record_param
1043 const WCHAR *class;
1044 const WCHAR *method;
1045 INT32 direction;
1046 const WCHAR *parameter;
1047 UINT32 type;
1048 UINT32 varianttype;
1049 UINT32 defaultvalue;
1051 struct record_physicalmedia
1053 const WCHAR *serialnumber;
1054 const WCHAR *tag;
1056 struct record_physicalmemory
1058 UINT64 capacity;
1059 const WCHAR *devicelocator;
1060 UINT16 memorytype;
1062 struct record_pnpentity
1064 const WCHAR *device_id;
1066 struct record_printer
1068 UINT32 attributes;
1069 const WCHAR *device_id;
1070 const WCHAR *drivername;
1071 UINT32 horizontalresolution;
1072 int local;
1073 const WCHAR *location;
1074 const WCHAR *name;
1075 int network;
1076 const WCHAR *portname;
1078 struct record_process
1080 const WCHAR *caption;
1081 const WCHAR *commandline;
1082 const WCHAR *description;
1083 const WCHAR *handle;
1084 const WCHAR *name;
1085 UINT32 pprocess_id;
1086 UINT32 process_id;
1087 UINT32 thread_count;
1088 UINT64 workingsetsize;
1089 /* methods */
1090 class_method *get_owner;
1092 struct record_processor
1094 UINT16 addresswidth;
1095 UINT16 architecture;
1096 const WCHAR *caption;
1097 UINT16 cpu_status;
1098 UINT32 currentclockspeed;
1099 UINT16 datawidth;
1100 const WCHAR *description;
1101 const WCHAR *device_id;
1102 UINT16 family;
1103 UINT16 level;
1104 const WCHAR *manufacturer;
1105 UINT32 maxclockspeed;
1106 const WCHAR *name;
1107 UINT32 num_cores;
1108 UINT32 num_logical_processors;
1109 const WCHAR *processor_id;
1110 UINT16 processortype;
1111 UINT16 revision;
1112 const WCHAR *unique_id;
1113 const WCHAR *version;
1115 struct record_qualifier
1117 const WCHAR *class;
1118 const WCHAR *member;
1119 UINT32 type;
1120 INT32 flavor;
1121 const WCHAR *name;
1122 INT32 intvalue;
1123 const WCHAR *strvalue;
1125 struct record_service
1127 int accept_pause;
1128 int accept_stop;
1129 const WCHAR *displayname;
1130 const WCHAR *name;
1131 UINT32 process_id;
1132 const WCHAR *servicetype;
1133 const WCHAR *startmode;
1134 const WCHAR *state;
1135 const WCHAR *systemname;
1136 /* methods */
1137 class_method *pause_service;
1138 class_method *resume_service;
1139 class_method *start_service;
1140 class_method *stop_service;
1142 struct record_sid
1144 const WCHAR *accountname;
1145 const struct array *binaryrepresentation;
1146 const WCHAR *referenceddomainname;
1147 const WCHAR *sid;
1148 UINT32 sidlength;
1150 struct record_sounddevice
1152 const WCHAR *name;
1153 const WCHAR *productname;
1154 UINT16 statusinfo;
1156 struct record_stdregprov
1158 class_method *createkey;
1159 class_method *enumkey;
1160 class_method *enumvalues;
1161 class_method *getstringvalue;
1163 struct record_systemsecurity
1165 class_method *getsd;
1166 class_method *setsd;
1168 struct record_systemenclosure
1170 const WCHAR *caption;
1171 const struct array *chassistypes;
1172 const WCHAR *description;
1173 int lockpresent;
1174 const WCHAR *manufacturer;
1175 const WCHAR *name;
1176 const WCHAR *tag;
1178 struct record_videocontroller
1180 const WCHAR *adapter_dactype;
1181 UINT32 adapter_ram;
1182 UINT16 availability;
1183 const WCHAR *caption;
1184 UINT32 config_errorcode;
1185 UINT32 current_bitsperpixel;
1186 UINT32 current_horizontalres;
1187 UINT32 current_refreshrate;
1188 UINT16 current_scanmode;
1189 UINT32 current_verticalres;
1190 const WCHAR *description;
1191 const WCHAR *device_id;
1192 const WCHAR *driverdate;
1193 const WCHAR *driverversion;
1194 const WCHAR *installeddriver;
1195 const WCHAR *name;
1196 const WCHAR *pnpdevice_id;
1197 const WCHAR *status;
1198 UINT16 videoarchitecture;
1199 UINT16 videomemorytype;
1200 const WCHAR *videomodedescription;
1201 const WCHAR *videoprocessor;
1203 #include "poppack.h"
1205 static const struct record_baseboard data_baseboard[] =
1207 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_versionW }
1209 static const struct record_bios data_bios[] =
1211 { bios_descriptionW, NULL, bios_manufacturerW, bios_nameW, bios_releasedateW, bios_serialnumberW,
1212 bios_smbiosbiosversionW, 1, 0, bios_versionW }
1214 static const struct record_param data_param[] =
1216 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1217 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
1218 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
1219 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1220 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1221 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1222 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1223 { class_stdregprovW, method_createkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1224 { class_stdregprovW, method_createkeyW, 1, param_subkeynameW, CIM_STRING },
1225 { class_stdregprovW, method_createkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1226 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1227 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
1228 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1229 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1230 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1231 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
1232 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1233 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1234 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
1235 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
1236 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
1237 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
1238 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1239 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
1240 { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1241 { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1242 { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1243 { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
1246 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
1247 WBEM_FLAVOR_ORIGIN_PROPAGATED)
1249 static const struct record_physicalmedia data_physicalmedia[] =
1251 { diskdrive_serialW, physicalmedia_tagW }
1253 static const struct record_qualifier data_qualifier[] =
1255 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
1256 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
1258 static const struct record_sounddevice data_sounddevice[] =
1260 { sounddevice_productnameW, sounddevice_productnameW, 3 /* enabled */ }
1262 static const struct record_stdregprov data_stdregprov[] =
1264 { reg_create_key, reg_enum_key, reg_enum_values, reg_get_stringvalue }
1266 static UINT16 systemenclosure_chassistypes[] =
1270 static const struct array systemenclosure_chassistypes_array =
1272 ARRAY_SIZE(systemenclosure_chassistypes),
1273 &systemenclosure_chassistypes
1275 static const struct record_systemenclosure data_systemenclosure[] =
1278 systemenclosure_systemenclosureW,
1279 &systemenclosure_chassistypes_array,
1280 systemenclosure_systemenclosureW,
1281 FALSE,
1282 systemenclosure_manufacturerW,
1283 systemenclosure_systemenclosureW,
1284 systemenclosure_tagW,
1287 static const struct record_systemsecurity data_systemsecurity[] =
1289 { security_get_sd, security_set_sd }
1292 /* check if row matches condition and update status */
1293 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
1295 LONGLONG val;
1296 UINT type;
1298 if (!cond)
1300 *status = FILL_STATUS_UNFILTERED;
1301 return TRUE;
1303 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
1305 *status = FILL_STATUS_FAILED;
1306 return FALSE;
1308 *status = FILL_STATUS_FILTERED;
1309 return val != 0;
1312 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
1314 if (!table->num_rows_allocated)
1316 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
1317 table->num_rows_allocated = row_count;
1318 return TRUE;
1320 if (row_count > table->num_rows_allocated)
1322 BYTE *data;
1323 UINT count = max( row_count, table->num_rows_allocated * 2 );
1324 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
1325 table->data = data;
1326 table->num_rows_allocated = count;
1328 return TRUE;
1331 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
1333 static const WCHAR fmtW[] = {'%','c',':',0};
1334 WCHAR drive[3], root[] = {'A',':','\\',0};
1335 struct record_cdromdrive *rec;
1336 UINT i, row = 0, offset = 0;
1337 DWORD drives = GetLogicalDrives();
1338 enum fill_status status = FILL_STATUS_UNFILTERED;
1340 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1342 for (i = 0; i < 26; i++)
1344 if (drives & (1 << i))
1346 root[0] = 'A' + i;
1347 if (GetDriveTypeW( root ) != DRIVE_CDROM)
1348 continue;
1350 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1352 rec = (struct record_cdromdrive *)(table->data + offset);
1353 rec->device_id = cdromdrive_pnpdeviceidW;
1354 sprintfW( drive, fmtW, 'A' + i );
1355 rec->drive = heap_strdupW( drive );
1356 rec->mediatype = cdromdrive_mediatypeW;
1357 rec->name = cdromdrive_nameW;
1358 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
1359 if (!match_row( table, row, cond, &status ))
1361 free_row_values( table, row );
1362 continue;
1364 offset += sizeof(*rec);
1365 row++;
1368 TRACE("created %u rows\n", row);
1369 table->num_rows = row;
1370 return status;
1373 static UINT get_processor_count(void)
1375 SYSTEM_BASIC_INFORMATION info;
1377 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
1378 return info.NumberOfProcessors;
1381 static UINT get_logical_processor_count( UINT *num_physical, UINT *num_packages )
1383 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buf, *entry;
1384 UINT core_relation_count = 0, package_relation_count = 0;
1385 NTSTATUS status;
1386 ULONG len, offset = 0;
1387 BOOL smt_enabled = FALSE;
1388 DWORD all = RelationAll;
1390 if (num_packages) *num_packages = 1;
1391 status = NtQuerySystemInformationEx( SystemLogicalProcessorInformationEx, &all, sizeof(all), NULL, 0, &len );
1392 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
1394 if (!(buf = heap_alloc( len ))) return get_processor_count();
1395 status = NtQuerySystemInformationEx( SystemLogicalProcessorInformationEx, &all, sizeof(all), buf, len, NULL );
1396 if (status != STATUS_SUCCESS)
1398 heap_free( buf );
1399 return get_processor_count();
1402 while (offset < len)
1404 entry = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)((char *)buf + offset);
1406 if (entry->Relationship == RelationProcessorCore)
1408 core_relation_count++;
1409 if (entry->u.Processor.Flags & LTP_PC_SMT) smt_enabled = TRUE;
1411 else if (entry->Relationship == RelationProcessorPackage)
1413 package_relation_count++;
1415 offset += entry->Size;
1418 heap_free( buf );
1419 if (num_physical) *num_physical = core_relation_count;
1420 if (num_packages) *num_packages = package_relation_count;
1421 return smt_enabled ? core_relation_count * 2 : core_relation_count;
1424 static UINT64 get_total_physical_memory(void)
1426 MEMORYSTATUSEX status;
1428 status.dwLength = sizeof(status);
1429 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1430 return status.ullTotalPhys;
1433 static UINT64 get_available_physical_memory(void)
1435 MEMORYSTATUSEX status;
1437 status.dwLength = sizeof(status);
1438 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1439 return status.ullAvailPhys;
1442 static WCHAR *get_computername(void)
1444 WCHAR *ret;
1445 DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
1447 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1448 GetComputerNameW( ret, &size );
1449 return ret;
1452 static WCHAR *get_username(void)
1454 WCHAR *ret;
1455 DWORD compsize, usersize;
1456 DWORD size;
1458 compsize = 0;
1459 GetComputerNameW( NULL, &compsize );
1460 usersize = 0;
1461 GetUserNameW( NULL, &usersize );
1462 size = compsize + usersize; /* two null terminators account for the \ */
1463 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1464 GetComputerNameW( ret, &compsize );
1465 ret[compsize] = '\\';
1466 GetUserNameW( ret + compsize + 1, &usersize );
1467 return ret;
1470 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1472 struct record_computersystem *rec;
1473 enum fill_status status = FILL_STATUS_UNFILTERED;
1474 UINT row = 0;
1476 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1478 rec = (struct record_computersystem *)table->data;
1479 rec->description = compsys_descriptionW;
1480 rec->domain = compsys_domainW;
1481 rec->domainrole = 0; /* standalone workstation */
1482 rec->manufacturer = compsys_manufacturerW;
1483 rec->model = compsys_modelW;
1484 rec->name = get_computername();
1485 rec->num_logical_processors = get_logical_processor_count( NULL, &rec->num_processors );
1486 rec->total_physical_memory = get_total_physical_memory();
1487 rec->username = get_username();
1488 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1489 else row++;
1491 TRACE("created %u rows\n", row);
1492 table->num_rows = row;
1493 return status;
1496 static WCHAR *get_compsysproduct_uuid(void)
1498 #ifdef __APPLE__
1499 unsigned char uuid[16];
1500 const struct timespec timeout = {1, 0};
1501 if (!gethostuuid( uuid, &timeout ))
1503 static const WCHAR fmtW[] =
1504 {'%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-',
1505 '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X',
1506 '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',0};
1507 WCHAR *ret = heap_alloc( 37 * sizeof(WCHAR) );
1508 if (!ret) return NULL;
1509 sprintfW( ret, fmtW, uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
1510 uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] );
1511 return ret;
1513 #endif
1514 #ifdef __linux__
1515 int file;
1516 if ((file = open( "/var/lib/dbus/machine-id", O_RDONLY )) != -1)
1518 unsigned char buf[32];
1519 if (read( file, buf, sizeof(buf) ) == sizeof(buf))
1521 unsigned int i, j;
1522 WCHAR *ret, *p;
1524 close( file );
1525 if (!(p = ret = heap_alloc( 37 * sizeof(WCHAR) ))) return NULL;
1526 for (i = 0, j = 0; i < 8; i++) p[i] = toupperW( buf[j++] );
1527 p[8] = '-';
1528 for (i = 9; i < 13; i++) p[i] = toupperW( buf[j++] );
1529 p[13] = '-';
1530 for (i = 14; i < 18; i++) p[i] = toupperW( buf[j++] );
1531 p[18] = '-';
1532 for (i = 19; i < 23; i++) p[i] = toupperW( buf[j++] );
1533 p[23] = '-';
1534 for (i = 24; i < 36; i++) p[i] = toupperW( buf[j++] );
1535 ret[i] = 0;
1536 return ret;
1538 close( file );
1540 #endif
1541 return heap_strdupW( compsysproduct_uuidW );
1544 static enum fill_status fill_compsysproduct( struct table *table, const struct expr *cond )
1546 struct record_computersystemproduct *rec;
1547 enum fill_status status = FILL_STATUS_UNFILTERED;
1548 UINT row = 0;
1550 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1552 rec = (struct record_computersystemproduct *)table->data;
1553 rec->identifyingnumber = compsysproduct_identifyingnumberW;
1554 rec->name = compsysproduct_nameW;
1555 rec->skunumber = NULL;
1556 rec->uuid = get_compsysproduct_uuid();
1557 rec->vendor = compsysproduct_vendorW;
1558 rec->version = compsysproduct_versionW;
1559 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1560 else row++;
1562 TRACE("created %u rows\n", row);
1563 table->num_rows = row;
1564 return status;
1567 struct dirstack
1569 WCHAR **dirs;
1570 UINT *len_dirs;
1571 UINT num_dirs;
1572 UINT num_allocated;
1575 static struct dirstack *alloc_dirstack( UINT size )
1577 struct dirstack *dirstack;
1579 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1580 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1582 heap_free( dirstack );
1583 return NULL;
1585 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1587 heap_free( dirstack->dirs );
1588 heap_free( dirstack );
1589 return NULL;
1591 dirstack->num_dirs = 0;
1592 dirstack->num_allocated = size;
1593 return dirstack;
1596 static void clear_dirstack( struct dirstack *dirstack )
1598 UINT i;
1599 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1600 dirstack->num_dirs = 0;
1603 static void free_dirstack( struct dirstack *dirstack )
1605 clear_dirstack( dirstack );
1606 heap_free( dirstack->dirs );
1607 heap_free( dirstack->len_dirs );
1608 heap_free( dirstack );
1611 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1613 UINT size, i = dirstack->num_dirs;
1615 if (!dir) return FALSE;
1617 if (i == dirstack->num_allocated)
1619 WCHAR **tmp;
1620 UINT *len_tmp;
1622 size = dirstack->num_allocated * 2;
1623 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1624 dirstack->dirs = tmp;
1625 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1626 dirstack->len_dirs = len_tmp;
1627 dirstack->num_allocated = size;
1629 dirstack->dirs[i] = dir;
1630 dirstack->len_dirs[i] = len;
1631 dirstack->num_dirs++;
1632 return TRUE;
1635 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1637 if (!dirstack->num_dirs)
1639 *len = 0;
1640 return NULL;
1642 dirstack->num_dirs--;
1643 *len = dirstack->len_dirs[dirstack->num_dirs];
1644 return dirstack->dirs[dirstack->num_dirs];
1647 static const WCHAR *peek_dir( struct dirstack *dirstack )
1649 if (!dirstack->num_dirs) return NULL;
1650 return dirstack->dirs[dirstack->num_dirs - 1];
1653 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1655 UINT i = 0;
1656 WCHAR *ret;
1658 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1659 ret[i++] = drive;
1660 ret[i++] = ':';
1661 ret[i++] = '\\';
1662 if (path && len)
1664 memcpy( ret + i, path, len * sizeof(WCHAR) );
1665 i += len;
1666 ret[i++] = '\\';
1668 ret[i++] = '*';
1669 ret[i] = 0;
1670 return ret;
1673 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1675 UINT i = 0, len = 0;
1676 const WCHAR *p;
1677 WCHAR *ret;
1679 for (p = path; *p; p++)
1681 if (*p == '\\') len += 2;
1682 else len++;
1684 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1685 ret[i++] = drive;
1686 ret[i++] = ':';
1687 ret[i++] = '\\';
1688 ret[i++] = '\\';
1689 for (p = path; *p; p++)
1691 if (*p != '\\') ret[i++] = *p;
1692 else
1694 ret[i++] = '\\';
1695 ret[i++] = '\\';
1698 ret[i] = 0;
1699 return ret;
1702 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1704 const WCHAR *p = path, *start;
1705 UINT len, i;
1706 WCHAR *ret;
1708 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1709 start = path + 4;
1710 len = strlenW( start );
1711 p = start + len - 1;
1712 if (*p == '\\') return NULL;
1714 while (p >= start && *p != '\\') { len--; p--; };
1715 while (p >= start && *p == '\\') { len--; p--; };
1717 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1718 for (i = 0, p = start; p < start + len; p++)
1720 if (p[0] == '\\' && p[1] == '\\')
1722 ret[i++] = '\\';
1723 p++;
1725 else ret[i++] = *p;
1727 ret[i] = 0;
1728 *ret_len = i;
1729 return ret;
1732 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1734 UINT i;
1735 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1736 return FALSE;
1739 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1740 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1742 const struct expr *left, *right;
1744 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1746 left = cond->u.expr.left;
1747 right = cond->u.expr.right;
1748 if (cond->u.expr.op == OP_EQ)
1750 UINT len;
1751 WCHAR *path;
1752 const WCHAR *str = NULL;
1754 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1755 !strcmpW( left->u.propval->name, prop_nameW ) &&
1756 toupperW( right->u.sval[0] ) == toupperW( root ))
1758 str = right->u.sval;
1760 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1761 !strcmpW( right->u.propval->name, prop_nameW ) &&
1762 toupperW( left->u.sval[0] ) == toupperW( root ))
1764 str = left->u.sval;
1766 if (str && (path = build_dirname( str, &len )))
1768 if (seen_dir( dirstack, path ))
1770 heap_free( path );
1771 return ++*count;
1773 else if (push_dir( dirstack, path, len )) return ++*count;
1774 heap_free( path );
1775 return *count = 0;
1778 else if (cond->u.expr.op == OP_OR)
1780 UINT left_count = 0, right_count = 0;
1782 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1783 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1784 return *count += left_count + right_count;
1786 return *count = 0;
1789 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1791 UINT len_path = 0, len_segment = strlenW( segment );
1792 WCHAR *ret;
1794 *len = 0;
1795 if (path) len_path = strlenW( path );
1796 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1797 if (path && len_path)
1799 memcpy( ret, path, len_path * sizeof(WCHAR) );
1800 ret[len_path] = '\\';
1801 *len += len_path + 1;
1803 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1804 *len += len_segment;
1805 ret[*len] = 0;
1806 return ret;
1809 static WCHAR *get_file_version( const WCHAR *filename )
1811 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1812 VS_FIXEDFILEINFO *info;
1813 DWORD size;
1814 void *block;
1815 WCHAR *ret;
1817 if (!(ret = heap_alloc( (4 * 5 + ARRAY_SIZE( fmtW )) * sizeof(WCHAR) ))) return NULL;
1818 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1820 heap_free( ret );
1821 return NULL;
1823 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1824 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1826 heap_free( block );
1827 heap_free( ret );
1828 return NULL;
1830 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1831 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1832 heap_free( block );
1833 return ret;
1836 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1838 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1839 struct record_datafile *rec;
1840 UINT i, len, row = 0, offset = 0, num_expected_rows;
1841 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1842 DWORD drives = GetLogicalDrives();
1843 WIN32_FIND_DATAW data;
1844 HANDLE handle;
1845 struct dirstack *dirstack;
1846 enum fill_status status = FILL_STATUS_UNFILTERED;
1848 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1850 dirstack = alloc_dirstack(2);
1852 for (i = 0; i < 26; i++)
1854 if (!(drives & (1 << i))) continue;
1856 root[0] = 'A' + i;
1857 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1859 num_expected_rows = 0;
1860 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1862 for (;;)
1864 heap_free( glob );
1865 heap_free( path );
1866 path = pop_dir( dirstack, &len );
1867 if (!(glob = build_glob( root[0], path, len )))
1869 status = FILL_STATUS_FAILED;
1870 goto done;
1872 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1876 if (!resize_table( table, row + 1, sizeof(*rec) ))
1878 status = FILL_STATUS_FAILED;
1879 FindClose( handle );
1880 goto done;
1882 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1883 new_path = append_path( path, data.cFileName, &len );
1885 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1887 if (push_dir( dirstack, new_path, len )) continue;
1888 heap_free( new_path );
1889 FindClose( handle );
1890 status = FILL_STATUS_FAILED;
1891 goto done;
1893 rec = (struct record_datafile *)(table->data + offset);
1894 rec->name = build_name( root[0], new_path );
1895 rec->version = get_file_version( rec->name );
1896 if (!match_row( table, row, cond, &status ))
1898 free_row_values( table, row );
1899 continue;
1901 else if (num_expected_rows && row == num_expected_rows - 1)
1903 row++;
1904 FindClose( handle );
1905 status = FILL_STATUS_FILTERED;
1906 goto done;
1908 offset += sizeof(*rec);
1909 row++;
1911 while (FindNextFileW( handle, &data ));
1912 FindClose( handle );
1914 if (!peek_dir( dirstack )) break;
1918 done:
1919 free_dirstack( dirstack );
1920 heap_free( glob );
1921 heap_free( path );
1923 TRACE("created %u rows\n", row);
1924 table->num_rows = row;
1925 return status;
1928 static UINT32 get_pixelsperxlogicalinch(void)
1930 HDC hdc = GetDC( NULL );
1931 UINT32 ret;
1933 if (!hdc) return 96;
1934 ret = GetDeviceCaps( hdc, LOGPIXELSX );
1935 ReleaseDC( NULL, hdc );
1936 return ret;
1939 static enum fill_status fill_desktopmonitor( struct table *table, const struct expr *cond )
1941 struct record_desktopmonitor *rec;
1942 enum fill_status status = FILL_STATUS_UNFILTERED;
1943 UINT row = 0;
1945 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1947 rec = (struct record_desktopmonitor *)table->data;
1948 rec->pixelsperxlogicalinch = get_pixelsperxlogicalinch();
1950 if (match_row( table, row, cond, &status )) row++;
1952 TRACE("created %u rows\n", row);
1953 table->num_rows = row;
1954 return status;
1957 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1959 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1960 struct record_directory *rec;
1961 UINT i, len, row = 0, offset = 0, num_expected_rows;
1962 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1963 DWORD drives = GetLogicalDrives();
1964 WIN32_FIND_DATAW data;
1965 HANDLE handle;
1966 struct dirstack *dirstack;
1967 enum fill_status status = FILL_STATUS_UNFILTERED;
1969 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1971 dirstack = alloc_dirstack(2);
1973 for (i = 0; i < 26; i++)
1975 if (!(drives & (1 << i))) continue;
1977 root[0] = 'A' + i;
1978 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1980 num_expected_rows = 0;
1981 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1983 for (;;)
1985 heap_free( glob );
1986 heap_free( path );
1987 path = pop_dir( dirstack, &len );
1988 if (!(glob = build_glob( root[0], path, len )))
1990 status = FILL_STATUS_FAILED;
1991 goto done;
1993 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1997 if (!resize_table( table, row + 1, sizeof(*rec) ))
1999 FindClose( handle );
2000 status = FILL_STATUS_FAILED;
2001 goto done;
2003 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
2004 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
2005 continue;
2007 new_path = append_path( path, data.cFileName, &len );
2008 if (!(push_dir( dirstack, new_path, len )))
2010 heap_free( new_path );
2011 FindClose( handle );
2012 status = FILL_STATUS_FAILED;
2013 goto done;
2015 rec = (struct record_directory *)(table->data + offset);
2016 rec->accessmask = FILE_ALL_ACCESS;
2017 rec->name = build_name( root[0], new_path );
2018 if (!match_row( table, row, cond, &status ))
2020 free_row_values( table, row );
2021 continue;
2023 else if (num_expected_rows && row == num_expected_rows - 1)
2025 row++;
2026 FindClose( handle );
2027 status = FILL_STATUS_FILTERED;
2028 goto done;
2030 offset += sizeof(*rec);
2031 row++;
2033 while (FindNextFileW( handle, &data ));
2034 FindClose( handle );
2036 if (!peek_dir( dirstack )) break;
2040 done:
2041 free_dirstack( dirstack );
2042 heap_free( glob );
2043 heap_free( path );
2045 TRACE("created %u rows\n", row);
2046 table->num_rows = row;
2047 return status;
2050 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
2052 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
2053 ULARGE_INTEGER free;
2054 DISK_GEOMETRY_EX info;
2055 HANDLE handle;
2056 DWORD bytes_returned;
2058 free.QuadPart = 512 * 1024 * 1024;
2059 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
2061 root[4] = dir[0];
2062 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
2063 if (handle != INVALID_HANDLE_VALUE)
2065 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
2066 *disksize = info.DiskSize.QuadPart;
2067 CloseHandle( handle );
2069 return free.QuadPart;
2072 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
2074 static const WCHAR fmtW[] =
2075 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
2076 WCHAR device_id[ARRAY_SIZE( fmtW ) + 10], root[] = {'A',':','\\',0};
2077 struct record_diskdrive *rec;
2078 UINT i, row = 0, offset = 0, index = 0, type;
2079 UINT64 size = 1024 * 1024 * 1024;
2080 DWORD drives = GetLogicalDrives();
2081 enum fill_status status = FILL_STATUS_UNFILTERED;
2083 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
2085 for (i = 0; i < 26; i++)
2087 if (drives & (1 << i))
2089 root[0] = 'A' + i;
2090 type = GetDriveTypeW( root );
2091 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
2092 continue;
2094 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2096 rec = (struct record_diskdrive *)(table->data + offset);
2097 sprintfW( device_id, fmtW, index );
2098 rec->device_id = heap_strdupW( device_id );
2099 rec->index = index;
2100 rec->interfacetype = diskdrive_interfacetypeW;
2101 rec->manufacturer = diskdrive_manufacturerW;
2102 if (type == DRIVE_FIXED)
2103 rec->mediatype = diskdrive_mediatype_fixedW;
2104 else
2105 rec->mediatype = diskdrive_mediatype_removableW;
2106 rec->model = diskdrive_modelW;
2107 rec->pnpdevice_id = diskdrive_pnpdeviceidW;
2108 rec->serialnumber = diskdrive_serialW;
2109 get_freespace( root, &size );
2110 rec->size = size;
2111 if (!match_row( table, row, cond, &status ))
2113 free_row_values( table, row );
2114 continue;
2116 offset += sizeof(*rec);
2117 index++;
2118 row++;
2121 TRACE("created %u rows\n", row);
2122 table->num_rows = row;
2123 return status;
2126 static WCHAR *get_filesystem( const WCHAR *root )
2128 static const WCHAR ntfsW[] = {'N','T','F','S',0};
2129 WCHAR buffer[MAX_PATH + 1];
2131 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
2132 return heap_strdupW( buffer );
2133 return heap_strdupW( ntfsW );
2136 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
2138 static const WCHAR fmtW[] =
2139 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
2140 WCHAR device_id[32], root[] = {'A',':','\\',0};
2141 struct record_diskpartition *rec;
2142 UINT i, row = 0, offset = 0, type, index = 0;
2143 UINT64 size = 1024 * 1024 * 1024;
2144 DWORD drives = GetLogicalDrives();
2145 enum fill_status status = FILL_STATUS_UNFILTERED;
2147 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2149 for (i = 0; i < 26; i++)
2151 if (drives & (1 << i))
2153 root[0] = 'A' + i;
2154 type = GetDriveTypeW( root );
2155 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
2156 continue;
2158 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2160 rec = (struct record_diskpartition *)(table->data + offset);
2161 rec->bootable = (i == 2) ? -1 : 0;
2162 rec->bootpartition = (i == 2) ? -1 : 0;
2163 sprintfW( device_id, fmtW, index );
2164 rec->device_id = heap_strdupW( device_id );
2165 rec->diskindex = index;
2166 rec->index = 0;
2167 rec->pnpdevice_id = heap_strdupW( device_id );
2168 get_freespace( root, &size );
2169 rec->size = size;
2170 rec->startingoffset = 0;
2171 rec->type = get_filesystem( root );
2172 if (!match_row( table, row, cond, &status ))
2174 free_row_values( table, row );
2175 continue;
2177 offset += sizeof(*rec);
2178 row++;
2179 index++;
2182 TRACE("created %u rows\n", row);
2183 table->num_rows = row;
2184 return status;
2187 static WCHAR *get_ip4_string( DWORD addr )
2189 static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
2190 WCHAR *ret;
2192 if (!(ret = heap_alloc( sizeof("ddd.ddd.ddd.ddd") * sizeof(WCHAR) ))) return NULL;
2193 sprintfW( ret, fmtW, (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff );
2194 return ret;
2197 static enum fill_status fill_ip4routetable( struct table *table, const struct expr *cond )
2199 struct record_ip4routetable *rec;
2200 UINT i, row = 0, offset = 0, size = 0;
2201 MIB_IPFORWARDTABLE *forwards;
2202 enum fill_status status = FILL_STATUS_UNFILTERED;
2204 if (GetIpForwardTable( NULL, &size, TRUE ) != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
2205 if (!(forwards = heap_alloc( size ))) return FILL_STATUS_FAILED;
2206 if (GetIpForwardTable( forwards, &size, TRUE ))
2208 heap_free( forwards );
2209 return FILL_STATUS_FAILED;
2211 if (!resize_table( table, max(forwards->dwNumEntries, 1), sizeof(*rec) ))
2213 heap_free( forwards );
2214 return FILL_STATUS_FAILED;
2217 for (i = 0; i < forwards->dwNumEntries; i++)
2219 rec = (struct record_ip4routetable *)(table->data + offset);
2221 rec->destination = get_ip4_string( ntohl(forwards->table[i].dwForwardDest) );
2222 rec->interfaceindex = forwards->table[i].dwForwardIfIndex;
2223 rec->nexthop = get_ip4_string( ntohl(forwards->table[i].dwForwardNextHop) );
2225 if (!match_row( table, row, cond, &status ))
2227 free_row_values( table, row );
2228 continue;
2230 offset += sizeof(*rec);
2231 row++;
2233 TRACE("created %u rows\n", row);
2234 table->num_rows = row;
2236 heap_free( forwards );
2237 return status;
2240 static WCHAR *get_volumename( const WCHAR *root )
2242 WCHAR buf[MAX_PATH + 1] = {0};
2243 GetVolumeInformationW( root, buf, ARRAY_SIZE( buf ), NULL, NULL, NULL, NULL, 0 );
2244 return heap_strdupW( buf );
2246 static WCHAR *get_volumeserialnumber( const WCHAR *root )
2248 static const WCHAR fmtW[] = {'%','0','8','X',0};
2249 DWORD serial = 0;
2250 WCHAR buffer[9];
2252 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
2253 sprintfW( buffer, fmtW, serial );
2254 return heap_strdupW( buffer );
2257 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
2259 static const WCHAR fmtW[] = {'%','c',':',0};
2260 WCHAR device_id[3], root[] = {'A',':','\\',0};
2261 struct record_logicaldisk *rec;
2262 UINT i, row = 0, offset = 0, type;
2263 UINT64 size = 1024 * 1024 * 1024;
2264 DWORD drives = GetLogicalDrives();
2265 enum fill_status status = FILL_STATUS_UNFILTERED;
2267 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2269 for (i = 0; i < 26; i++)
2271 if (drives & (1 << i))
2273 root[0] = 'A' + i;
2274 type = GetDriveTypeW( root );
2275 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
2276 continue;
2278 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2280 rec = (struct record_logicaldisk *)(table->data + offset);
2281 sprintfW( device_id, fmtW, 'A' + i );
2282 rec->device_id = heap_strdupW( device_id );
2283 rec->drivetype = type;
2284 rec->filesystem = get_filesystem( root );
2285 rec->freespace = get_freespace( root, &size );
2286 rec->name = heap_strdupW( device_id );
2287 rec->size = size;
2288 rec->volumename = get_volumename( root );
2289 rec->volumeserialnumber = get_volumeserialnumber( root );
2290 if (!match_row( table, row, cond, &status ))
2292 free_row_values( table, row );
2293 continue;
2295 offset += sizeof(*rec);
2296 row++;
2299 TRACE("created %u rows\n", row);
2300 table->num_rows = row;
2301 return status;
2304 static UINT16 get_connection_status( IF_OPER_STATUS status )
2306 switch (status)
2308 case IfOperStatusDown:
2309 return 0; /* Disconnected */
2310 case IfOperStatusUp:
2311 return 2; /* Connected */
2312 default:
2313 ERR("unhandled status %u\n", status);
2314 break;
2316 return 0;
2318 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
2320 static const WCHAR fmtW[] =
2321 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
2322 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
2323 WCHAR *ret;
2325 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
2326 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
2327 return ret;
2329 static const WCHAR *get_adaptertype( DWORD type, int *id, int *physical )
2331 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
2332 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
2333 static const WCHAR firewireW[] = {'1','3','9','4',0};
2334 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
2336 switch (type)
2338 case IF_TYPE_ETHERNET_CSMACD:
2339 *id = 0;
2340 *physical = -1;
2341 return ethernetW;
2342 case IF_TYPE_IEEE80211:
2343 *id = 9;
2344 *physical = -1;
2345 return wirelessW;
2346 case IF_TYPE_IEEE1394:
2347 *id = 13;
2348 *physical = -1;
2349 return firewireW;
2350 case IF_TYPE_TUNNEL:
2351 *id = 15;
2352 *physical = 0;
2353 return tunnelW;
2354 default:
2355 *id = -1;
2356 *physical = 0;
2357 return NULL;
2361 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
2363 static const WCHAR fmtW[] = {'%','u',0};
2364 WCHAR device_id[11];
2365 struct record_networkadapter *rec;
2366 IP_ADAPTER_ADDRESSES *aa, *buffer;
2367 UINT row = 0, offset = 0, count = 0;
2368 DWORD size = 0, ret;
2369 int adaptertypeid, physical;
2370 enum fill_status status = FILL_STATUS_UNFILTERED;
2372 ret = GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, NULL, &size );
2373 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2375 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2376 if (GetAdaptersAddresses( WS_AF_UNSPEC, 0, NULL, buffer, &size ))
2378 heap_free( buffer );
2379 return FILL_STATUS_FAILED;
2381 for (aa = buffer; aa; aa = aa->Next)
2383 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
2385 if (!resize_table( table, count, sizeof(*rec) ))
2387 heap_free( buffer );
2388 return FILL_STATUS_FAILED;
2390 for (aa = buffer; aa; aa = aa->Next)
2392 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2394 rec = (struct record_networkadapter *)(table->data + offset);
2395 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
2396 rec->adaptertype = get_adaptertype( aa->IfType, &adaptertypeid, &physical );
2397 rec->adaptertypeid = adaptertypeid;
2398 rec->description = heap_strdupW( aa->Description );
2399 rec->device_id = heap_strdupW( device_id );
2400 rec->index = aa->u.s.IfIndex;
2401 rec->interface_index = aa->u.s.IfIndex;
2402 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2403 rec->manufacturer = compsys_manufacturerW;
2404 rec->name = heap_strdupW( aa->FriendlyName );
2405 rec->netconnection_status = get_connection_status( aa->OperStatus );
2406 rec->physicaladapter = physical;
2407 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
2408 rec->speed = 1000000;
2409 if (!match_row( table, row, cond, &status ))
2411 free_row_values( table, row );
2412 continue;
2414 offset += sizeof(*rec);
2415 row++;
2417 TRACE("created %u rows\n", row);
2418 table->num_rows = row;
2420 heap_free( buffer );
2421 return status;
2424 static WCHAR *get_dnshostname( IP_ADAPTER_UNICAST_ADDRESS *addr )
2426 const SOCKET_ADDRESS *sa = &addr->Address;
2427 WCHAR buf[WS_NI_MAXHOST];
2429 if (!addr) return NULL;
2430 if (GetNameInfoW( sa->lpSockaddr, sa->iSockaddrLength, buf, ARRAY_SIZE( buf ), NULL,
2431 0, WS_NI_NAMEREQD )) return NULL;
2432 return heap_strdupW( buf );
2434 static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list )
2436 IP_ADAPTER_GATEWAY_ADDRESS *gateway;
2437 struct array *ret;
2438 ULONG buflen, i = 0, count = 0;
2439 WCHAR **ptr, buf[54]; /* max IPv6 address length */
2441 if (!list) return NULL;
2442 for (gateway = list; gateway; gateway = gateway->Next) count++;
2444 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2445 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2447 heap_free( ret );
2448 return NULL;
2450 for (gateway = list; gateway; gateway = gateway->Next)
2452 buflen = ARRAY_SIZE( buf );
2453 if (WSAAddressToStringW( gateway->Address.lpSockaddr, gateway->Address.iSockaddrLength,
2454 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2456 for (; i > 0; i--) heap_free( ptr[i - 1] );
2457 heap_free( ptr );
2458 heap_free( ret );
2459 return NULL;
2462 ret->count = count;
2463 ret->ptr = ptr;
2464 return ret;
2466 static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list )
2468 IP_ADAPTER_DNS_SERVER_ADDRESS *server;
2469 struct array *ret;
2470 ULONG buflen, i = 0, count = 0;
2471 WCHAR **ptr, *p, buf[54]; /* max IPv6 address length */
2473 if (!list) return NULL;
2474 for (server = list; server; server = server->Next) count++;
2476 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2477 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2479 heap_free( ret );
2480 return NULL;
2482 for (server = list; server; server = server->Next)
2484 buflen = ARRAY_SIZE( buf );
2485 if (WSAAddressToStringW( server->Address.lpSockaddr, server->Address.iSockaddrLength,
2486 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2488 for (; i > 0; i--) heap_free( ptr[i - 1] );
2489 heap_free( ptr );
2490 heap_free( ret );
2491 return NULL;
2493 if ((p = strrchrW( ptr[i - 1], ':' ))) *p = 0;
2495 ret->count = count;
2496 ret->ptr = ptr;
2497 return ret;
2499 static struct array *get_ipaddress( IP_ADAPTER_UNICAST_ADDRESS_LH *list )
2501 IP_ADAPTER_UNICAST_ADDRESS_LH *address;
2502 struct array *ret;
2503 ULONG buflen, i = 0, count = 0;
2504 WCHAR **ptr, buf[54]; /* max IPv6 address length */
2506 if (!list) return NULL;
2507 for (address = list; address; address = address->Next) count++;
2509 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2510 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2512 heap_free( ret );
2513 return NULL;
2515 for (address = list; address; address = address->Next)
2517 buflen = ARRAY_SIZE( buf );
2518 if (WSAAddressToStringW( address->Address.lpSockaddr, address->Address.iSockaddrLength,
2519 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
2521 for (; i > 0; i--) heap_free( ptr[i - 1] );
2522 heap_free( ptr );
2523 heap_free( ret );
2524 return NULL;
2527 ret->count = count;
2528 ret->ptr = ptr;
2529 return ret;
2531 static struct array *get_ipsubnet( IP_ADAPTER_UNICAST_ADDRESS_LH *list )
2533 IP_ADAPTER_UNICAST_ADDRESS_LH *address;
2534 struct array *ret;
2535 ULONG i = 0, count = 0;
2536 WCHAR **ptr;
2538 if (!list) return NULL;
2539 for (address = list; address; address = address->Next) count++;
2541 if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
2542 if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
2544 heap_free( ret );
2545 return NULL;
2547 for (address = list; address; address = address->Next)
2549 if (address->Address.lpSockaddr->sa_family == WS_AF_INET)
2551 WCHAR buf[INET_ADDRSTRLEN];
2552 SOCKADDR_IN addr;
2553 ULONG buflen = ARRAY_SIZE( buf );
2555 memset( &addr, 0, sizeof(addr) );
2556 addr.sin_family = WS_AF_INET;
2557 if (ConvertLengthToIpv4Mask( address->OnLinkPrefixLength, &addr.sin_addr.S_un.S_addr ) != NO_ERROR
2558 || WSAAddressToStringW( (SOCKADDR*)&addr, sizeof(addr), NULL, buf, &buflen))
2559 ptr[i] = NULL;
2560 else
2561 ptr[i] = heap_strdupW( buf );
2563 else
2565 static const WCHAR fmtW[] = {'%','u',0};
2566 WCHAR buf[11];
2568 sprintfW(buf, fmtW, address->OnLinkPrefixLength);
2569 ptr[i] = heap_strdupW( buf );
2571 if (!ptr[i++])
2573 for (; i > 0; i--) heap_free( ptr[i - 1] );
2574 heap_free( ptr );
2575 heap_free( ret );
2576 return NULL;
2579 ret->count = count;
2580 ret->ptr = ptr;
2581 return ret;
2583 static WCHAR *get_settingid( UINT32 index )
2585 GUID guid;
2586 WCHAR *ret, *str;
2587 memset( &guid, 0, sizeof(guid) );
2588 guid.Data1 = index;
2589 UuidToStringW( &guid, &str );
2590 ret = heap_strdupW( str );
2591 RpcStringFreeW( &str );
2592 return ret;
2595 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
2597 struct record_networkadapterconfig *rec;
2598 IP_ADAPTER_ADDRESSES *aa, *buffer;
2599 UINT row = 0, offset = 0, count = 0;
2600 DWORD size = 0, ret;
2601 enum fill_status status = FILL_STATUS_UNFILTERED;
2603 ret = GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &size );
2604 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
2606 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
2607 if (GetAdaptersAddresses( WS_AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, buffer, &size ))
2609 heap_free( buffer );
2610 return FILL_STATUS_FAILED;
2612 for (aa = buffer; aa; aa = aa->Next)
2614 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
2616 if (!resize_table( table, count, sizeof(*rec) ))
2618 heap_free( buffer );
2619 return FILL_STATUS_FAILED;
2621 for (aa = buffer; aa; aa = aa->Next)
2623 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2625 rec = (struct record_networkadapterconfig *)(table->data + offset);
2626 rec->defaultipgateway = get_defaultipgateway( aa->FirstGatewayAddress );
2627 rec->description = heap_strdupW( aa->Description );
2628 rec->dhcpenabled = -1;
2629 rec->dnshostname = get_dnshostname( aa->FirstUnicastAddress );
2630 rec->dnsserversearchorder = get_dnsserversearchorder( aa->FirstDnsServerAddress );
2631 rec->index = aa->u.s.IfIndex;
2632 rec->ipaddress = get_ipaddress( aa->FirstUnicastAddress );
2633 rec->ipconnectionmetric = 20;
2634 rec->ipenabled = -1;
2635 rec->ipsubnet = get_ipsubnet( aa->FirstUnicastAddress );
2636 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
2637 rec->settingid = get_settingid( rec->index );
2638 if (!match_row( table, row, cond, &status ))
2640 free_row_values( table, row );
2641 continue;
2643 offset += sizeof(*rec);
2644 row++;
2646 TRACE("created %u rows\n", row);
2647 table->num_rows = row;
2649 heap_free( buffer );
2650 return status;
2653 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
2655 static const WCHAR dimm0W[] = {'D','I','M','M',' ','0',0};
2656 struct record_physicalmemory *rec;
2657 enum fill_status status = FILL_STATUS_UNFILTERED;
2658 UINT row = 0;
2660 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2662 rec = (struct record_physicalmemory *)table->data;
2663 rec->capacity = get_total_physical_memory();
2664 rec->devicelocator = heap_strdupW( dimm0W );
2665 rec->memorytype = 9; /* RAM */
2666 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2667 else row++;
2669 TRACE("created %u rows\n", row);
2670 table->num_rows = row;
2671 return status;
2674 static enum fill_status fill_pnpentity( struct table *table, const struct expr *cond )
2676 struct record_pnpentity *rec;
2677 enum fill_status status = FILL_STATUS_UNFILTERED;
2678 HDEVINFO device_info_set;
2679 SP_DEVINFO_DATA devinfo = {0};
2680 DWORD idx;
2682 device_info_set = SetupDiGetClassDevsW( NULL, NULL, NULL, DIGCF_ALLCLASSES|DIGCF_PRESENT );
2684 devinfo.cbSize = sizeof(devinfo);
2686 idx = 0;
2687 while (SetupDiEnumDeviceInfo( device_info_set, idx++, &devinfo ))
2689 /* noop */
2692 resize_table( table, idx, sizeof(*rec) );
2693 table->num_rows = 0;
2694 rec = (struct record_pnpentity *)table->data;
2696 idx = 0;
2697 while (SetupDiEnumDeviceInfo( device_info_set, idx++, &devinfo ))
2699 WCHAR device_id[MAX_PATH];
2700 if (SetupDiGetDeviceInstanceIdW( device_info_set, &devinfo, device_id,
2701 ARRAY_SIZE(device_id), NULL ))
2703 rec->device_id = heap_strdupW( device_id );
2705 table->num_rows++;
2706 if (!match_row( table, table->num_rows - 1, cond, &status ))
2708 free_row_values( table, table->num_rows - 1 );
2709 table->num_rows--;
2711 else
2712 rec++;
2716 SetupDiDestroyDeviceInfoList( device_info_set );
2718 return status;
2721 static enum fill_status fill_printer( struct table *table, const struct expr *cond )
2723 static const WCHAR fmtW[] = {'P','r','i','n','t','e','r','%','d',0};
2724 struct record_printer *rec;
2725 enum fill_status status = FILL_STATUS_UNFILTERED;
2726 PRINTER_INFO_2W *info;
2727 DWORD i, offset = 0, count = 0, size = 0, num_rows = 0;
2728 WCHAR id[20];
2730 EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count );
2731 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
2733 if (!(info = heap_alloc( size ))) return FILL_STATUS_FAILED;
2734 if (!EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, (BYTE *)info, size, &size, &count ))
2736 heap_free( info );
2737 return FILL_STATUS_FAILED;
2739 if (!resize_table( table, count, sizeof(*rec) ))
2741 heap_free( info );
2742 return FILL_STATUS_FAILED;
2745 for (i = 0; i < count; i++)
2747 rec = (struct record_printer *)(table->data + offset);
2748 rec->attributes = info[i].Attributes;
2749 sprintfW( id, fmtW, i );
2750 rec->device_id = heap_strdupW( id );
2751 rec->drivername = heap_strdupW( info[i].pDriverName );
2752 rec->horizontalresolution = info[i].pDevMode->u1.s1.dmPrintQuality;
2753 rec->local = -1;
2754 rec->location = heap_strdupW( info[i].pLocation );
2755 rec->name = heap_strdupW( info[i].pPrinterName );
2756 rec->network = 0;
2757 rec->portname = heap_strdupW( info[i].pPortName );
2758 if (!match_row( table, i, cond, &status ))
2760 free_row_values( table, i );
2761 continue;
2763 offset += sizeof(*rec);
2764 num_rows++;
2766 TRACE("created %u rows\n", num_rows);
2767 table->num_rows = num_rows;
2769 heap_free( info );
2770 return status;
2773 static WCHAR *get_cmdline( DWORD process_id )
2775 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
2776 return NULL; /* FIXME handle different process case */
2779 static enum fill_status fill_process( struct table *table, const struct expr *cond )
2781 static const WCHAR fmtW[] = {'%','u',0};
2782 WCHAR handle[11];
2783 struct record_process *rec;
2784 PROCESSENTRY32W entry;
2785 HANDLE snap;
2786 enum fill_status status = FILL_STATUS_FAILED;
2787 UINT row = 0, offset = 0;
2789 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
2790 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
2792 entry.dwSize = sizeof(entry);
2793 if (!Process32FirstW( snap, &entry )) goto done;
2794 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
2798 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
2800 rec = (struct record_process *)(table->data + offset);
2801 rec->caption = heap_strdupW( entry.szExeFile );
2802 rec->commandline = get_cmdline( entry.th32ProcessID );
2803 rec->description = heap_strdupW( entry.szExeFile );
2804 sprintfW( handle, fmtW, entry.th32ProcessID );
2805 rec->handle = heap_strdupW( handle );
2806 rec->name = heap_strdupW( entry.szExeFile );
2807 rec->process_id = entry.th32ProcessID;
2808 rec->pprocess_id = entry.th32ParentProcessID;
2809 rec->thread_count = entry.cntThreads;
2810 rec->workingsetsize = 0;
2811 rec->get_owner = process_get_owner;
2812 if (!match_row( table, row, cond, &status ))
2814 free_row_values( table, row );
2815 continue;
2817 offset += sizeof(*rec);
2818 row++;
2819 } while (Process32NextW( snap, &entry ));
2821 TRACE("created %u rows\n", row);
2822 table->num_rows = row;
2823 status = FILL_STATUS_UNFILTERED;
2825 done:
2826 CloseHandle( snap );
2827 return status;
2830 extern void do_cpuid( unsigned int ax, unsigned int *p );
2831 #if defined(_MSC_VER)
2832 void do_cpuid( unsigned int ax, unsigned int *p )
2834 __cpuid( p, ax );
2836 #elif defined(__i386__)
2837 __ASM_GLOBAL_FUNC( do_cpuid,
2838 "pushl %esi\n\t"
2839 "pushl %ebx\n\t"
2840 "movl 12(%esp),%eax\n\t"
2841 "movl 16(%esp),%esi\n\t"
2842 "cpuid\n\t"
2843 "movl %eax,(%esi)\n\t"
2844 "movl %ebx,4(%esi)\n\t"
2845 "movl %ecx,8(%esi)\n\t"
2846 "movl %edx,12(%esi)\n\t"
2847 "popl %ebx\n\t"
2848 "popl %esi\n\t"
2849 "ret" )
2850 #elif defined(__x86_64__)
2851 __ASM_GLOBAL_FUNC( do_cpuid,
2852 "pushq %rbx\n\t"
2853 "movl %edi,%eax\n\t"
2854 "cpuid\n\t"
2855 "movl %eax,(%rsi)\n\t"
2856 "movl %ebx,4(%rsi)\n\t"
2857 "movl %ecx,8(%rsi)\n\t"
2858 "movl %edx,12(%rsi)\n\t"
2859 "popq %rbx\n\t"
2860 "ret" )
2861 #else
2862 void do_cpuid( unsigned int ax, unsigned int *p )
2864 FIXME("\n");
2866 #endif
2868 static unsigned int get_processor_model( unsigned int reg0, unsigned int *stepping, unsigned int *family )
2870 unsigned int model, family_id = (reg0 & (0x0f << 8)) >> 8;
2872 model = (reg0 & (0x0f << 4)) >> 4;
2873 if (family_id == 6 || family_id == 15) model |= (reg0 & (0x0f << 16)) >> 12;
2874 if (family)
2876 *family = family_id;
2877 if (family_id == 15) *family += (reg0 & (0xff << 20)) >> 20;
2879 *stepping = reg0 & 0x0f;
2880 return model;
2882 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
2884 unsigned int i;
2885 unsigned char *p = (unsigned char *)regs;
2887 for (i = 0; i < len; i++) { buffer[i] = *p++; }
2888 buffer[i] = 0;
2890 static void get_processor_manufacturer( WCHAR *manufacturer )
2892 unsigned int tmp, regs[4] = {0, 0, 0, 0};
2894 do_cpuid( 0, regs );
2895 tmp = regs[2]; /* swap edx and ecx */
2896 regs[2] = regs[3];
2897 regs[3] = tmp;
2899 regs_to_str( regs + 1, 12, manufacturer );
2901 static const WCHAR *get_osarchitecture(void)
2903 SYSTEM_INFO info;
2904 GetNativeSystemInfo( &info );
2905 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
2906 return os_32bitW;
2908 static void get_processor_caption( WCHAR *caption )
2910 static const WCHAR fmtW[] =
2911 {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ',
2912 'M','o','d','e','l',' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
2913 static const WCHAR x86W[] = {'x','8','6',0};
2914 static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0};
2915 static const WCHAR amd64W[] = {'A','M','D','6','4',0};
2916 static const WCHAR authenticamdW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0};
2917 const WCHAR *arch;
2918 WCHAR manufacturer[13];
2919 unsigned int regs[4] = {0, 0, 0, 0}, family, model, stepping;
2921 get_processor_manufacturer( manufacturer );
2922 if (get_osarchitecture() == os_32bitW) arch = x86W;
2923 else if (!strcmpW( manufacturer, authenticamdW )) arch = amd64W;
2924 else arch = intel64W;
2926 do_cpuid( 1, regs );
2928 model = get_processor_model( regs[0], &stepping, &family );
2929 sprintfW( caption, fmtW, arch, family, model, stepping );
2931 static void get_processor_version( WCHAR *version )
2933 static const WCHAR fmtW[] =
2934 {'M','o','d','e','l',' ','%','u',',',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
2935 unsigned int regs[4] = {0, 0, 0, 0}, model, stepping;
2937 do_cpuid( 1, regs );
2939 model = get_processor_model( regs[0], &stepping, NULL );
2940 sprintfW( version, fmtW, model, stepping );
2942 static UINT16 get_processor_revision(void)
2944 unsigned int regs[4] = {0, 0, 0, 0};
2945 do_cpuid( 1, regs );
2946 return regs[0];
2948 static void get_processor_id( WCHAR *processor_id )
2950 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
2951 unsigned int regs[4] = {0, 0, 0, 0};
2953 do_cpuid( 1, regs );
2954 sprintfW( processor_id, fmtW, regs[3], regs[0] );
2956 static void get_processor_name( WCHAR *name )
2958 unsigned int regs[4] = {0, 0, 0, 0};
2959 int i;
2961 do_cpuid( 0x80000000, regs );
2962 if (regs[0] >= 0x80000004)
2964 do_cpuid( 0x80000002, regs );
2965 regs_to_str( regs, 16, name );
2966 do_cpuid( 0x80000003, regs );
2967 regs_to_str( regs, 16, name + 16 );
2968 do_cpuid( 0x80000004, regs );
2969 regs_to_str( regs, 16, name + 32 );
2971 for (i = strlenW(name) - 1; i >= 0 && name[i] == ' '; i--) name[i] = 0;
2973 static UINT get_processor_currentclockspeed( UINT index )
2975 PROCESSOR_POWER_INFORMATION *info;
2976 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2977 NTSTATUS status;
2979 if ((info = heap_alloc( size )))
2981 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2982 if (!status) ret = info[index].CurrentMhz;
2983 heap_free( info );
2985 return ret;
2987 static UINT get_processor_maxclockspeed( UINT index )
2989 PROCESSOR_POWER_INFORMATION *info;
2990 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
2991 NTSTATUS status;
2993 if ((info = heap_alloc( size )))
2995 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
2996 if (!status) ret = info[index].MaxMhz;
2997 heap_free( info );
2999 return ret;
3002 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
3004 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
3005 WCHAR caption[100], device_id[14], processor_id[17], manufacturer[13], name[49] = {0}, version[50];
3006 struct record_processor *rec;
3007 UINT i, offset = 0, num_rows = 0, num_logical, num_physical, num_packages;
3008 enum fill_status status = FILL_STATUS_UNFILTERED;
3010 num_logical = get_logical_processor_count( &num_physical, &num_packages );
3012 if (!resize_table( table, num_packages, sizeof(*rec) )) return FILL_STATUS_FAILED;
3014 get_processor_caption( caption );
3015 get_processor_id( processor_id );
3016 get_processor_manufacturer( manufacturer );
3017 get_processor_name( name );
3018 get_processor_version( version );
3020 for (i = 0; i < num_packages; i++)
3022 rec = (struct record_processor *)(table->data + offset);
3023 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
3024 rec->architecture = get_osarchitecture() == os_32bitW ? 0 : 9;
3025 rec->caption = heap_strdupW( caption );
3026 rec->cpu_status = 1; /* CPU Enabled */
3027 rec->currentclockspeed = get_processor_currentclockspeed( i );
3028 rec->datawidth = get_osarchitecture() == os_32bitW ? 32 : 64;
3029 rec->description = heap_strdupW( caption );
3030 sprintfW( device_id, fmtW, i );
3031 rec->device_id = heap_strdupW( device_id );
3032 rec->family = 2; /* Unknown */
3033 rec->level = 15;
3034 rec->manufacturer = heap_strdupW( manufacturer );
3035 rec->maxclockspeed = get_processor_maxclockspeed( i );
3036 rec->name = heap_strdupW( name );
3037 rec->num_cores = num_physical / num_packages;
3038 rec->num_logical_processors = num_logical / num_packages;
3039 rec->processor_id = heap_strdupW( processor_id );
3040 rec->processortype = 3; /* central processor */
3041 rec->revision = get_processor_revision();
3042 rec->unique_id = NULL;
3043 rec->version = heap_strdupW( version );
3044 if (!match_row( table, i, cond, &status ))
3046 free_row_values( table, i );
3047 continue;
3049 offset += sizeof(*rec);
3050 num_rows++;
3053 TRACE("created %u rows\n", num_rows);
3054 table->num_rows = num_rows;
3055 return status;
3058 static WCHAR *get_lastbootuptime(void)
3060 static const WCHAR fmtW[] =
3061 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
3062 '.','%','0','6','u','+','0','0','0',0};
3063 SYSTEM_TIMEOFDAY_INFORMATION ti;
3064 TIME_FIELDS tf;
3065 WCHAR *ret;
3067 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
3069 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
3070 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
3071 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
3072 return ret;
3074 static WCHAR *get_localdatetime(void)
3076 static const WCHAR fmtW[] =
3077 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
3078 '.','%','0','6','u','%','+','0','3','d',0};
3079 TIME_ZONE_INFORMATION tzi;
3080 SYSTEMTIME st;
3081 WCHAR *ret;
3082 DWORD Status;
3083 LONG Bias;
3085 Status = GetTimeZoneInformation(&tzi);
3087 if(Status == TIME_ZONE_ID_INVALID) return NULL;
3088 Bias = tzi.Bias;
3089 if(Status == TIME_ZONE_ID_DAYLIGHT)
3090 Bias+= tzi.DaylightBias;
3091 else
3092 Bias+= tzi.StandardBias;
3093 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
3095 GetLocalTime(&st);
3096 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
3097 return ret;
3099 static WCHAR *get_systemdirectory(void)
3101 void *redir;
3102 WCHAR *ret;
3104 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
3105 Wow64DisableWow64FsRedirection( &redir );
3106 GetSystemDirectoryW( ret, MAX_PATH );
3107 Wow64RevertWow64FsRedirection( redir );
3108 return ret;
3110 static WCHAR *get_systemdrive(void)
3112 WCHAR *ret = heap_alloc( 3 * sizeof(WCHAR) ); /* "c:" */
3113 if (ret && GetEnvironmentVariableW( prop_systemdriveW, ret, 3 )) return ret;
3114 heap_free( ret );
3115 return NULL;
3117 static WCHAR *get_codeset(void)
3119 static const WCHAR fmtW[] = {'%','u',0};
3120 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
3121 if (ret) sprintfW( ret, fmtW, GetACP() );
3122 return ret;
3124 static WCHAR *get_countrycode(void)
3126 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
3127 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
3128 return ret;
3130 static WCHAR *get_locale(void)
3132 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
3133 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
3134 return ret;
3136 static WCHAR *get_osbuildnumber( OSVERSIONINFOEXW *ver )
3138 static const WCHAR fmtW[] = {'%','u',0};
3139 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
3140 if (ret) sprintfW( ret, fmtW, ver->dwBuildNumber );
3141 return ret;
3143 static WCHAR *get_oscaption( OSVERSIONINFOEXW *ver )
3145 static const WCHAR windowsW[] =
3146 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' '};
3147 static const WCHAR win2000W[] =
3148 {'2','0','0','0',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
3149 static const WCHAR win2003W[] =
3150 {'S','e','r','v','e','r',' ','2','0','0','3',' ','S','t','a','n','d','a','r','d',' ','E','d','i','t','i','o','n',0};
3151 static const WCHAR winxpW[] =
3152 {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
3153 static const WCHAR winxp64W[] =
3154 {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',' ','x','6','4',' ','E','d','i','t','i','o','n',0};
3155 static const WCHAR vistaW[] =
3156 {'V','i','s','t','a',' ','U','l','t','i','m','a','t','e',0};
3157 static const WCHAR win2008W[] =
3158 {'S','e','r','v','e','r',' ','2','0','0','8',' ','S','t','a','n','d','a','r','d',0};
3159 static const WCHAR win7W[] =
3160 {'7',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
3161 static const WCHAR win2008r2W[] =
3162 {'S','e','r','v','e','r',' ','2','0','0','8',' ','R','2',' ','S','t','a','n','d','a','r','d',0};
3163 static const WCHAR win8W[] =
3164 {'8',' ','P','r','o',0};
3165 static const WCHAR win81W[] =
3166 {'8','.','1',' ','P','r','o',0};
3167 static const WCHAR win10W[] =
3168 {'1','0',' ','P','r','o',0};
3169 int len = ARRAY_SIZE( windowsW );
3170 WCHAR *ret;
3172 if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(win2003W) ))) return NULL;
3173 memcpy( ret, windowsW, sizeof(windowsW) );
3174 if (ver->dwMajorVersion == 10 && ver->dwMinorVersion == 0) memcpy( ret + len, win10W, sizeof(win10W) );
3175 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 3) memcpy( ret + len, win8W, sizeof(win8W) );
3176 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 2) memcpy( ret + len, win81W, sizeof(win81W) );
3177 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 1)
3179 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, win7W, sizeof(win7W) );
3180 else memcpy( ret + len, win2008r2W, sizeof(win2008r2W) );
3182 else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 0)
3184 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, vistaW, sizeof(vistaW) );
3185 else memcpy( ret + len, win2008W, sizeof(win2008W) );
3187 else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 2)
3189 if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, winxp64W, sizeof(winxp64W) );
3190 else memcpy( ret + len, win2003W, sizeof(win2003W) );
3192 else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 1) memcpy( ret + len, winxpW, sizeof(winxpW) );
3193 else memcpy( ret + len, win2000W, sizeof(win2000W) );
3194 return ret;
3196 static WCHAR *get_osname( const WCHAR *caption )
3198 static const WCHAR partitionW[] =
3199 {'|','C',':','\\','W','I','N','D','O','W','S','|','\\','D','e','v','i','c','e','\\',
3200 'H','a','r','d','d','i','s','k','0','\\','P','a','r','t','i','t','i','o','n','1',0};
3201 int len = strlenW( caption );
3202 WCHAR *ret;
3204 if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(partitionW) ))) return NULL;
3205 memcpy( ret, caption, len * sizeof(WCHAR) );
3206 memcpy( ret + len, partitionW, sizeof(partitionW) );
3207 return ret;
3209 static WCHAR *get_osversion( OSVERSIONINFOEXW *ver )
3211 static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u',0};
3212 WCHAR *ret = heap_alloc( 33 * sizeof(WCHAR) );
3213 if (ret) sprintfW( ret, fmtW, ver->dwMajorVersion, ver->dwMinorVersion, ver->dwBuildNumber );
3214 return ret;
3216 static DWORD get_operatingsystemsku(void)
3218 DWORD ret = PRODUCT_UNDEFINED;
3219 GetProductInfo( 6, 0, 0, 0, &ret );
3220 return ret;
3223 static enum fill_status fill_os( struct table *table, const struct expr *cond )
3225 struct record_operatingsystem *rec;
3226 enum fill_status status = FILL_STATUS_UNFILTERED;
3227 OSVERSIONINFOEXW ver;
3228 UINT row = 0;
3230 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3232 ver.dwOSVersionInfoSize = sizeof(ver);
3233 GetVersionExW( (OSVERSIONINFOW *)&ver );
3235 rec = (struct record_operatingsystem *)table->data;
3236 rec->buildnumber = get_osbuildnumber( &ver );
3237 rec->caption = get_oscaption( &ver );
3238 rec->codeset = get_codeset();
3239 rec->countrycode = get_countrycode();
3240 rec->csdversion = ver.szCSDVersion[0] ? heap_strdupW( ver.szCSDVersion ) : NULL;
3241 rec->freephysicalmemory = get_available_physical_memory() / 1024;
3242 rec->installdate = os_installdateW;
3243 rec->lastbootuptime = get_lastbootuptime();
3244 rec->localdatetime = get_localdatetime();
3245 rec->locale = get_locale();
3246 rec->name = get_osname( rec->caption );
3247 rec->operatingsystemsku = get_operatingsystemsku();
3248 rec->osarchitecture = get_osarchitecture();
3249 rec->oslanguage = GetSystemDefaultLangID();
3250 rec->osproductsuite = 2461140; /* Windows XP Professional */
3251 rec->ostype = 18; /* WINNT */
3252 rec->primary = -1;
3253 rec->serialnumber = os_serialnumberW;
3254 rec->servicepackmajor = ver.wServicePackMajor;
3255 rec->servicepackminor = ver.wServicePackMinor;
3256 rec->suitemask = 272; /* Single User + Terminal */
3257 rec->systemdirectory = get_systemdirectory();
3258 rec->systemdrive = get_systemdrive();
3259 rec->totalvirtualmemorysize = get_total_physical_memory() / 1024;
3260 rec->totalvisiblememorysize = rec->totalvirtualmemorysize;
3261 rec->version = get_osversion( &ver );
3262 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
3263 else row++;
3265 TRACE("created %u rows\n", row);
3266 table->num_rows = row;
3267 return status;
3270 static const WCHAR *get_service_type( DWORD type )
3272 static const WCHAR filesystem_driverW[] =
3273 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
3274 static const WCHAR kernel_driverW[] =
3275 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
3276 static const WCHAR own_processW[] =
3277 {'O','w','n',' ','P','r','o','c','e','s','s',0};
3278 static const WCHAR share_processW[] =
3279 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
3281 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
3282 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
3283 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
3284 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
3285 else ERR("unhandled type 0x%08x\n", type);
3286 return NULL;
3288 static const WCHAR *get_service_state( DWORD state )
3290 static const WCHAR runningW[] =
3291 {'R','u','n','n','i','n','g',0};
3292 static const WCHAR start_pendingW[] =
3293 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
3294 static const WCHAR stop_pendingW[] =
3295 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
3296 static const WCHAR stoppedW[] =
3297 {'S','t','o','p','p','e','d',0};
3298 static const WCHAR unknownW[] =
3299 {'U','n','k','n','o','w','n',0};
3301 switch (state)
3303 case SERVICE_STOPPED: return stoppedW;
3304 case SERVICE_START_PENDING: return start_pendingW;
3305 case SERVICE_STOP_PENDING: return stop_pendingW;
3306 case SERVICE_RUNNING: return runningW;
3307 default:
3308 ERR("unknown state %u\n", state);
3309 return unknownW;
3312 static const WCHAR *get_service_startmode( DWORD mode )
3314 static const WCHAR bootW[] = {'B','o','o','t',0};
3315 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
3316 static const WCHAR autoW[] = {'A','u','t','o',0};
3317 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
3318 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
3319 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
3321 switch (mode)
3323 case SERVICE_BOOT_START: return bootW;
3324 case SERVICE_SYSTEM_START: return systemW;
3325 case SERVICE_AUTO_START: return autoW;
3326 case SERVICE_DEMAND_START: return manualW;
3327 case SERVICE_DISABLED: return disabledW;
3328 default:
3329 ERR("unknown mode 0x%x\n", mode);
3330 return unknownW;
3333 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
3335 QUERY_SERVICE_CONFIGW *config = NULL;
3336 SC_HANDLE service;
3337 DWORD size;
3339 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
3340 QueryServiceConfigW( service, NULL, 0, &size );
3341 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
3342 if (!(config = heap_alloc( size ))) goto done;
3343 if (QueryServiceConfigW( service, config, size, &size )) goto done;
3344 heap_free( config );
3345 config = NULL;
3347 done:
3348 CloseServiceHandle( service );
3349 return config;
3352 static enum fill_status fill_service( struct table *table, const struct expr *cond )
3354 struct record_service *rec;
3355 SC_HANDLE manager;
3356 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
3357 SERVICE_STATUS_PROCESS *status;
3358 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
3359 DWORD len = ARRAY_SIZE( sysnameW );
3360 UINT i, row = 0, offset = 0, size = 256, needed, count;
3361 enum fill_status fill_status = FILL_STATUS_FAILED;
3362 BOOL ret;
3364 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
3365 if (!(services = heap_alloc( size ))) goto done;
3367 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
3368 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
3369 &count, NULL, NULL );
3370 if (!ret)
3372 if (GetLastError() != ERROR_MORE_DATA) goto done;
3373 size = needed;
3374 if (!(tmp = heap_realloc( services, size ))) goto done;
3375 services = tmp;
3376 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
3377 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
3378 &count, NULL, NULL );
3379 if (!ret) goto done;
3381 if (!resize_table( table, count, sizeof(*rec) )) goto done;
3383 GetComputerNameW( sysnameW, &len );
3384 fill_status = FILL_STATUS_UNFILTERED;
3386 for (i = 0; i < count; i++)
3388 QUERY_SERVICE_CONFIGW *config;
3390 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
3392 status = &services[i].ServiceStatusProcess;
3393 rec = (struct record_service *)(table->data + offset);
3394 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
3395 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
3396 rec->displayname = heap_strdupW( services[i].lpDisplayName );
3397 rec->name = heap_strdupW( services[i].lpServiceName );
3398 rec->process_id = status->dwProcessId;
3399 rec->servicetype = get_service_type( status->dwServiceType );
3400 rec->startmode = get_service_startmode( config->dwStartType );
3401 rec->state = get_service_state( status->dwCurrentState );
3402 rec->systemname = heap_strdupW( sysnameW );
3403 rec->pause_service = service_pause_service;
3404 rec->resume_service = service_resume_service;
3405 rec->start_service = service_start_service;
3406 rec->stop_service = service_stop_service;
3407 heap_free( config );
3408 if (!match_row( table, row, cond, &fill_status ))
3410 free_row_values( table, row );
3411 continue;
3413 offset += sizeof(*rec);
3414 row++;
3417 TRACE("created %u rows\n", row);
3418 table->num_rows = row;
3420 done:
3421 CloseServiceHandle( manager );
3422 heap_free( services );
3423 return fill_status;
3426 static WCHAR *get_accountname( LSA_TRANSLATED_NAME *name )
3428 if (!name || !name->Name.Buffer) return NULL;
3429 return heap_strdupW( name->Name.Buffer );
3431 static struct array *get_binaryrepresentation( PSID sid, UINT len )
3433 struct array *array = heap_alloc( sizeof(struct array) );
3434 if (array)
3436 UINT8 *ret = heap_alloc( len );
3437 if (ret)
3439 memcpy( ret, sid, len );
3440 array->count = len;
3441 array->ptr = ret;
3442 return array;
3444 heap_free( array );
3446 return NULL;
3448 static WCHAR *get_referenceddomainname( LSA_REFERENCED_DOMAIN_LIST *domain )
3450 if (!domain || !domain->Domains || !domain->Domains->Name.Buffer) return NULL;
3451 return heap_strdupW( domain->Domains->Name.Buffer );
3453 static const WCHAR *find_sid_str( const struct expr *cond )
3455 const struct expr *left, *right;
3456 const WCHAR *ret = NULL;
3458 if (!cond || cond->type != EXPR_COMPLEX || cond->u.expr.op != OP_EQ) return NULL;
3460 left = cond->u.expr.left;
3461 right = cond->u.expr.right;
3462 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL && !strcmpiW( left->u.propval->name, prop_sidW ))
3464 ret = right->u.sval;
3466 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL && !strcmpiW( right->u.propval->name, prop_sidW ))
3468 ret = left->u.sval;
3470 return ret;
3473 static enum fill_status fill_sid( struct table *table, const struct expr *cond )
3475 PSID sid;
3476 LSA_REFERENCED_DOMAIN_LIST *domain;
3477 LSA_TRANSLATED_NAME *name;
3478 LSA_HANDLE handle;
3479 LSA_OBJECT_ATTRIBUTES attrs;
3480 const WCHAR *str;
3481 struct record_sid *rec;
3482 UINT len;
3484 if (!(str = find_sid_str( cond ))) return FILL_STATUS_FAILED;
3485 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3487 if (!ConvertStringSidToSidW( str, &sid )) return FILL_STATUS_FAILED;
3488 len = GetLengthSid( sid );
3490 memset( &attrs, 0, sizeof(attrs) );
3491 attrs.Length = sizeof(attrs);
3492 if (LsaOpenPolicy( NULL, &attrs, POLICY_ALL_ACCESS, &handle ))
3494 LocalFree( sid );
3495 return FILL_STATUS_FAILED;
3497 if (LsaLookupSids( handle, 1, &sid, &domain, &name ))
3499 LocalFree( sid );
3500 LsaClose( handle );
3501 return FILL_STATUS_FAILED;
3504 rec = (struct record_sid *)table->data;
3505 rec->accountname = get_accountname( name );
3506 rec->binaryrepresentation = get_binaryrepresentation( sid, len );
3507 rec->referenceddomainname = get_referenceddomainname( domain );
3508 rec->sid = heap_strdupW( str );
3509 rec->sidlength = len;
3511 TRACE("created 1 row\n");
3512 table->num_rows = 1;
3514 LsaFreeMemory( domain );
3515 LsaFreeMemory( name );
3516 LocalFree( sid );
3517 LsaClose( handle );
3518 return FILL_STATUS_FILTERED;
3521 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
3523 HDC hdc = GetDC( NULL );
3524 UINT32 ret;
3526 if (!hdc) return 32;
3527 ret = GetDeviceCaps( hdc, BITSPIXEL );
3528 *hres = GetDeviceCaps( hdc, HORZRES );
3529 *vres = GetDeviceCaps( hdc, VERTRES );
3530 ReleaseDC( NULL, hdc );
3531 return ret;
3533 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
3535 static const WCHAR fmtW[] =
3536 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
3537 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
3538 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
3539 WCHAR *ret;
3541 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
3542 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
3543 return ret;
3546 #define HW_VENDOR_AMD 0x1002
3547 #define HW_VENDOR_NVIDIA 0x10de
3548 #define HW_VENDOR_VMWARE 0x15ad
3549 #define HW_VENDOR_INTEL 0x8086
3551 static const WCHAR *get_installeddriver( UINT vendorid )
3553 static const WCHAR driver_amdW[] = {'a','t','i','c','f','x','3','2','.','d','l','l',0};
3554 static const WCHAR driver_intelW[] = {'i','g','d','u','m','d','i','m','3','2','.','d','l','l',0};
3555 static const WCHAR driver_nvidiaW[] = {'n','v','d','3','d','u','m','.','d','l','l',0};
3556 static const WCHAR driver_wineW[] = {'w','i','n','e','.','d','l','l',0};
3558 /* FIXME: wined3d has a better table, but we cannot access this information through dxgi */
3560 if (vendorid == HW_VENDOR_AMD)
3561 return driver_amdW;
3562 else if (vendorid == HW_VENDOR_NVIDIA)
3563 return driver_nvidiaW;
3564 else if (vendorid == HW_VENDOR_INTEL)
3565 return driver_intelW;
3566 return driver_wineW;
3569 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
3571 static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0};
3572 struct record_videocontroller *rec;
3573 HRESULT hr;
3574 IDXGIFactory *factory = NULL;
3575 IDXGIAdapter *adapter = NULL;
3576 DXGI_ADAPTER_DESC desc;
3577 UINT row = 0, hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
3578 const WCHAR *name = videocontroller_deviceidW;
3579 enum fill_status status = FILL_STATUS_UNFILTERED;
3580 WCHAR mode[44];
3582 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3584 memset (&desc, 0, sizeof(desc));
3585 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
3586 if (FAILED(hr)) goto done;
3588 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
3589 if (FAILED(hr)) goto done;
3591 hr = IDXGIAdapter_GetDesc( adapter, &desc );
3592 if (SUCCEEDED(hr))
3594 vidmem = desc.DedicatedVideoMemory;
3595 name = desc.Description;
3598 done:
3599 rec = (struct record_videocontroller *)table->data;
3600 rec->adapter_dactype = videocontroller_dactypeW;
3601 rec->adapter_ram = vidmem;
3602 rec->availability = 3; /* Running or Full Power */
3603 rec->config_errorcode = 0; /* no error */
3604 rec->caption = heap_strdupW( name );
3605 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
3606 rec->current_horizontalres = hres;
3607 rec->current_refreshrate = 0; /* default refresh rate */
3608 rec->current_scanmode = 2; /* Unknown */
3609 rec->current_verticalres = vres;
3610 rec->description = heap_strdupW( name );
3611 rec->device_id = videocontroller_deviceidW;
3612 rec->driverdate = videocontroller_driverdateW;
3613 rec->driverversion = videocontroller_driverversionW;
3614 rec->installeddriver = get_installeddriver( desc.VendorId );
3615 rec->name = heap_strdupW( name );
3616 rec->pnpdevice_id = get_pnpdeviceid( &desc );
3617 rec->status = videocontroller_statusW;
3618 rec->videoarchitecture = 2; /* Unknown */
3619 rec->videomemorytype = 2; /* Unknown */
3620 wsprintfW( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel );
3621 rec->videomodedescription = heap_strdupW( mode );
3622 rec->videoprocessor = heap_strdupW( name );
3623 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
3624 else row++;
3626 TRACE("created %u rows\n", row);
3627 table->num_rows = row;
3629 if (adapter) IDXGIAdapter_Release( adapter );
3630 if (factory) IDXGIFactory_Release( factory );
3631 return status;
3634 static struct table builtin_classes[] =
3636 { class_baseboardW, ARRAY_SIZE(col_baseboard), col_baseboard, ARRAY_SIZE(data_baseboard), 0, (BYTE *)data_baseboard },
3637 { class_biosW, ARRAY_SIZE(col_bios), col_bios, ARRAY_SIZE(data_bios), 0, (BYTE *)data_bios },
3638 { class_cdromdriveW, ARRAY_SIZE(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
3639 { class_compsysW, ARRAY_SIZE(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
3640 { class_compsysproductW, ARRAY_SIZE(col_compsysproduct), col_compsysproduct, 0, 0, NULL, fill_compsysproduct },
3641 { class_datafileW, ARRAY_SIZE(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
3642 { class_desktopmonitorW, ARRAY_SIZE(col_desktopmonitor), col_desktopmonitor, 0, 0, NULL, fill_desktopmonitor },
3643 { class_directoryW, ARRAY_SIZE(col_directory), col_directory, 0, 0, NULL, fill_directory },
3644 { class_diskdriveW, ARRAY_SIZE(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
3645 { class_diskpartitionW, ARRAY_SIZE(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
3646 { class_ip4routetableW, ARRAY_SIZE(col_ip4routetable), col_ip4routetable, 0, 0, NULL, fill_ip4routetable },
3647 { class_logicaldiskW, ARRAY_SIZE(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
3648 { class_logicaldisk2W, ARRAY_SIZE(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
3649 { class_networkadapterW, ARRAY_SIZE(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
3650 { class_networkadapterconfigW, ARRAY_SIZE(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL, fill_networkadapterconfig },
3651 { class_osW, ARRAY_SIZE(col_os), col_os, 0, 0, NULL, fill_os },
3652 { class_paramsW, ARRAY_SIZE(col_param), col_param, ARRAY_SIZE(data_param), 0, (BYTE *)data_param },
3653 { class_physicalmediaW, ARRAY_SIZE(col_physicalmedia), col_physicalmedia, ARRAY_SIZE(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
3654 { class_physicalmemoryW, ARRAY_SIZE(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
3655 { class_pnpentityW, ARRAY_SIZE(col_pnpentity), col_pnpentity, 0, 0, NULL, fill_pnpentity },
3656 { class_printerW, ARRAY_SIZE(col_printer), col_printer, 0, 0, NULL, fill_printer },
3657 { class_processW, ARRAY_SIZE(col_process), col_process, 0, 0, NULL, fill_process },
3658 { class_processorW, ARRAY_SIZE(col_processor), col_processor, 0, 0, NULL, fill_processor },
3659 { class_processor2W, ARRAY_SIZE(col_processor), col_processor, 0, 0, NULL, fill_processor },
3660 { class_qualifiersW, ARRAY_SIZE(col_qualifier), col_qualifier, ARRAY_SIZE(data_qualifier), 0, (BYTE *)data_qualifier },
3661 { class_serviceW, ARRAY_SIZE(col_service), col_service, 0, 0, NULL, fill_service },
3662 { class_sidW, ARRAY_SIZE(col_sid), col_sid, 0, 0, NULL, fill_sid },
3663 { class_sounddeviceW, ARRAY_SIZE(col_sounddevice), col_sounddevice, ARRAY_SIZE(data_sounddevice), 0, (BYTE *)data_sounddevice },
3664 { class_stdregprovW, ARRAY_SIZE(col_stdregprov), col_stdregprov, ARRAY_SIZE(data_stdregprov), 0, (BYTE *)data_stdregprov },
3665 { class_systemsecurityW, ARRAY_SIZE(col_systemsecurity), col_systemsecurity, ARRAY_SIZE(data_systemsecurity), 0, (BYTE *)data_systemsecurity },
3666 { class_systemenclosureW, ARRAY_SIZE(col_systemenclosure), col_systemenclosure, ARRAY_SIZE(data_systemenclosure), 0, (BYTE *)data_systemenclosure },
3667 { class_videocontrollerW, ARRAY_SIZE(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
3670 void init_table_list( void )
3672 static struct list tables = LIST_INIT( tables );
3673 UINT i;
3675 for (i = 0; i < ARRAY_SIZE(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
3676 table_list = &tables;