VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp@ 17323

Last change on this file since 17323 was 17323, checked in by vboxsync, 16 years ago

VBoxManage: additional hostif->bridged, hostonly fixes for windows

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 74.0 KB
Line 
1/* $Id: VBoxManageInfo.cpp 17323 2009-03-04 07:34:16Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'showvminfo' command and helper routines.
4 */
5
6/*
7 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef VBOX_ONLY_DOCS
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/com/com.h>
28#include <VBox/com/string.h>
29#include <VBox/com/Guid.h>
30#include <VBox/com/array.h>
31#include <VBox/com/ErrorInfo.h>
32#include <VBox/com/errorprint2.h>
33
34#include <VBox/com/VirtualBox.h>
35
36#include <VBox/log.h>
37#include <iprt/stream.h>
38#include <iprt/time.h>
39#include <iprt/string.h>
40
41#include "VBoxManage.h"
42using namespace com;
43
44
45// funcs
46///////////////////////////////////////////////////////////////////////////////
47
48void showSnapshots(ComPtr<ISnapshot> rootSnapshot, VMINFO_DETAILS details, const Bstr &prefix /* = ""*/, int level /*= 0*/)
49{
50 /* start with the root */
51 Bstr name;
52 Guid uuid;
53 rootSnapshot->COMGETTER(Name)(name.asOutParam());
54 rootSnapshot->COMGETTER(Id)(uuid.asOutParam());
55 if (details == VMINFO_MACHINEREADABLE)
56 {
57 /* print with hierarchical numbering */
58 RTPrintf("SnapshotName%lS=\"%lS\"\n", prefix.raw(), name.raw());
59 RTPrintf("SnapshotUUID%lS=\"%s\"\n", prefix.raw(), uuid.toString().raw());
60 }
61 else
62 {
63 /* print with indentation */
64 RTPrintf(" %lSName: %lS (UUID: %s)\n", prefix.raw(), name.raw(), uuid.toString().raw());
65 }
66
67 /* get the children */
68 SafeIfaceArray <ISnapshot> coll;
69 rootSnapshot->COMGETTER(Children)(ComSafeArrayAsOutParam(coll));
70 if (!coll.isNull())
71 {
72 for (size_t index = 0; index < coll.size(); ++index)
73 {
74 ComPtr<ISnapshot> snapshot = coll[index];
75 if (snapshot)
76 {
77 Bstr newPrefix;
78 if (details == VMINFO_MACHINEREADABLE)
79 newPrefix = Utf8StrFmt("%lS-%d", prefix.raw(), index + 1);
80 else
81 newPrefix = Utf8StrFmt("%lS ", prefix.raw());
82 /* recursive call */
83 showSnapshots(snapshot, details, newPrefix, level + 1);
84 }
85 }
86 }
87}
88
89static void makeTimeStr (char *s, int cb, int64_t millies)
90{
91 RTTIME t;
92 RTTIMESPEC ts;
93
94 RTTimeSpecSetMilli(&ts, millies);
95
96 RTTimeExplode (&t, &ts);
97
98 RTStrPrintf(s, cb, "%04d/%02d/%02d %02d:%02d:%02d UTC",
99 t.i32Year, t.u8Month, t.u8MonthDay,
100 t.u8Hour, t.u8Minute, t.u8Second);
101}
102
103/* Disable global optimizations for MSC 8.0/64 to make it compile in reasonable
104 time. MSC 7.1/32 doesn't have quite as much trouble with it, but still
105 sufficient to qualify for this hack as well since this code isn't performance
106 critical and probably won't gain much from the extra optimizing in real life. */
107#if defined(_MSC_VER)
108# pragma optimize("g", off)
109#endif
110
111HRESULT showVMInfo (ComPtr<IVirtualBox> virtualBox,
112 ComPtr<IMachine> machine,
113 VMINFO_DETAILS details /*= VMINFO_NONE*/,
114 ComPtr<IConsole> console /*= ComPtr <IConsole> ()*/)
115{
116 HRESULT rc;
117
118 /*
119 * The rules for output in -argdump format:
120 * 1) the key part (the [0-9a-zA-Z_]+ string before the '=' delimiter)
121 * is all lowercase for "VBoxManage modifyvm" parameters. Any
122 * other values printed are in CamelCase.
123 * 2) strings (anything non-decimal) are printed surrounded by
124 * double quotes '"'. If the strings themselves contain double
125 * quotes, these characters are escaped by '\'. Any '\' character
126 * in the original string is also escaped by '\'.
127 * 3) numbers (containing just [0-9\-]) are written out unchanged.
128 */
129
130 /** @todo the quoting is not yet implemented! */
131
132 BOOL accessible = FALSE;
133 CHECK_ERROR (machine, COMGETTER(Accessible) (&accessible));
134 CheckComRCReturnRC (rc);
135
136 Guid uuid;
137 rc = machine->COMGETTER(Id) (uuid.asOutParam());
138
139 if (!accessible)
140 {
141 if (details == VMINFO_COMPACT)
142 RTPrintf("\"<inaccessible>\" {%s}\n", uuid.toString().raw());
143 else
144 {
145 if (details == VMINFO_MACHINEREADABLE)
146 RTPrintf("name=\"<inaccessible>\"\n");
147 else
148 RTPrintf ("Name: <inaccessible!>\n");
149 if (details == VMINFO_MACHINEREADABLE)
150 RTPrintf ("UUID=\"%s\"\n", uuid.toString().raw());
151 else
152 RTPrintf ("UUID: %s\n", uuid.toString().raw());
153 if (details != VMINFO_MACHINEREADABLE)
154 {
155 Bstr settingsFilePath;
156 rc = machine->COMGETTER(SettingsFilePath) (settingsFilePath.asOutParam());
157 RTPrintf ("Config file: %lS\n", settingsFilePath.raw());
158 ComPtr<IVirtualBoxErrorInfo> accessError;
159 rc = machine->COMGETTER(AccessError) (accessError.asOutParam());
160 RTPrintf ("Access error details:\n");
161 ErrorInfo ei (accessError);
162 GluePrintErrorInfo(ei);
163 RTPrintf ("\n");
164 }
165 }
166 return S_OK;
167 }
168
169 Bstr machineName;
170 rc = machine->COMGETTER(Name)(machineName.asOutParam());
171
172 if (details == VMINFO_COMPACT)
173 {
174 RTPrintf("\"%lS\" {%s}\n", machineName.raw(), uuid.toString().raw());
175 return S_OK;
176 }
177
178 if (details == VMINFO_MACHINEREADABLE)
179 RTPrintf("name=\"%lS\"\n", machineName.raw());
180 else
181 RTPrintf("Name: %lS\n", machineName.raw());
182
183 Bstr osTypeId;
184 rc = machine->COMGETTER(OSTypeId)(osTypeId.asOutParam());
185 ComPtr<IGuestOSType> osType;
186 rc = virtualBox->GetGuestOSType (osTypeId, osType.asOutParam());
187 Bstr osName;
188 rc = osType->COMGETTER(Description)(osName.asOutParam());
189 if (details == VMINFO_MACHINEREADABLE)
190 RTPrintf("ostype=\"%lS\"\n", osTypeId.raw());
191 else
192 RTPrintf("Guest OS: %lS\n", osName.raw());
193
194 if (details == VMINFO_MACHINEREADABLE)
195 RTPrintf("UUID=\"%s\"\n", uuid.toString().raw());
196 else
197 RTPrintf("UUID: %s\n", uuid.toString().raw());
198
199 Bstr settingsFilePath;
200 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
201 if (details == VMINFO_MACHINEREADABLE)
202 RTPrintf("CfgFile=\"%lS\"\n", settingsFilePath.raw());
203 else
204 RTPrintf("Config file: %lS\n", settingsFilePath.raw());
205
206 ULONG memorySize;
207 rc = machine->COMGETTER(MemorySize)(&memorySize);
208 if (details == VMINFO_MACHINEREADABLE)
209 RTPrintf("memory=%u\n", memorySize);
210 else
211 RTPrintf("Memory size: %uMB\n", memorySize);
212
213 ULONG vramSize;
214 rc = machine->COMGETTER(VRAMSize)(&vramSize);
215 if (details == VMINFO_MACHINEREADABLE)
216 RTPrintf("vram=%u\n", vramSize);
217 else
218 RTPrintf("VRAM size: %uMB\n", vramSize);
219
220 ComPtr <IBIOSSettings> biosSettings;
221 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
222
223 BIOSBootMenuMode_T bootMenuMode;
224 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
225 const char *pszBootMenu = NULL;
226 switch (bootMenuMode)
227 {
228 case BIOSBootMenuMode_Disabled:
229 pszBootMenu = "disabled";
230 break;
231 case BIOSBootMenuMode_MenuOnly:
232 if (details == VMINFO_MACHINEREADABLE)
233 pszBootMenu = "menuonly";
234 else
235 pszBootMenu = "menu only";
236 break;
237 default:
238 if (details == VMINFO_MACHINEREADABLE)
239 pszBootMenu = "messageandmenu";
240 else
241 pszBootMenu = "message and menu";
242 }
243 if (details == VMINFO_MACHINEREADABLE)
244 RTPrintf("bootmenu=\"%s\"\n", pszBootMenu);
245 else
246 RTPrintf("Boot menu mode: %s\n", pszBootMenu);
247
248 BOOL acpiEnabled;
249 biosSettings->COMGETTER(ACPIEnabled)(&acpiEnabled);
250 if (details == VMINFO_MACHINEREADABLE)
251 RTPrintf("acpi=\"%s\"\n", acpiEnabled ? "on" : "off");
252 else
253 RTPrintf("ACPI: %s\n", acpiEnabled ? "on" : "off");
254
255 BOOL ioapicEnabled;
256 biosSettings->COMGETTER(IOAPICEnabled)(&ioapicEnabled);
257 if (details == VMINFO_MACHINEREADABLE)
258 RTPrintf("ioapic=\"%s\"\n", ioapicEnabled ? "on" : "off");
259 else
260 RTPrintf("IOAPIC: %s\n", ioapicEnabled ? "on" : "off");
261
262 BOOL PAEEnabled;
263 machine->COMGETTER(PAEEnabled)(&PAEEnabled);
264 if (details == VMINFO_MACHINEREADABLE)
265 RTPrintf("pae=\"%s\"\n", PAEEnabled ? "on" : "off");
266 else
267 RTPrintf("PAE: %s\n", PAEEnabled ? "on" : "off");
268
269 LONG64 timeOffset;
270 biosSettings->COMGETTER(TimeOffset)(&timeOffset);
271 if (details == VMINFO_MACHINEREADABLE)
272 RTPrintf("biossystemtimeoffset=%lld\n", timeOffset);
273 else
274 RTPrintf("Time offset: %lld ms\n", timeOffset);
275
276 TSBool_T hwVirtExEnabled;
277 machine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled);
278 if (hwVirtExEnabled == TSBool_Default)
279 {
280 BOOL fHWVirtExEnabled;
281 ComPtr<ISystemProperties> systemProperties;
282 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
283 systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled);
284 if (details == VMINFO_MACHINEREADABLE)
285 RTPrintf("hwvirtex=\"default\"\n");
286 else
287 RTPrintf("Hardw. virt.ext: Default (%s)\n", fHWVirtExEnabled ? "on" : "off");
288 }
289 else
290 {
291 if (details == VMINFO_MACHINEREADABLE)
292 RTPrintf("hwvirtex=\"%s\"\n", hwVirtExEnabled == TSBool_True ? "on" : "off");
293 else
294 RTPrintf("Hardw. virt.ext: %s\n", hwVirtExEnabled == TSBool_True ? "on" : "off");
295 }
296 BOOL HWVirtExNestedPagingEnabled;
297 machine->COMGETTER(HWVirtExNestedPagingEnabled)(&HWVirtExNestedPagingEnabled);
298 if (details == VMINFO_MACHINEREADABLE)
299 RTPrintf("nestedpaging=\"%s\"\n", HWVirtExNestedPagingEnabled ? "on" : "off");
300 else
301 RTPrintf("Nested Paging: %s\n", HWVirtExNestedPagingEnabled ? "on" : "off");
302
303 BOOL HWVirtExVPIDEnabled;
304 machine->COMGETTER(HWVirtExVPIDEnabled)(&HWVirtExVPIDEnabled);
305 if (details == VMINFO_MACHINEREADABLE)
306 RTPrintf("vtxvpid=\"%s\"\n", HWVirtExVPIDEnabled ? "on" : "off");
307 else
308 RTPrintf("VT-x VPID: %s\n", HWVirtExVPIDEnabled ? "on" : "off");
309
310 MachineState_T machineState;
311 const char *pszState = NULL;
312 rc = machine->COMGETTER(State)(&machineState);
313 switch (machineState)
314 {
315 case MachineState_PoweredOff:
316 if (details == VMINFO_MACHINEREADABLE)
317 pszState = "poweroff";
318 else
319 pszState = "powered off";
320 break;
321 case MachineState_Saved:
322 pszState = "saved";
323 break;
324 case MachineState_Aborted:
325 pszState = "aborted";
326 break;
327 case MachineState_Running:
328 pszState = "running";
329 break;
330 case MachineState_Paused:
331 pszState = "paused";
332 break;
333 case MachineState_Starting:
334 pszState = "starting";
335 break;
336 case MachineState_Stopping:
337 pszState = "stopping";
338 break;
339 case MachineState_Saving:
340 pszState = "saving";
341 break;
342 case MachineState_Restoring:
343 pszState = "restoring";
344 break;
345 default:
346 pszState = "unknown";
347 break;
348 }
349 LONG64 stateSince;
350 machine->COMGETTER(LastStateChange)(&stateSince);
351 RTTIMESPEC timeSpec;
352 RTTimeSpecSetMilli(&timeSpec, stateSince);
353 char pszTime[30] = {0};
354 RTTimeSpecToString(&timeSpec, pszTime, sizeof(pszTime));
355 if (details == VMINFO_MACHINEREADABLE)
356 {
357 RTPrintf("VMState=\"%s\"\n", pszState);
358 RTPrintf("VMStateChangeTime=\"%s\"\n", pszTime);
359 }
360 else
361 RTPrintf("State: %s (since %s)\n", pszState, pszTime);
362
363 ULONG numMonitors;
364 machine->COMGETTER(MonitorCount)(&numMonitors);
365 if (details == VMINFO_MACHINEREADABLE)
366 RTPrintf("monitorcount=%d\n", numMonitors);
367 else
368 RTPrintf("Monitor count: %d\n", numMonitors);
369
370 BOOL accelerate3d;
371 machine->COMGETTER(Accelerate3DEnabled)(&accelerate3d);
372 if (details == VMINFO_MACHINEREADABLE)
373 RTPrintf("accelerate3d=\"%s\"\n", accelerate3d ? "on" : "off");
374 else
375 RTPrintf("3D Acceleration: %s\n", accelerate3d ? "on" : "off");
376
377 ComPtr<IFloppyDrive> floppyDrive;
378 rc = machine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
379 if (SUCCEEDED(rc) && floppyDrive)
380 {
381 BOOL fFloppyEnabled;
382 floppyDrive->COMGETTER(Enabled)(&fFloppyEnabled);
383 Utf8Str pszFloppy = "invalid";
384 if (fFloppyEnabled)
385 {
386 DriveState_T floppyState;
387 floppyDrive->COMGETTER(State)(&floppyState);
388 switch (floppyState)
389 {
390 case DriveState_ImageMounted:
391 {
392 ComPtr<IFloppyImage> floppyImage;
393 rc = floppyDrive->GetImage(floppyImage.asOutParam());
394 if (SUCCEEDED(rc) && floppyImage)
395 {
396 Bstr imagePath;
397 floppyImage->COMGETTER(Location)(imagePath.asOutParam());
398 Guid imageGuid;
399 floppyImage->COMGETTER(Id)(imageGuid.asOutParam());
400 if (details == VMINFO_MACHINEREADABLE)
401 {
402 RTPrintf("FloppyImageUUID=\"%s\"\n", imageGuid.toString().raw());
403 pszFloppy = Utf8StrFmt("%lS", imagePath.raw());
404 }
405 else
406 pszFloppy = Utf8StrFmt("%lS (UUID: %s)", imagePath.raw(), imageGuid.toString().raw());
407 }
408 break;
409 }
410
411 case DriveState_HostDriveCaptured:
412 {
413 ComPtr<IHostFloppyDrive> hostFloppyDrive;
414 rc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam());
415 if (SUCCEEDED(rc) && floppyDrive)
416 {
417 Bstr driveName;
418 hostFloppyDrive->COMGETTER(Name)(driveName.asOutParam());
419 if (details == VMINFO_MACHINEREADABLE)
420 pszFloppy = Utf8StrFmt("host:%lS", driveName.raw());
421 else
422 pszFloppy = Utf8StrFmt("Host drive %lS", driveName.raw());
423 }
424 break;
425 }
426
427 case DriveState_NotMounted:
428 {
429 pszFloppy = "empty";
430 break;
431 }
432 }
433 }
434 else
435 {
436 pszFloppy = "disabled";
437 }
438 if (details == VMINFO_MACHINEREADABLE)
439 RTPrintf("floppy=\"%s\"\n", pszFloppy.raw());
440 else
441 RTPrintf("Floppy: %s\n", pszFloppy.raw());
442 }
443
444 /*
445 * SATA.
446 *
447 * Contributed by: James Lucas
448 */
449#ifdef VBOX_WITH_AHCI
450 ComPtr<ISATAController> SATACtl;
451 BOOL fSataEnabled;
452 rc = machine->COMGETTER(SATAController)(SATACtl.asOutParam());
453 if (SUCCEEDED(rc))
454 {
455 rc = SATACtl->COMGETTER(Enabled)(&fSataEnabled);
456 if (FAILED(rc))
457 fSataEnabled = false;
458 if (details == VMINFO_MACHINEREADABLE)
459 RTPrintf("sata=\"%s\"\n", fSataEnabled ? "on" : "off");
460 else
461 RTPrintf("SATA: %s\n", fSataEnabled ? "enabled" : "disabled");
462 }
463
464 /*
465 * SATA Hard disks
466 */
467 if (fSataEnabled)
468 {
469 ComPtr<IHardDisk> hardDisk;
470 Bstr filePath;
471 ULONG cSataPorts;
472
473 SATACtl->COMGETTER(PortCount)(&cSataPorts);
474 for (ULONG i = 0; i < cSataPorts; ++ i)
475 {
476 rc = machine->GetHardDisk(StorageBus_SATA, i, 0, hardDisk.asOutParam());
477 if (SUCCEEDED(rc) && hardDisk)
478 {
479 hardDisk->COMGETTER(Location)(filePath.asOutParam());
480 hardDisk->COMGETTER(Id)(uuid.asOutParam());
481 if (details == VMINFO_MACHINEREADABLE)
482 {
483 RTPrintf("sataport%d=\"%lS\"\n", i, filePath.raw());
484 RTPrintf("SataPortImageUUID%d=\"%s\"\n", i, uuid.toString().raw());
485 }
486 else
487 RTPrintf("SATA %d: %lS (UUID: %s)\n", i, filePath.raw(), uuid.toString().raw());
488 }
489 else
490 {
491 if (details == VMINFO_MACHINEREADABLE)
492 RTPrintf("sata%d=\"none\"\n",i);
493 }
494 }
495 }
496#endif
497
498 /*
499 * IDE Hard disks
500 */
501 IDEControllerType_T ideController;
502 const char *pszIdeController = NULL;
503 biosSettings->COMGETTER(IDEControllerType)(&ideController);
504 switch (ideController)
505 {
506 case IDEControllerType_PIIX3:
507 pszIdeController = "PIIX3";
508 break;
509 case IDEControllerType_PIIX4:
510 pszIdeController = "PIIX4";
511 break;
512 case IDEControllerType_ICH6:
513 pszIdeController = "ICH6";
514 break;
515 default:
516 pszIdeController = "unknown";
517 }
518 if (details == VMINFO_MACHINEREADABLE)
519 RTPrintf("idecontroller=\"%s\"\n", pszIdeController);
520 else
521 RTPrintf("IDE Controller: %s\n", pszIdeController);
522
523 ComPtr<IHardDisk> hardDisk;
524 Bstr filePath;
525 rc = machine->GetHardDisk(StorageBus_IDE, 0, 0, hardDisk.asOutParam());
526 if (SUCCEEDED(rc) && hardDisk)
527 {
528 hardDisk->COMGETTER(Location)(filePath.asOutParam());
529 hardDisk->COMGETTER(Id)(uuid.asOutParam());
530 if (details == VMINFO_MACHINEREADABLE)
531 {
532 RTPrintf("hda=\"%lS\"\n", filePath.raw());
533 RTPrintf("HdaImageUUID=\"%s\"\n", uuid.toString().raw());
534 }
535 else
536 RTPrintf("Primary master: %lS (UUID: %s)\n", filePath.raw(), uuid.toString().raw());
537 }
538 else
539 {
540 if (details == VMINFO_MACHINEREADABLE)
541 RTPrintf("hda=\"none\"\n");
542 }
543 rc = machine->GetHardDisk(StorageBus_IDE, 0, 1, hardDisk.asOutParam());
544 if (SUCCEEDED(rc) && hardDisk)
545 {
546 hardDisk->COMGETTER(Location)(filePath.asOutParam());
547 hardDisk->COMGETTER(Id)(uuid.asOutParam());
548 if (details == VMINFO_MACHINEREADABLE)
549 {
550 RTPrintf("hdb=\"%lS\"\n", filePath.raw());
551 RTPrintf("HdbImageUUID=\"%s\"\n", uuid.toString().raw());
552 }
553 else
554 RTPrintf("Primary slave: %lS (UUID: %s)\n", filePath.raw(), uuid.toString().raw());
555 }
556 else
557 {
558 if (details == VMINFO_MACHINEREADABLE)
559 RTPrintf("hdb=\"none\"\n");
560 }
561 rc = machine->GetHardDisk(StorageBus_IDE, 1, 1, hardDisk.asOutParam());
562 if (SUCCEEDED(rc) && hardDisk)
563 {
564 hardDisk->COMGETTER(Location)(filePath.asOutParam());
565 hardDisk->COMGETTER(Id)(uuid.asOutParam());
566 if (details == VMINFO_MACHINEREADABLE)
567 {
568 RTPrintf("hdd=\"%lS\"\n", filePath.raw());
569 RTPrintf("HddImageUUID=\"%s\"\n", uuid.toString().raw());
570 }
571 else
572 RTPrintf("Secondary slave: %lS (UUID: %s)\n", filePath.raw(), uuid.toString().raw());
573 }
574 else
575 {
576 if (details == VMINFO_MACHINEREADABLE)
577 RTPrintf("hdd=\"none\"\n");
578 }
579 ComPtr<IDVDDrive> dvdDrive;
580 rc = machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
581 if (SUCCEEDED(rc) && dvdDrive)
582 {
583 ComPtr<IDVDImage> dvdImage;
584 rc = dvdDrive->GetImage(dvdImage.asOutParam());
585 if (SUCCEEDED(rc) && dvdImage)
586 {
587 rc = dvdImage->COMGETTER(Location)(filePath.asOutParam());
588 if (SUCCEEDED(rc) && filePath)
589 {
590 rc = dvdImage->COMGETTER(Id)(uuid.asOutParam());
591 if (details == VMINFO_MACHINEREADABLE)
592 {
593 RTPrintf("dvd=\"%lS\"\n", filePath.raw());
594 RTPrintf("DvdImageUUID=\"%s\"\n", uuid.toString().raw());
595 }
596 else
597 RTPrintf("DVD: %lS (UUID: %s)\n", filePath.raw(), uuid.toString().raw());
598 }
599 }
600 else
601 {
602 ComPtr<IHostDVDDrive> hostDVDDrive;
603 rc = dvdDrive->GetHostDrive(hostDVDDrive.asOutParam());
604 if (SUCCEEDED(rc) && hostDVDDrive)
605 {
606 Bstr name;
607 hostDVDDrive->COMGETTER(Name)(name.asOutParam());
608 if (details == VMINFO_MACHINEREADABLE)
609 RTPrintf("dvd=\"host:%lS\"\n", name.raw());
610 else
611 RTPrintf("DVD: Host drive %lS", name.raw());
612 }
613 else
614 {
615 if (details == VMINFO_MACHINEREADABLE)
616 RTPrintf("dvd=\"none\"\n");
617 else
618 RTPrintf("DVD: empty");
619 }
620 BOOL fPassthrough;
621 dvdDrive->COMGETTER(Passthrough)(&fPassthrough);
622 if (details == VMINFO_MACHINEREADABLE)
623 {
624 RTPrintf("dvdpassthrough=\"%s\"\n", fPassthrough ? "on" : "off");
625 }
626 else
627 {
628 if (fPassthrough)
629 RTPrintf(" (passthrough enabled)");
630 RTPrintf("\n");
631 }
632 }
633 }
634
635 /* get the maximum amount of NICS */
636 ComPtr<ISystemProperties> sysProps;
637 virtualBox->COMGETTER(SystemProperties)(sysProps.asOutParam());
638 ULONG maxNICs = 0;
639 sysProps->COMGETTER(NetworkAdapterCount)(&maxNICs);
640 for (ULONG currentNIC = 0; currentNIC < maxNICs; currentNIC++)
641 {
642 ComPtr<INetworkAdapter> nic;
643 rc = machine->GetNetworkAdapter(currentNIC, nic.asOutParam());
644 if (SUCCEEDED(rc) && nic)
645 {
646 BOOL fEnabled;
647 nic->COMGETTER(Enabled)(&fEnabled);
648 if (!fEnabled)
649 {
650 if (details == VMINFO_MACHINEREADABLE)
651 RTPrintf("nic%d=\"none\"\n", currentNIC + 1);
652 else
653 RTPrintf("NIC %d: disabled\n", currentNIC + 1);
654 }
655 else
656 {
657 Bstr strMACAddress;
658 nic->COMGETTER(MACAddress)(strMACAddress.asOutParam());
659 Utf8Str strAttachment;
660 NetworkAttachmentType_T attachment;
661 nic->COMGETTER(AttachmentType)(&attachment);
662 switch (attachment)
663 {
664 case NetworkAttachmentType_Null:
665 if (details == VMINFO_MACHINEREADABLE)
666 strAttachment = "null";
667 else
668 strAttachment = "none";
669 break;
670 case NetworkAttachmentType_NAT:
671 {
672 Bstr strNetwork;
673 nic->COMGETTER(NATNetwork)(strNetwork.asOutParam());
674 if (details == VMINFO_MACHINEREADABLE)
675 {
676 RTPrintf("natnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
677 strAttachment = "nat";
678 }
679 else if (!strNetwork.isEmpty())
680 strAttachment = Utf8StrFmt("NAT (%lS)", strNetwork.raw());
681 else
682 strAttachment = "NAT";
683 break;
684 }
685 case NetworkAttachmentType_Bridged:
686 {
687 Bstr strBridgeAdp;
688 nic->COMGETTER(HostInterface)(strBridgeAdp.asOutParam());
689 if (details == VMINFO_MACHINEREADABLE)
690 {
691 RTPrintf("bridgeadapter%d=\"%lS\"\n", currentNIC + 1, strBridgeAdp.raw());
692 strAttachment = "bridged";
693 }
694 else
695 strAttachment = Utf8StrFmt("Bridged Interface '%lS'", strBridgeAdp.raw());
696 break;
697 }
698 case NetworkAttachmentType_Internal:
699 {
700 Bstr strNetwork;
701 nic->COMGETTER(InternalNetwork)(strNetwork.asOutParam());
702 if (details == VMINFO_MACHINEREADABLE)
703 {
704 RTPrintf("intnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
705 strAttachment = "intnet";
706 }
707 else
708 strAttachment = Utf8StrFmt("Internal Network '%s'", Utf8Str(strNetwork).raw());
709 break;
710 }
711 case NetworkAttachmentType_HostOnly:
712 {
713#if (defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT))
714 Bstr strHostonlyAdp;
715 nic->COMGETTER(HostInterface)(strHostonlyAdp.asOutParam());
716#endif
717 if (details == VMINFO_MACHINEREADABLE)
718 {
719#if (defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT))
720 RTPrintf("hostonlyadapter%d=\"%lS\"\n", currentNIC + 1, strHostonlyAdp.raw());
721#endif
722 strAttachment = "hostonly";
723 }
724 else
725#if (defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT))
726 strAttachment = Utf8StrFmt("Host-only Interface '%lS'", strHostonlyAdp.raw());
727#else
728 strAttachment = "Host-only Network";
729#endif
730 break;
731 }
732 default:
733 strAttachment = "unknown";
734 break;
735 }
736
737 /* cable connected */
738 BOOL fConnected;
739 nic->COMGETTER(CableConnected)(&fConnected);
740
741 /* trace stuff */
742 BOOL fTraceEnabled;
743 nic->COMGETTER(TraceEnabled)(&fTraceEnabled);
744 Bstr traceFile;
745 nic->COMGETTER(TraceFile)(traceFile.asOutParam());
746
747 /* NIC type */
748 Utf8Str strNICType;
749 NetworkAdapterType_T NICType;
750 nic->COMGETTER(AdapterType)(&NICType);
751 switch (NICType) {
752 case NetworkAdapterType_Am79C970A:
753 strNICType = "Am79C970A";
754 break;
755 case NetworkAdapterType_Am79C973:
756 strNICType = "Am79C973";
757 break;
758#ifdef VBOX_WITH_E1000
759 case NetworkAdapterType_I82540EM:
760 strNICType = "82540EM";
761 break;
762 case NetworkAdapterType_I82543GC:
763 strNICType = "82543GC";
764 break;
765#endif
766 default:
767 strNICType = "unknown";
768 break;
769 }
770
771 /* reported line speed */
772 ULONG ulLineSpeed;
773 nic->COMGETTER(LineSpeed)(&ulLineSpeed);
774
775 if (details == VMINFO_MACHINEREADABLE)
776 {
777 RTPrintf("macaddress%d=\"%lS\"\n", currentNIC + 1, strMACAddress.raw());
778 RTPrintf("cableconnected%d=\"%s\"\n", currentNIC + 1, fConnected ? "on" : "off");
779 RTPrintf("nic%d=\"%s\"\n", currentNIC + 1, strAttachment.raw());
780 }
781 else
782 RTPrintf("NIC %d: MAC: %lS, Attachment: %s, Cable connected: %s, Trace: %s (file: %lS), Type: %s, Reported speed: %d Mbps\n",
783 currentNIC + 1, strMACAddress.raw(), strAttachment.raw(),
784 fConnected ? "on" : "off",
785 fTraceEnabled ? "on" : "off",
786 traceFile.isEmpty() ? Bstr("none").raw() : traceFile.raw(),
787 strNICType.raw(),
788 ulLineSpeed / 1000);
789 }
790 }
791 }
792
793 /* get the maximum amount of UARTs */
794 ULONG maxUARTs = 0;
795 sysProps->COMGETTER(SerialPortCount)(&maxUARTs);
796 for (ULONG currentUART = 0; currentUART < maxUARTs; currentUART++)
797 {
798 ComPtr<ISerialPort> uart;
799 rc = machine->GetSerialPort(currentUART, uart.asOutParam());
800 if (SUCCEEDED(rc) && uart)
801 {
802 BOOL fEnabled;
803 uart->COMGETTER(Enabled)(&fEnabled);
804 if (!fEnabled)
805 {
806 if (details == VMINFO_MACHINEREADABLE)
807 RTPrintf("uart%d=\"off\"\n", currentUART + 1);
808 else
809 RTPrintf("UART %d: disabled\n", currentUART + 1);
810 }
811 else
812 {
813 ULONG ulIRQ, ulIOBase;
814 PortMode_T HostMode;
815 Bstr path;
816 BOOL fServer;
817 uart->COMGETTER(IRQ)(&ulIRQ);
818 uart->COMGETTER(IOBase)(&ulIOBase);
819 uart->COMGETTER(Path)(path.asOutParam());
820 uart->COMGETTER(Server)(&fServer);
821 uart->COMGETTER(HostMode)(&HostMode);
822
823 if (details == VMINFO_MACHINEREADABLE)
824 RTPrintf("uart%d=\"%#06x,%d\"\n", currentUART + 1,
825 ulIOBase, ulIRQ);
826 else
827 RTPrintf("UART %d: I/O base: 0x%04x, IRQ: %d",
828 currentUART + 1, ulIOBase, ulIRQ);
829 switch (HostMode)
830 {
831 default:
832 case PortMode_Disconnected:
833 if (details == VMINFO_MACHINEREADABLE)
834 RTPrintf("uartmode%d=\"disconnected\"\n", currentUART + 1);
835 else
836 RTPrintf(", disconnected\n");
837 break;
838 case PortMode_HostPipe:
839 if (details == VMINFO_MACHINEREADABLE)
840 RTPrintf("uartmode%d=\"%s,%lS\"\n", currentUART + 1,
841 fServer ? "server" : "client", path.raw());
842 else
843 RTPrintf(", attached to pipe (%s) '%lS'\n",
844 fServer ? "server" : "client", path.raw());
845 break;
846 case PortMode_HostDevice:
847 if (details == VMINFO_MACHINEREADABLE)
848 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
849 path.raw());
850 else
851 RTPrintf(", attached to device '%lS'\n", path.raw());
852 break;
853 }
854 }
855 }
856 }
857
858 ComPtr<IAudioAdapter> AudioAdapter;
859 rc = machine->COMGETTER(AudioAdapter)(AudioAdapter.asOutParam());
860 if (SUCCEEDED(rc))
861 {
862 const char *pszDrv = "Unknown";
863 const char *pszCtrl = "Unknown";
864 BOOL fEnabled;
865 rc = AudioAdapter->COMGETTER(Enabled)(&fEnabled);
866 if (SUCCEEDED(rc) && fEnabled)
867 {
868 AudioDriverType_T enmDrvType;
869 rc = AudioAdapter->COMGETTER(AudioDriver)(&enmDrvType);
870 switch (enmDrvType)
871 {
872 case AudioDriverType_Null:
873 if (details == VMINFO_MACHINEREADABLE)
874 pszDrv = "null";
875 else
876 pszDrv = "Null";
877 break;
878 case AudioDriverType_WinMM:
879 if (details == VMINFO_MACHINEREADABLE)
880 pszDrv = "winmm";
881 else
882 pszDrv = "WINMM";
883 break;
884 case AudioDriverType_DirectSound:
885 if (details == VMINFO_MACHINEREADABLE)
886 pszDrv = "dsound";
887 else
888 pszDrv = "DSOUND";
889 break;
890 case AudioDriverType_OSS:
891 if (details == VMINFO_MACHINEREADABLE)
892 pszDrv = "oss";
893 else
894 pszDrv = "OSS";
895 break;
896 case AudioDriverType_ALSA:
897 if (details == VMINFO_MACHINEREADABLE)
898 pszDrv = "alsa";
899 else
900 pszDrv = "ALSA";
901 break;
902 case AudioDriverType_Pulse:
903 if (details == VMINFO_MACHINEREADABLE)
904 pszDrv = "pulse";
905 else
906 pszDrv = "PulseAudio";
907 break;
908 case AudioDriverType_CoreAudio:
909 if (details == VMINFO_MACHINEREADABLE)
910 pszDrv = "coreaudio";
911 else
912 pszDrv = "CoreAudio";
913 break;
914 case AudioDriverType_SolAudio:
915 if (details == VMINFO_MACHINEREADABLE)
916 pszDrv = "solaudio";
917 else
918 pszDrv = "SolAudio";
919 break;
920 default:
921 if (details == VMINFO_MACHINEREADABLE)
922 pszDrv = "unknown";
923 break;
924 }
925 AudioControllerType_T enmCtrlType;
926 rc = AudioAdapter->COMGETTER(AudioController)(&enmCtrlType);
927 switch (enmCtrlType)
928 {
929 case AudioControllerType_AC97:
930 if (details == VMINFO_MACHINEREADABLE)
931 pszCtrl = "ac97";
932 else
933 pszCtrl = "AC97";
934 break;
935 case AudioControllerType_SB16:
936 if (details == VMINFO_MACHINEREADABLE)
937 pszCtrl = "sb16";
938 else
939 pszCtrl = "SB16";
940 break;
941 }
942 }
943 else
944 fEnabled = FALSE;
945 if (details == VMINFO_MACHINEREADABLE)
946 {
947 if (fEnabled)
948 RTPrintf("audio=\"%s\"\n", pszDrv);
949 else
950 RTPrintf("audio=\"none\"\n");
951 }
952 else
953 RTPrintf("Audio: %s (Driver: %s, Controller: %s)\n",
954 fEnabled ? "enabled" : "disabled", pszDrv, pszCtrl);
955 }
956
957 /* Shared clipboard */
958 {
959 const char *psz = "Unknown";
960 ClipboardMode_T enmMode;
961 rc = machine->COMGETTER(ClipboardMode)(&enmMode);
962 switch (enmMode)
963 {
964 case ClipboardMode_Disabled:
965 if (details == VMINFO_MACHINEREADABLE)
966 psz = "disabled";
967 else
968 psz = "disabled";
969 break;
970 case ClipboardMode_HostToGuest:
971 if (details == VMINFO_MACHINEREADABLE)
972 psz = "hosttoguest";
973 else
974 psz = "HostToGuest";
975 break;
976 case ClipboardMode_GuestToHost:
977 if (details == VMINFO_MACHINEREADABLE)
978 psz = "guesttohost";
979 else
980 psz = "GuestToHost";
981 break;
982 case ClipboardMode_Bidirectional:
983 if (details == VMINFO_MACHINEREADABLE)
984 psz = "bidirectional";
985 else
986 psz = "Bidirectional";
987 break;
988 default:
989 if (details == VMINFO_MACHINEREADABLE)
990 psz = "unknown";
991 break;
992 }
993 if (details == VMINFO_MACHINEREADABLE)
994 RTPrintf("clipboard=\"%s\"\n", psz);
995 else
996 RTPrintf("Clipboard Mode: %s\n", psz);
997 }
998
999 if (console)
1000 {
1001 ComPtr<IDisplay> display;
1002 CHECK_ERROR_RET(console, COMGETTER(Display)(display.asOutParam()), rc);
1003 do
1004 {
1005 ULONG xRes, yRes, bpp;
1006 rc = display->COMGETTER(Width)(&xRes);
1007 if (rc == E_ACCESSDENIED)
1008 break; /* VM not powered up */
1009 if (FAILED(rc))
1010 {
1011 com::ErrorInfo info (display);
1012 GluePrintErrorInfo(info);
1013 return rc;
1014 }
1015 rc = display->COMGETTER(Height)(&yRes);
1016 if (rc == E_ACCESSDENIED)
1017 break; /* VM not powered up */
1018 if (FAILED(rc))
1019 {
1020 com::ErrorInfo info (display);
1021 GluePrintErrorInfo(info);
1022 return rc;
1023 }
1024 rc = display->COMGETTER(BitsPerPixel)(&bpp);
1025 if (rc == E_ACCESSDENIED)
1026 break; /* VM not powered up */
1027 if (FAILED(rc))
1028 {
1029 com::ErrorInfo info (display);
1030 GluePrintErrorInfo(info);
1031 return rc;
1032 }
1033 if (details == VMINFO_MACHINEREADABLE)
1034 RTPrintf("VideoMode=\"%d,%d,%d\"\n", xRes, yRes, bpp);
1035 else
1036 RTPrintf("Video mode: %dx%dx%d\n", xRes, yRes, bpp);
1037 }
1038 while (0);
1039 }
1040
1041 /*
1042 * VRDP
1043 */
1044 ComPtr<IVRDPServer> vrdpServer;
1045 rc = machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1046 if (SUCCEEDED(rc) && vrdpServer)
1047 {
1048 BOOL fEnabled = false;
1049 vrdpServer->COMGETTER(Enabled)(&fEnabled);
1050 if (fEnabled)
1051 {
1052 ULONG port;
1053 vrdpServer->COMGETTER(Port)(&port);
1054 Bstr address;
1055 vrdpServer->COMGETTER(NetAddress)(address.asOutParam());
1056 BOOL fMultiCon;
1057 vrdpServer->COMGETTER(AllowMultiConnection)(&fMultiCon);
1058 BOOL fReuseCon;
1059 vrdpServer->COMGETTER(ReuseSingleConnection)(&fReuseCon);
1060 VRDPAuthType_T vrdpAuthType;
1061 const char *strAuthType;
1062 vrdpServer->COMGETTER(AuthType)(&vrdpAuthType);
1063 switch (vrdpAuthType)
1064 {
1065 case VRDPAuthType_Null:
1066 strAuthType = "null";
1067 break;
1068 case VRDPAuthType_External:
1069 strAuthType = "external";
1070 break;
1071 case VRDPAuthType_Guest:
1072 strAuthType = "guest";
1073 break;
1074 default:
1075 strAuthType = "unknown";
1076 break;
1077 }
1078 if (details == VMINFO_MACHINEREADABLE)
1079 {
1080 RTPrintf("vrdp=\"on\"\n");
1081 RTPrintf("vrdpport=%d\n", port);
1082 RTPrintf("vrdpaddress=\"%lS\"\n", address.raw());
1083 RTPrintf("vrdpauthtype=\"%s\"\n", strAuthType);
1084 RTPrintf("vrdpmulticon=\"%s\"\n", fMultiCon ? "on" : "off");
1085 RTPrintf("vrdpreusecon=\"%s\"\n", fReuseCon ? "on" : "off");
1086 }
1087 else
1088 {
1089 if (address.isEmpty())
1090 address = "0.0.0.0";
1091 RTPrintf("VRDP: enabled (Address %lS, Port %d, MultiConn: %s, ReuseSingleConn: %s, Authentication type: %s)\n", address.raw(), port, fMultiCon ? "on" : "off", fReuseCon ? "on" : "off", strAuthType);
1092 }
1093 }
1094 else
1095 {
1096 if (details == VMINFO_MACHINEREADABLE)
1097 RTPrintf("vrdp=\"off\"\n");
1098 else
1099 RTPrintf("VRDP: disabled\n");
1100 }
1101 }
1102
1103 /*
1104 * USB.
1105 */
1106 ComPtr<IUSBController> USBCtl;
1107 rc = machine->COMGETTER(USBController)(USBCtl.asOutParam());
1108 if (SUCCEEDED(rc))
1109 {
1110 BOOL fEnabled;
1111 rc = USBCtl->COMGETTER(Enabled)(&fEnabled);
1112 if (FAILED(rc))
1113 fEnabled = false;
1114 if (details == VMINFO_MACHINEREADABLE)
1115 RTPrintf("usb=\"%s\"\n", fEnabled ? "on" : "off");
1116 else
1117 RTPrintf("USB: %s\n", fEnabled ? "enabled" : "disabled");
1118
1119 if (details != VMINFO_MACHINEREADABLE)
1120 RTPrintf("\nUSB Device Filters:\n\n");
1121
1122 ComPtr<IUSBDeviceFilterCollection> Coll;
1123 CHECK_ERROR_RET (USBCtl, COMGETTER(DeviceFilters)(Coll.asOutParam()), rc);
1124
1125 ComPtr<IUSBDeviceFilterEnumerator> Enum;
1126 CHECK_ERROR_RET (Coll, Enumerate(Enum.asOutParam()), rc);
1127
1128 ULONG index = 0;
1129 BOOL fMore = FALSE;
1130 ASSERT(SUCCEEDED(rc = Enum->HasMore (&fMore)));
1131 if (FAILED(rc))
1132 return rc;
1133
1134 if (!fMore)
1135 {
1136 if (details != VMINFO_MACHINEREADABLE)
1137 RTPrintf("<none>\n\n");
1138 }
1139 else
1140 while (fMore)
1141 {
1142 ComPtr<IUSBDeviceFilter> DevPtr;
1143 ASSERT(SUCCEEDED(rc = Enum->GetNext(DevPtr.asOutParam())));
1144 if (FAILED(rc))
1145 return rc;
1146
1147 /* Query info. */
1148
1149 if (details != VMINFO_MACHINEREADABLE)
1150 RTPrintf("Index: %lu\n", index);
1151
1152 BOOL bActive = FALSE;
1153 CHECK_ERROR_RET (DevPtr, COMGETTER (Active) (&bActive), rc);
1154 if (details == VMINFO_MACHINEREADABLE)
1155 RTPrintf("USBFilterActive%d=\"%s\"\n", index + 1, bActive ? "on" : "off");
1156 else
1157 RTPrintf("Active: %s\n", bActive ? "yes" : "no");
1158
1159 Bstr bstr;
1160 CHECK_ERROR_RET (DevPtr, COMGETTER (Name) (bstr.asOutParam()), rc);
1161 if (details == VMINFO_MACHINEREADABLE)
1162 RTPrintf("USBFilterName%d=\"%lS\"\n", index + 1, bstr.raw());
1163 else
1164 RTPrintf("Name: %lS\n", bstr.raw());
1165 CHECK_ERROR_RET (DevPtr, COMGETTER (VendorId) (bstr.asOutParam()), rc);
1166 if (details == VMINFO_MACHINEREADABLE)
1167 RTPrintf("USBFilterVendorId%d=\"%lS\"\n", index + 1, bstr.raw());
1168 else
1169 RTPrintf("VendorId: %lS\n", bstr.raw());
1170 CHECK_ERROR_RET (DevPtr, COMGETTER (ProductId) (bstr.asOutParam()), rc);
1171 if (details == VMINFO_MACHINEREADABLE)
1172 RTPrintf("USBFilterProductId%d=\"%lS\"\n", index + 1, bstr.raw());
1173 else
1174 RTPrintf("ProductId: %lS\n", bstr.raw());
1175 CHECK_ERROR_RET (DevPtr, COMGETTER (Revision) (bstr.asOutParam()), rc);
1176 if (details == VMINFO_MACHINEREADABLE)
1177 RTPrintf("USBFilterRevision%d=\"%lS\"\n", index + 1, bstr.raw());
1178 else
1179 RTPrintf("Revision: %lS\n", bstr.raw());
1180 CHECK_ERROR_RET (DevPtr, COMGETTER (Manufacturer) (bstr.asOutParam()), rc);
1181 if (details == VMINFO_MACHINEREADABLE)
1182 RTPrintf("USBFilterManufacturer%d=\"%lS\"\n", index + 1, bstr.raw());
1183 else
1184 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1185 CHECK_ERROR_RET (DevPtr, COMGETTER (Product) (bstr.asOutParam()), rc);
1186 if (details == VMINFO_MACHINEREADABLE)
1187 RTPrintf("USBFilterProduct%d=\"%lS\"\n", index + 1, bstr.raw());
1188 else
1189 RTPrintf("Product: %lS\n", bstr.raw());
1190 CHECK_ERROR_RET (DevPtr, COMGETTER (Remote) (bstr.asOutParam()), rc);
1191 if (details == VMINFO_MACHINEREADABLE)
1192 RTPrintf("USBFilterRemote%d=\"%lS\"\n", index + 1, bstr.raw());
1193 else
1194 RTPrintf("Remote: %lS\n", bstr.raw());
1195 CHECK_ERROR_RET (DevPtr, COMGETTER (SerialNumber) (bstr.asOutParam()), rc);
1196 if (details == VMINFO_MACHINEREADABLE)
1197 RTPrintf("USBFilterSerialNumber%d=\"%lS\"\n", index + 1, bstr.raw());
1198 else
1199 RTPrintf("Serial Number: %lS\n", bstr.raw());
1200 if (details != VMINFO_MACHINEREADABLE)
1201 {
1202 ULONG fMaskedIfs;
1203 CHECK_ERROR_RET (DevPtr, COMGETTER (MaskedInterfaces) (&fMaskedIfs), rc);
1204 if (fMaskedIfs)
1205 RTPrintf("Masked Interfaces: 0x%08x\n", fMaskedIfs);
1206 RTPrintf("\n");
1207 }
1208
1209 ASSERT(SUCCEEDED(rc = Enum->HasMore (&fMore)));
1210 if (FAILED(rc))
1211 return rc;
1212
1213 index ++;
1214 }
1215
1216 if (console)
1217 {
1218 index = 0;
1219 /* scope */
1220 {
1221 if (details != VMINFO_MACHINEREADABLE)
1222 RTPrintf("Available remote USB devices:\n\n");
1223
1224 ComPtr<IHostUSBDeviceCollection> coll;
1225 CHECK_ERROR_RET (console, COMGETTER(RemoteUSBDevices) (coll.asOutParam()), rc);
1226
1227 ComPtr <IHostUSBDeviceEnumerator> en;
1228 CHECK_ERROR_RET (coll, Enumerate (en.asOutParam()), rc);
1229
1230 BOOL more = FALSE;
1231 ASSERT(SUCCEEDED(rc = en->HasMore(&more)));
1232 if (FAILED(rc))
1233 return rc;
1234
1235 if (!more)
1236 {
1237 if (details != VMINFO_MACHINEREADABLE)
1238 RTPrintf("<none>\n\n");
1239 }
1240 else
1241 while (more)
1242 {
1243 ComPtr <IHostUSBDevice> dev;
1244 ASSERT(SUCCEEDED(rc = en->GetNext (dev.asOutParam())));
1245 if (FAILED(rc))
1246 return rc;
1247
1248 /* Query info. */
1249 Guid id;
1250 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1251 USHORT usVendorId;
1252 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1253 USHORT usProductId;
1254 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1255 USHORT bcdRevision;
1256 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1257
1258 if (details == VMINFO_MACHINEREADABLE)
1259 RTPrintf("USBRemoteUUID%d=\"%S\"\n"
1260 "USBRemoteVendorId%d=\"%#06x\"\n"
1261 "USBRemoteProductId%d=\"%#06x\"\n"
1262 "USBRemoteRevision%d=\"%#04x%02x\"\n",
1263 index + 1, id.toString().raw(),
1264 index + 1, usVendorId,
1265 index + 1, usProductId,
1266 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1267 else
1268 RTPrintf("UUID: %S\n"
1269 "VendorId: 0x%04x (%04X)\n"
1270 "ProductId: 0x%04x (%04X)\n"
1271 "Revision: %u.%u (%02u%02u)\n",
1272 id.toString().raw(),
1273 usVendorId, usVendorId, usProductId, usProductId,
1274 bcdRevision >> 8, bcdRevision & 0xff,
1275 bcdRevision >> 8, bcdRevision & 0xff);
1276
1277 /* optional stuff. */
1278 Bstr bstr;
1279 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1280 if (!bstr.isEmpty())
1281 {
1282 if (details == VMINFO_MACHINEREADABLE)
1283 RTPrintf("USBRemoteManufacturer%d=\"%lS\"\n", index + 1, bstr.raw());
1284 else
1285 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1286 }
1287 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1288 if (!bstr.isEmpty())
1289 {
1290 if (details == VMINFO_MACHINEREADABLE)
1291 RTPrintf("USBRemoteProduct%d=\"%lS\"\n", index + 1, bstr.raw());
1292 else
1293 RTPrintf("Product: %lS\n", bstr.raw());
1294 }
1295 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1296 if (!bstr.isEmpty())
1297 {
1298 if (details == VMINFO_MACHINEREADABLE)
1299 RTPrintf("USBRemoteSerialNumber%d=\"%lS\"\n", index + 1, bstr.raw());
1300 else
1301 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1302 }
1303 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1304 if (!bstr.isEmpty())
1305 {
1306 if (details == VMINFO_MACHINEREADABLE)
1307 RTPrintf("USBRemoteAddress%d=\"%lS\"\n", index + 1, bstr.raw());
1308 else
1309 RTPrintf("Address: %lS\n", bstr.raw());
1310 }
1311
1312 if (details != VMINFO_MACHINEREADABLE)
1313 RTPrintf("\n");
1314
1315 ASSERT(SUCCEEDED(rc = en->HasMore (&more)));
1316 if (FAILED(rc))
1317 return rc;
1318
1319 index ++;
1320 }
1321 }
1322
1323 index = 0;
1324 /* scope */
1325 {
1326 if (details != VMINFO_MACHINEREADABLE)
1327 RTPrintf ("Currently Attached USB Devices:\n\n");
1328
1329 ComPtr <IUSBDeviceCollection> coll;
1330 CHECK_ERROR_RET (console, COMGETTER(USBDevices) (coll.asOutParam()), rc);
1331
1332 ComPtr <IUSBDeviceEnumerator> en;
1333 CHECK_ERROR_RET (coll, Enumerate (en.asOutParam()), rc);
1334
1335 BOOL more = FALSE;
1336 ASSERT(SUCCEEDED(rc = en->HasMore (&more)));
1337 if (FAILED(rc))
1338 return rc;
1339
1340 if (!more)
1341 {
1342 if (details != VMINFO_MACHINEREADABLE)
1343 RTPrintf("<none>\n\n");
1344 }
1345 else
1346 while (more)
1347 {
1348 ComPtr <IUSBDevice> dev;
1349 ASSERT(SUCCEEDED(rc = en->GetNext (dev.asOutParam())));
1350 if (FAILED(rc))
1351 return rc;
1352
1353 /* Query info. */
1354 Guid id;
1355 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1356 USHORT usVendorId;
1357 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1358 USHORT usProductId;
1359 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1360 USHORT bcdRevision;
1361 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1362
1363 if (details == VMINFO_MACHINEREADABLE)
1364 RTPrintf("USBAttachedUUID%d=\"%S\"\n"
1365 "USBAttachedVendorId%d=\"%#06x\"\n"
1366 "USBAttachedProductId%d=\"%#06x\"\n"
1367 "USBAttachedRevision%d=\"%#04x%02x\"\n",
1368 index + 1, id.toString().raw(),
1369 index + 1, usVendorId,
1370 index + 1, usProductId,
1371 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1372 else
1373 RTPrintf("UUID: %S\n"
1374 "VendorId: 0x%04x (%04X)\n"
1375 "ProductId: 0x%04x (%04X)\n"
1376 "Revision: %u.%u (%02u%02u)\n",
1377 id.toString().raw(),
1378 usVendorId, usVendorId, usProductId, usProductId,
1379 bcdRevision >> 8, bcdRevision & 0xff,
1380 bcdRevision >> 8, bcdRevision & 0xff);
1381
1382 /* optional stuff. */
1383 Bstr bstr;
1384 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1385 if (!bstr.isEmpty())
1386 {
1387 if (details == VMINFO_MACHINEREADABLE)
1388 RTPrintf("USBAttachedManufacturer%d=\"%lS\"\n", index + 1, bstr.raw());
1389 else
1390 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1391 }
1392 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1393 if (!bstr.isEmpty())
1394 {
1395 if (details == VMINFO_MACHINEREADABLE)
1396 RTPrintf("USBAttachedProduct%d=\"%lS\"\n", index + 1, bstr.raw());
1397 else
1398 RTPrintf("Product: %lS\n", bstr.raw());
1399 }
1400 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1401 if (!bstr.isEmpty())
1402 {
1403 if (details == VMINFO_MACHINEREADABLE)
1404 RTPrintf("USBAttachedSerialNumber%d=\"%lS\"\n", index + 1, bstr.raw());
1405 else
1406 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1407 }
1408 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1409 if (!bstr.isEmpty())
1410 {
1411 if (details == VMINFO_MACHINEREADABLE)
1412 RTPrintf("USBAttachedAddress%d=\"%lS\"\n", index + 1, bstr.raw());
1413 else
1414 RTPrintf("Address: %lS\n", bstr.raw());
1415 }
1416
1417 if (details != VMINFO_MACHINEREADABLE)
1418 RTPrintf("\n");
1419
1420 ASSERT(SUCCEEDED(rc = en->HasMore (&more)));
1421 if (FAILED(rc))
1422 return rc;
1423
1424 index ++;
1425 }
1426 }
1427 }
1428 } /* USB */
1429
1430 /*
1431 * Shared folders
1432 */
1433 if (details != VMINFO_MACHINEREADABLE)
1434 RTPrintf("Shared folders: ");
1435 uint32_t numSharedFolders = 0;
1436#if 0 // not yet implemented
1437 /* globally shared folders first */
1438 {
1439 ComPtr<ISharedFolderCollection> sfColl;
1440 ComPtr<ISharedFolderEnumerator> sfEnum;
1441 CHECK_ERROR_RET(virtualBox, COMGETTER(SharedFolders)(sfColl.asOutParam()), rc);
1442 CHECK_ERROR_RET(sfColl, Enumerate(sfEnum.asOutParam()), rc);
1443 BOOL fMore;
1444 sfEnum->HasMore(&fMore);
1445 while (fMore)
1446 {
1447 ComPtr<ISharedFolder> sf;
1448 CHECK_ERROR_RET(sfEnum, GetNext(sf.asOutParam()), rc);
1449 Bstr name, hostPath;
1450 sf->COMGETTER(Name)(name.asOutParam());
1451 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1452 RTPrintf("Name: '%lS', Host path: '%lS' (global mapping)\n", name.raw(), hostPath.raw());
1453 ++numSharedFolders;
1454 CHECK_ERROR_RET(sfEnum, HasMore(&fMore), rc);
1455 }
1456 }
1457#endif
1458 /* now VM mappings */
1459 {
1460 com::SafeIfaceArray <ISharedFolder> folders;
1461
1462 CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1463 ULONG index = 0;
1464
1465 for (size_t i = 0; i < folders.size(); ++i)
1466 {
1467 ComPtr <ISharedFolder> sf = folders[i];
1468
1469 Bstr name, hostPath;
1470 BOOL writable;
1471 sf->COMGETTER(Name)(name.asOutParam());
1472 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1473 sf->COMGETTER(Writable)(&writable);
1474 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1475 RTPrintf("\n\n");
1476 if (details == VMINFO_MACHINEREADABLE)
1477 {
1478 RTPrintf("SharedFolderNameMachineMapping%d=\"%lS\"\n", index + 1,
1479 name.raw());
1480 RTPrintf("SharedFolderPathMachineMapping%d=\"%lS\"\n", index + 1,
1481 hostPath.raw());
1482 }
1483 else
1484 RTPrintf("Name: '%lS', Host path: '%lS' (machine mapping), %s\n",
1485 name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
1486 ++numSharedFolders;
1487 }
1488 }
1489 /* transient mappings */
1490 if (console)
1491 {
1492 com::SafeIfaceArray <ISharedFolder> folders;
1493
1494 CHECK_ERROR_RET(console, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1495 ULONG index = 0;
1496
1497 for (size_t i = 0; i < folders.size(); ++i)
1498 {
1499 ComPtr <ISharedFolder> sf = folders[i];
1500
1501 Bstr name, hostPath;
1502 sf->COMGETTER(Name)(name.asOutParam());
1503 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1504 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1505 RTPrintf("\n\n");
1506 if (details == VMINFO_MACHINEREADABLE)
1507 {
1508 RTPrintf("SharedFolderNameTransientMapping%d=\"%lS\"\n", index + 1,
1509 name.raw());
1510 RTPrintf("SharedFolderPathTransientMapping%d=\"%lS\"\n", index + 1,
1511 hostPath.raw());
1512 }
1513 else
1514 RTPrintf("Name: '%lS', Host path: '%lS' (transient mapping)\n", name.raw(), hostPath.raw());
1515 ++numSharedFolders;
1516 }
1517 }
1518 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1519 RTPrintf("<none>\n");
1520 if (details != VMINFO_MACHINEREADABLE)
1521 RTPrintf("\n");
1522
1523 if (console)
1524 {
1525 /*
1526 * Live VRDP info.
1527 */
1528 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1529 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1530 BOOL Active;
1531 ULONG NumberOfClients;
1532 LONG64 BeginTime;
1533 LONG64 EndTime;
1534 ULONG64 BytesSent;
1535 ULONG64 BytesSentTotal;
1536 ULONG64 BytesReceived;
1537 ULONG64 BytesReceivedTotal;
1538 Bstr User;
1539 Bstr Domain;
1540 Bstr ClientName;
1541 Bstr ClientIP;
1542 ULONG ClientVersion;
1543 ULONG EncryptionStyle;
1544
1545 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Active) (&Active), rc);
1546 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(NumberOfClients) (&NumberOfClients), rc);
1547 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BeginTime) (&BeginTime), rc);
1548 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EndTime) (&EndTime), rc);
1549 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSent) (&BytesSent), rc);
1550 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSentTotal) (&BytesSentTotal), rc);
1551 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceived) (&BytesReceived), rc);
1552 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceivedTotal) (&BytesReceivedTotal), rc);
1553 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(User) (User.asOutParam ()), rc);
1554 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Domain) (Domain.asOutParam ()), rc);
1555 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientName) (ClientName.asOutParam ()), rc);
1556 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientIP) (ClientIP.asOutParam ()), rc);
1557 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientVersion) (&ClientVersion), rc);
1558 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EncryptionStyle) (&EncryptionStyle), rc);
1559
1560 if (details == VMINFO_MACHINEREADABLE)
1561 RTPrintf("VRDPActiveConnection=\"%s\"\n", Active ? "on": "off");
1562 else
1563 RTPrintf("VRDP Connection: %s\n", Active? "active": "not active");
1564
1565 if (details == VMINFO_MACHINEREADABLE)
1566 RTPrintf("VRDPClients=%d\n", NumberOfClients);
1567 else
1568 RTPrintf("Clients so far: %d\n", NumberOfClients);
1569
1570 if (NumberOfClients > 0)
1571 {
1572 char timestr[128];
1573
1574 if (Active)
1575 {
1576 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1577 if (details == VMINFO_MACHINEREADABLE)
1578 RTPrintf("VRDPStartTime=\"%s\"\n", timestr);
1579 else
1580 RTPrintf("Start time: %s\n", timestr);
1581 }
1582 else
1583 {
1584 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1585 if (details == VMINFO_MACHINEREADABLE)
1586 RTPrintf("VRDPLastStartTime=\"%s\"\n", timestr);
1587 else
1588 RTPrintf("Last started: %s\n", timestr);
1589 makeTimeStr (timestr, sizeof (timestr), EndTime);
1590 if (details == VMINFO_MACHINEREADABLE)
1591 RTPrintf("VRDPLastEndTime=\"%s\"\n", timestr);
1592 else
1593 RTPrintf("Last ended: %s\n", timestr);
1594 }
1595
1596 uint64_t ThroughputSend = 0;
1597 uint64_t ThroughputReceive = 0;
1598 if (EndTime != BeginTime)
1599 {
1600 ThroughputSend = (BytesSent * 1000) / (EndTime - BeginTime);
1601 ThroughputReceive = (BytesReceived * 1000) / (EndTime - BeginTime);
1602 }
1603
1604 if (details == VMINFO_MACHINEREADABLE)
1605 {
1606 RTPrintf("VRDPBytesSent=%llu\n", BytesSent);
1607 RTPrintf("VRDPThroughputSend=%llu\n", ThroughputSend);
1608 RTPrintf("VRDPBytesSentTotal=%llu\n", BytesSentTotal);
1609
1610 RTPrintf("VRDPBytesReceived=%llu\n", BytesReceived);
1611 RTPrintf("VRDPThroughputReceive=%llu\n", ThroughputReceive);
1612 RTPrintf("VRDPBytesReceivedTotal=%llu\n", BytesReceivedTotal);
1613 }
1614 else
1615 {
1616 RTPrintf("Sent: %llu Bytes\n", BytesSent);
1617 RTPrintf("Average speed: %llu B/s\n", ThroughputSend);
1618 RTPrintf("Sent total: %llu Bytes\n", BytesSentTotal);
1619
1620 RTPrintf("Received: %llu Bytes\n", BytesReceived);
1621 RTPrintf("Speed: %llu B/s\n", ThroughputReceive);
1622 RTPrintf("Received total: %llu Bytes\n", BytesReceivedTotal);
1623 }
1624
1625 if (Active)
1626 {
1627 if (details == VMINFO_MACHINEREADABLE)
1628 {
1629 RTPrintf("VRDPUserName=\"%lS\"\n", User.raw());
1630 RTPrintf("VRDPDomain=\"%lS\"\n", Domain.raw());
1631 RTPrintf("VRDPClientName=\"%lS\"\n", ClientName.raw());
1632 RTPrintf("VRDPClientIP=\"%lS\"\n", ClientIP.raw());
1633 RTPrintf("VRDPClientVersion=%d\n", ClientVersion);
1634 RTPrintf("VRDPEncryption=\"%s\"\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1635 }
1636 else
1637 {
1638 RTPrintf("User name: %lS\n", User.raw());
1639 RTPrintf("Domain: %lS\n", Domain.raw());
1640 RTPrintf("Client name: %lS\n", ClientName.raw());
1641 RTPrintf("Client IP: %lS\n", ClientIP.raw());
1642 RTPrintf("Client version: %d\n", ClientVersion);
1643 RTPrintf("Encryption: %s\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1644 }
1645 }
1646 }
1647
1648 if (details != VMINFO_MACHINEREADABLE)
1649 RTPrintf("\n");
1650 }
1651
1652 if ( details == VMINFO_STANDARD
1653 || details == VMINFO_FULL
1654 || details == VMINFO_MACHINEREADABLE)
1655 {
1656 Bstr description;
1657 machine->COMGETTER(Description)(description.asOutParam());
1658 if (!description.isEmpty())
1659 {
1660 if (details == VMINFO_MACHINEREADABLE)
1661 RTPrintf("description=\"%lS\"\n", description.raw());
1662 else
1663 RTPrintf("Description:\n%lS\n", description.raw());
1664 }
1665 }
1666
1667 ULONG guestVal;
1668 if (details != VMINFO_MACHINEREADABLE)
1669 RTPrintf("Guest:\n\n");
1670
1671#ifdef VBOX_WITH_MEM_BALLOONING
1672 rc = machine->COMGETTER(MemoryBalloonSize)(&guestVal);
1673 if (SUCCEEDED(rc))
1674 {
1675 if (details == VMINFO_MACHINEREADABLE)
1676 RTPrintf("GuestMemoryBalloon=%d\n", guestVal);
1677 else
1678 RTPrintf("Configured memory balloon size: %d MB\n", guestVal);
1679 }
1680#endif
1681 rc = machine->COMGETTER(StatisticsUpdateInterval)(&guestVal);
1682 if (SUCCEEDED(rc))
1683 {
1684 if (details == VMINFO_MACHINEREADABLE)
1685 RTPrintf("GuestStatisticsUpdateInterval=%d\n", guestVal);
1686 else
1687 {
1688 if (guestVal == 0)
1689 RTPrintf("Statistics update: disabled\n");
1690 else
1691 RTPrintf("Statistics update interval: %d seconds\n", guestVal);
1692 }
1693 }
1694 if (details != VMINFO_MACHINEREADABLE)
1695 RTPrintf("\n");
1696
1697 if ( console
1698 && ( details == VMINFO_STATISTICS
1699 || details == VMINFO_FULL
1700 || details == VMINFO_MACHINEREADABLE))
1701 {
1702 ComPtr <IGuest> guest;
1703
1704 rc = console->COMGETTER(Guest)(guest.asOutParam());
1705 if (SUCCEEDED(rc))
1706 {
1707 ULONG statVal;
1708
1709 rc = guest->GetStatistic(0, GuestStatisticType_SampleNumber, &statVal);
1710 if (details == VMINFO_MACHINEREADABLE)
1711 RTPrintf("StatGuestSample=%d\n", statVal);
1712 else
1713 RTPrintf("Guest statistics for sample %d:\n\n", statVal);
1714
1715 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Idle, &statVal);
1716 if (SUCCEEDED(rc))
1717 {
1718 if (details == VMINFO_MACHINEREADABLE)
1719 RTPrintf("StatGuestLoadIdleCPU%d=%d\n", 0, statVal);
1720 else
1721 RTPrintf("CPU%d: CPU Load Idle %-3d%%\n", 0, statVal);
1722 }
1723
1724 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Kernel, &statVal);
1725 if (SUCCEEDED(rc))
1726 {
1727 if (details == VMINFO_MACHINEREADABLE)
1728 RTPrintf("StatGuestLoadKernelCPU%d=%d\n", 0, statVal);
1729 else
1730 RTPrintf("CPU%d: CPU Load Kernel %-3d%%\n", 0, statVal);
1731 }
1732
1733 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_User, &statVal);
1734 if (SUCCEEDED(rc))
1735 {
1736 if (details == VMINFO_MACHINEREADABLE)
1737 RTPrintf("StatGuestLoadUserCPU%d=%d\n", 0, statVal);
1738 else
1739 RTPrintf("CPU%d: CPU Load User %-3d%%\n", 0, statVal);
1740 }
1741
1742 rc = guest->GetStatistic(0, GuestStatisticType_Threads, &statVal);
1743 if (SUCCEEDED(rc))
1744 {
1745 if (details == VMINFO_MACHINEREADABLE)
1746 RTPrintf("StatGuestThreadsCPU%d=%d\n", 0, statVal);
1747 else
1748 RTPrintf("CPU%d: Threads %d\n", 0, statVal);
1749 }
1750
1751 rc = guest->GetStatistic(0, GuestStatisticType_Processes, &statVal);
1752 if (SUCCEEDED(rc))
1753 {
1754 if (details == VMINFO_MACHINEREADABLE)
1755 RTPrintf("StatGuestProcessesCPU%d=%d\n", 0, statVal);
1756 else
1757 RTPrintf("CPU%d: Processes %d\n", 0, statVal);
1758 }
1759
1760 rc = guest->GetStatistic(0, GuestStatisticType_Handles, &statVal);
1761 if (SUCCEEDED(rc))
1762 {
1763 if (details == VMINFO_MACHINEREADABLE)
1764 RTPrintf("StatGuestHandlesCPU%d=%d\n", 0, statVal);
1765 else
1766 RTPrintf("CPU%d: Handles %d\n", 0, statVal);
1767 }
1768
1769 rc = guest->GetStatistic(0, GuestStatisticType_MemoryLoad, &statVal);
1770 if (SUCCEEDED(rc))
1771 {
1772 if (details == VMINFO_MACHINEREADABLE)
1773 RTPrintf("StatGuestMemoryLoadCPU%d=%d\n", 0, statVal);
1774 else
1775 RTPrintf("CPU%d: Memory Load %d%%\n", 0, statVal);
1776 }
1777
1778 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemTotal, &statVal);
1779 if (SUCCEEDED(rc))
1780 {
1781 if (details == VMINFO_MACHINEREADABLE)
1782 RTPrintf("StatGuestMemoryTotalPhysCPU%d=%d\n", 0, statVal);
1783 else
1784 RTPrintf("CPU%d: Total physical memory %-4d MB\n", 0, statVal);
1785 }
1786
1787 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemAvailable, &statVal);
1788 if (SUCCEEDED(rc))
1789 {
1790 if (details == VMINFO_MACHINEREADABLE)
1791 RTPrintf("StatGuestMemoryFreePhysCPU%d=%d\n", 0, statVal);
1792 else
1793 RTPrintf("CPU%d: Free physical memory %-4d MB\n", 0, statVal);
1794 }
1795
1796#ifdef VBOX_WITH_MEM_BALLOONING
1797 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemBalloon, &statVal);
1798 if (SUCCEEDED(rc))
1799 {
1800 if (details == VMINFO_MACHINEREADABLE)
1801 RTPrintf("StatGuestMemoryBalloonCPU%d=%d\n", 0, statVal);
1802 else
1803 RTPrintf("CPU%d: Memory balloon size %-4d MB\n", 0, statVal);
1804 }
1805#endif
1806 rc = guest->GetStatistic(0, GuestStatisticType_MemCommitTotal, &statVal);
1807 if (SUCCEEDED(rc))
1808 {
1809 if (details == VMINFO_MACHINEREADABLE)
1810 RTPrintf("StatGuestMemoryCommittedCPU%d=%d\n", 0, statVal);
1811 else
1812 RTPrintf("CPU%d: Committed memory %-4d MB\n", 0, statVal);
1813 }
1814
1815 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelTotal, &statVal);
1816 if (SUCCEEDED(rc))
1817 {
1818 if (details == VMINFO_MACHINEREADABLE)
1819 RTPrintf("StatGuestMemoryTotalKernelCPU%d=%d\n", 0, statVal);
1820 else
1821 RTPrintf("CPU%d: Total kernel memory %-4d MB\n", 0, statVal);
1822 }
1823
1824 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelPaged, &statVal);
1825 if (SUCCEEDED(rc))
1826 {
1827 if (details == VMINFO_MACHINEREADABLE)
1828 RTPrintf("StatGuestMemoryPagedKernelCPU%d=%d\n", 0, statVal);
1829 else
1830 RTPrintf("CPU%d: Paged kernel memory %-4d MB\n", 0, statVal);
1831 }
1832
1833 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelNonpaged, &statVal);
1834 if (SUCCEEDED(rc))
1835 {
1836 if (details == VMINFO_MACHINEREADABLE)
1837 RTPrintf("StatGuestMemoryNonpagedKernelCPU%d=%d\n", 0, statVal);
1838 else
1839 RTPrintf("CPU%d: Nonpaged kernel memory %-4d MB\n", 0, statVal);
1840 }
1841
1842 rc = guest->GetStatistic(0, GuestStatisticType_MemSystemCache, &statVal);
1843 if (SUCCEEDED(rc))
1844 {
1845 if (details == VMINFO_MACHINEREADABLE)
1846 RTPrintf("StatGuestSystemCacheSizeCPU%d=%d\n", 0, statVal);
1847 else
1848 RTPrintf("CPU%d: System cache size %-4d MB\n", 0, statVal);
1849 }
1850
1851 rc = guest->GetStatistic(0, GuestStatisticType_PageFileSize, &statVal);
1852 if (SUCCEEDED(rc))
1853 {
1854 if (details == VMINFO_MACHINEREADABLE)
1855 RTPrintf("StatGuestPageFileSizeCPU%d=%d\n", 0, statVal);
1856 else
1857 RTPrintf("CPU%d: Page file size %-4d MB\n", 0, statVal);
1858 }
1859
1860 RTPrintf("\n");
1861 }
1862 else
1863 {
1864 if (details != VMINFO_MACHINEREADABLE)
1865 {
1866 RTPrintf("[!] FAILED calling console->getGuest at line %d!\n", __LINE__);
1867 GluePrintRCMessage(rc);
1868 }
1869 }
1870 }
1871
1872 /*
1873 * snapshots
1874 */
1875 ComPtr<ISnapshot> snapshot;
1876 rc = machine->GetSnapshot(Guid(), snapshot.asOutParam());
1877 if (SUCCEEDED(rc) && snapshot)
1878 {
1879 if (details != VMINFO_MACHINEREADABLE)
1880 RTPrintf("Snapshots:\n\n");
1881 showSnapshots(snapshot, details);
1882 }
1883
1884 if (details != VMINFO_MACHINEREADABLE)
1885 RTPrintf("\n");
1886 return S_OK;
1887}
1888
1889#if defined(_MSC_VER)
1890# pragma optimize("", on)
1891#endif
1892
1893int handleShowVMInfo(HandlerArg *a)
1894{
1895 HRESULT rc;
1896
1897 /* at least one option: the UUID or name of the VM */
1898 if (a->argc < 1)
1899 return errorSyntax(USAGE_SHOWVMINFO, "Incorrect number of parameters");
1900
1901 /* try to find the given machine */
1902 ComPtr <IMachine> machine;
1903 Guid uuid (a->argv[0]);
1904 if (!uuid.isEmpty())
1905 {
1906 CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
1907 }
1908 else
1909 {
1910 CHECK_ERROR (a->virtualBox, FindMachine (Bstr(a->argv[0]), machine.asOutParam()));
1911 if (SUCCEEDED (rc))
1912 machine->COMGETTER(Id) (uuid.asOutParam());
1913 }
1914 if (FAILED (rc))
1915 return 1;
1916
1917 /* 2nd option can be -details, -statistics or -argdump */
1918 VMINFO_DETAILS details = VMINFO_NONE;
1919 bool fDetails = false;
1920 bool fStatistics = false;
1921 bool fMachinereadable = false;
1922 for (int i=1;i<a->argc;i++)
1923 {
1924 if (!strcmp(a->argv[i], "-details"))
1925 fDetails = true;
1926 else
1927 if (!strcmp(a->argv[i], "-statistics"))
1928 fStatistics = true;
1929 if (!strcmp(a->argv[1], "-machinereadable"))
1930 fMachinereadable = true;
1931 }
1932 if (fMachinereadable)
1933 details = VMINFO_MACHINEREADABLE;
1934 else
1935 if (fDetails && fStatistics)
1936 details = VMINFO_FULL;
1937 else
1938 if (fDetails)
1939 details = VMINFO_STANDARD;
1940 else
1941 if (fStatistics)
1942 details = VMINFO_STATISTICS;
1943
1944 ComPtr <IConsole> console;
1945
1946 /* open an existing session for the VM */
1947 rc = a->virtualBox->OpenExistingSession (a->session, uuid);
1948 if (SUCCEEDED(rc))
1949 /* get the session machine */
1950 rc = a->session->COMGETTER(Machine)(machine.asOutParam());
1951 if (SUCCEEDED(rc))
1952 /* get the session console */
1953 rc = a->session->COMGETTER(Console)(console.asOutParam());
1954
1955 rc = showVMInfo(a->virtualBox, machine, details, console);
1956
1957 if (console)
1958 a->session->Close();
1959
1960 return SUCCEEDED (rc) ? 0 : 1;
1961}
1962
1963#endif /* !VBOX_ONLY_DOCS */
1964
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette