VirtualBox

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

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

#2954 & #3569: Linux TAP driver is embedded to vboxnetflt. API, VBoxManage and VirtualBox now provide host-only network attachment on Linux.

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