Index: /trunk/src/VBox/Main/ApplianceImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/ApplianceImpl.cpp	(revision 30880)
+++ /trunk/src/VBox/Main/ApplianceImpl.cpp	(revision 30881)
@@ -454,4 +454,38 @@
 }
 
+/**
+ * Public method implementation.
+ * @param aDisks
+ * @return
+ */
+STDMETHODIMP Appliance::COMGETTER(Machines)(ComSafeArrayOut(BSTR, aMachines))
+{
+    CheckComArgOutSafeArrayPointerValid(aMachines);
+
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    if (!isApplianceIdle())
+        return E_ACCESSDENIED;
+
+    com::SafeArray<BSTR> sfaMachines(m->llGuidsMachinesCreated.size());
+    size_t u = 0;
+    for (std::list<Guid>::const_iterator it = m->llGuidsMachinesCreated.begin();
+         it != m->llGuidsMachinesCreated.end();
+         ++it)
+    {
+        const Guid &uuid = *it;
+        Bstr bstr(uuid.toUtf16());
+        bstr.detachTo(&sfaMachines[u]);
+        ++u;
+    }
+
+    sfaMachines.detachTo(ComSafeArrayOutArg(aMachines));
+
+    return S_OK;
+}
+
 STDMETHODIMP Appliance::CreateVFSExplorer(IN_BSTR aURI, IVFSExplorer **aExplorer)
 {
Index: /trunk/src/VBox/Main/ApplianceImplImport.cpp
===================================================================
--- /trunk/src/VBox/Main/ApplianceImplImport.cpp	(revision 30880)
+++ /trunk/src/VBox/Main/ApplianceImplImport.cpp	(revision 30881)
@@ -1114,4 +1114,7 @@
     ImportStack stack(locInfo, reader.m_mapDisks, pProgress);
 
+    // clear the list of imported machines, if any
+    m->llGuidsMachinesCreated.clear();
+
     try
     {
@@ -1259,10 +1262,10 @@
 
         // finally, deregister and remove all machines
-        list<Bstr>::iterator itID;
-        for (itID = stack.llMachinesRegistered.begin();
-             itID != stack.llMachinesRegistered.end();
+        for (list<Guid>::iterator itID = m->llGuidsMachinesCreated.begin();
+             itID != m->llGuidsMachinesCreated.end();
              ++itID)
         {
-            Bstr bstrGuid = *itID;      // make a copy, Windows can't handle const Bstr
+            Guid guid = *itID;
+            Bstr bstrGuid = guid.toUtf16();
             ComPtr<IMachine> failedMachine;
             rc2 = mVirtualBox->UnregisterMachine(bstrGuid, failedMachine.asOutParam());
@@ -1738,5 +1741,5 @@
     rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam());
     if (FAILED(rc)) DebugBreakThrow(rc);
-    stack.llMachinesRegistered.push_back(bstrNewMachineId);
+    m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId));
 
     // Add floppies and CD-ROMs to the appropriate controllers.
@@ -2153,5 +2156,5 @@
     rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam());
     if (FAILED(rc)) DebugBreakThrow(rc);
-    stack.llMachinesRegistered.push_back(bstrNewMachineId);
+    m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId));
 }
 
Index: /trunk/src/VBox/Main/VirtualBoxImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 30880)
+++ /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 30881)
@@ -1392,4 +1392,6 @@
     /* save the global registry */
     rc = saveSettings();
+
+    alock.release();
 
     /* return the unregistered machine to the caller */
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 30880)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 30881)
@@ -1316,5 +1316,5 @@
   <interface
     name="IVirtualBox" extends="$unknown"
-    uuid="f0c2e058-8c72-4d56-95e7-3107627aba6e"
+    uuid="2275c97d-31b0-41c7-a138-c77d3c28406e"
     wsmap="managed"
   >
@@ -1710,5 +1710,4 @@
     <method name="unregisterMachine">
       <desc>
-
         Unregisters the machine previously registered using
         <link to="#registerMachine"/>. After successful method invocation, the
@@ -2894,5 +2893,5 @@
   <interface
      name="IAppliance" extends="$unknown"
-     uuid="e3ba9ab9-ac2c-4266-8bd2-91c4bf721ceb"
+     uuid="fb61a4fc-57e7-48d6-859b-71f37d484cf2"
      wsmap="managed"
      >
@@ -2946,5 +2945,6 @@
           <li>Finally, call <link to="#importMachines" /> to  create virtual machines in
               VirtualBox as instances of <link to="IMachine" /> that match the information in the
-              virtual system descriptions.
+              virtual system descriptions. After this call suceeded, the UUIDs of the machines created
+              can be found in the <link to="#machines" /> array attribute.
           </li>
         </ol>
@@ -3027,4 +3027,12 @@
     </attribute>
 
+    <attribute name="machines" type="wstring" readonly="yes" safearray="yes">
+      <desc>
+        Contains the UUIDs of the machines created from the information in this appliances. This is only
+        relevant for the import case, and will only contain data after a call to <link to="#importMachines" />
+        succeeded.
+      </desc>
+    </attribute>
+
     <method name="read">
       <desc>
@@ -3076,4 +3084,7 @@
         disk images, which can take a long time, this method operates asynchronously and
         returns an IProgress object to allow the caller to monitor the progress.
+
+        After the import succeeded, the UUIDs of the IMachine instances created can be
+        retrieved from the <link to="#machines" /> array attribute.
       </desc>
 
Index: /trunk/src/VBox/Main/include/ApplianceImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 30880)
+++ /trunk/src/VBox/Main/include/ApplianceImpl.h	(revision 30881)
@@ -84,4 +84,5 @@
     STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
     STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
+    STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines));
 
     /* IAppliance methods */
Index: /trunk/src/VBox/Main/include/ApplianceImplPrivate.h
===================================================================
--- /trunk/src/VBox/Main/include/ApplianceImplPrivate.h	(revision 30880)
+++ /trunk/src/VBox/Main/include/ApplianceImplPrivate.h	(revision 30881)
@@ -80,4 +80,6 @@
     ULONG               cDisks;
     Utf8Str             strOVFSHA1Digest;
+
+    std::list<Guid>     llGuidsMachinesCreated;
 };
 
@@ -166,5 +168,4 @@
     std::list<MyHardDiskAttachment> llHardDiskAttachments;      // disks that were attached
     std::list< ComPtr<IMedium> >    llHardDisksCreated;         // media that were created
-    std::list<Bstr>                 llMachinesRegistered;       // machines that were registered; list of string UUIDs
 
     ImportStack(const LocationInfo &aLocInfo,
Index: /trunk/src/VBox/Main/testcase/tstOVF.cpp
===================================================================
--- /trunk/src/VBox/Main/testcase/tstOVF.cpp	(revision 30880)
+++ /trunk/src/VBox/Main/testcase/tstOVF.cpp	(revision 30881)
@@ -75,10 +75,13 @@
  * Imports the given OVF file, with all bells and whistles.
  * Throws MyError on errors.
+ * @param pcszPrefix Descriptive short prefix string for console output.
  * @param pVirtualBox VirtualBox instance.
- * @param pcszOVF File to import.
+ * @param pcszOVF0 File to import.
+ * @param llMachinesCreated out: UUIDs of machines that were created so that caller can clean up.
  */
 void importOVF(const char *pcszPrefix,
                ComPtr<IVirtualBox> &pVirtualBox,
-               const char *pcszOVF0)
+               const char *pcszOVF0,
+               std::list<Guid> &llMachinesCreated)
 {
     char szAbsOVF[RTPATH_MAX];
@@ -88,23 +91,18 @@
     ComPtr<IAppliance> pAppl;
     HRESULT rc = pVirtualBox->CreateAppliance(pAppl.asOutParam());
-    if (FAILED(rc))
-        throw MyError(rc, "failed to create appliance\n");
+    if (FAILED(rc)) throw MyError(rc, "failed to create appliance\n");
 
     ComPtr<IProgress> pProgress;
     rc = pAppl->Read(Bstr(szAbsOVF), pProgress.asOutParam());
-    if (FAILED(rc))
-        throw MyError(rc, "Appliance::Read() failed\n");
+    if (FAILED(rc)) throw MyError(rc, "Appliance::Read() failed\n");
     rc = pProgress->WaitForCompletion(-1);
-    if (FAILED(rc))
-        throw MyError(rc, "Progress::WaitForCompletion() failed\n");
+    if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n");
     LONG rc2;
     pProgress->COMGETTER(ResultCode)(&rc2);
-    if (FAILED(rc2))
-        throw MyError(rc2, "Appliance::Read() failed\n", pProgress);
+    if (FAILED(rc2)) throw MyError(rc2, "Appliance::Read() failed\n", pProgress);
 
     RTPrintf("%s: interpreting appliance \"%s\"...\n", pcszPrefix, szAbsOVF);
     rc = pAppl->Interpret();
-    if (FAILED(rc))
-        throw MyError(rc, "Appliance::Interpret() failed\n");
+    if (FAILED(rc)) throw MyError(rc, "Appliance::Interpret() failed\n");
 
     com::SafeIfaceArray<IVirtualSystemDescription> aDescriptions;
@@ -126,4 +124,6 @@
                                    ComSafeArrayAsOutParam(aVboxValues),
                                    ComSafeArrayAsOutParam(aExtraConfigValues));
+        if (FAILED(rc)) throw MyError(rc, "VirtualSystemDescription::GetDescription() failed\n");
+
         for (uint32_t u2 = 0;
              u2 < aTypes.size();
@@ -234,12 +234,22 @@
     RTPrintf("%s: importing %d machine(s)...\n", pcszPrefix, aDescriptions.size());
     rc = pAppl->ImportMachines(pProgress.asOutParam());
-    if (FAILED(rc))
-        throw MyError(rc, "Appliance::ImportMachines() failed\n");
+    if (FAILED(rc)) throw MyError(rc, "Appliance::ImportMachines() failed\n");
     rc = pProgress->WaitForCompletion(-1);
-    if (FAILED(rc))
-        throw MyError(rc, "Progress::WaitForCompletion() failed\n");
+    if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n");
     pProgress->COMGETTER(ResultCode)(&rc2);
-    if (FAILED(rc2))
-        throw MyError(rc2, "Progress::GetResultCode() failed\n");
+    if (FAILED(rc2)) throw MyError(rc2, "Progress::GetResultCode() failed\n");
+
+    com::SafeArray<BSTR> aMachineUUIDs;
+    rc = pAppl->COMGETTER(Machines)(ComSafeArrayAsOutParam(aMachineUUIDs));
+    if (FAILED(rc)) throw MyError(rc, "Appliance::GetMachines() failed\n");
+
+    for (size_t u = 0;
+         u < aMachineUUIDs.size();
+         ++u)
+    {
+        RTPrintf("%s: created machine %u: %ls\n", pcszPrefix, u, aMachineUUIDs[u]);
+        llMachinesCreated.push_back(Guid(Bstr(aMachineUUIDs[u])));
+    }
+
     RTPrintf("%s: success!\n", pcszPrefix);
 }
@@ -255,6 +265,5 @@
 {
     int vrc = RTFileCopy("ovf-testcases/ovf-dummy.vmdk", pcszDest);
-    if (RT_FAILURE(vrc))
-        throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str());
+    if (RT_FAILURE(vrc)) throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str());
     llFiles2Delete.push_back(pcszDest);
 }
@@ -273,4 +282,7 @@
 
     std::list<Utf8Str> llFiles2Delete;
+    std::list<Guid> llMachinesCreated;
+
+    ComPtr<IVirtualBox> pVirtualBox;
 
     try
@@ -278,18 +290,14 @@
         RTPrintf("Initializing COM...\n");
         rc = com::Initialize();
-        if (FAILED(rc))
-            throw MyError(rc, "failed to initialize COM!\n");
-
-        ComPtr<IVirtualBox> pVirtualBox;
+        if (FAILED(rc)) throw MyError(rc, "failed to initialize COM!\n");
+
         ComPtr<ISession> pSession;
 
         RTPrintf("Creating VirtualBox object...\n");
         rc = pVirtualBox.createLocalObject(CLSID_VirtualBox);
-        if (FAILED(rc))
-            throw MyError(rc, "failed to create the VirtualBox object!\n");
+        if (FAILED(rc)) throw MyError(rc, "failed to create the VirtualBox object!\n");
 
         rc = pSession.createInprocObject(CLSID_Session);
-        if (FAILED(rc))
-            throw MyError(rc, "failed to create a session object!\n");
+        if (FAILED(rc)) throw MyError(rc, "failed to create a session object!\n");
 
         // create the event queue
@@ -298,16 +306,14 @@
 
         // testcase 1: import ovf-joomla-0.9/joomla-1.1.4-ovf.ovf
-//         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
-//         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
-//         importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf");
+        copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
+        copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
+        importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf", llMachinesCreated);
 
         // testcase 2: import ovf-winxp-vbox-sharedfolders/winxp.ovf
         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/Windows 5.1 XP 1 merged.vmdk");
         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk");
-        importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf");
-
-        RTPrintf ("tstOVF all done, no errors.\n");
-
-        // todo: cleanup created machines, created disk images
+        importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf", llMachinesCreated);
+
+        RTPrintf("Machine imports done, no errors. Cleaning up...\n");
     }
     catch (MyError &e)
@@ -317,5 +323,58 @@
     }
 
-    // clean up
+    try
+    {
+        // clean up the machines created
+        for (std::list<Guid>::const_iterator it = llMachinesCreated.begin();
+             it != llMachinesCreated.end();
+             ++it)
+        {
+//             const Guid &uuid = *it;
+//             Bstr bstrUUID(uuid.toUtf16());
+//             ComPtr<IMachine> pMachine;
+//             rc = pVirtualBox->GetMachine(bstrUUID, pMachine.asOutParam());
+//             if (FAILED(rc)) throw MyError(rc, "VirtualBox::FindMachine() failed\n");
+//
+//             SafeIfaceArray<IMediumAttachment> aMediumAttachments;
+//             rc = pMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(aMediumAttachments));
+//             if (FAILED(rc)) throw MyError(rc, "Machine::MediumAttachments() failed\n");
+//
+//             for (size_t u2 = 0;
+//                  u2 < aMediumAttachments.size();
+//                  ++u2)
+//             {
+//                 ComPtr<IMediumAttachment> pMediumAttachment(aMediumAttachments[u2]);
+//                 ComPtr<IMedium> pMedium;
+//                 rc = pMediumAttachment->COMGETTER(Medium)(pMedium.asOutParam());
+//                 if (FAILED(rc)) throw MyError(rc, "MediumAttachment::GetMedium() failed\n");
+//
+//                 if (!pMedium.isNull())
+//                 {
+//                     Bstr bstrLocation;
+//                     rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
+//                     if (FAILED(rc)) throw MyError(rc, "Medium::GetLocation() failed\n");
+//
+//                     llFiles2Delete.push_back(bstrLocation);
+//                 }
+//             }
+
+            RTPrintf("  Deleting machine %ls...\n", bstrUUID.raw());
+            pVirtualBox->UnregisterMachine(bstrUUID, pMachine.asOutParam());
+            if (FAILED(rc)) throw MyError(rc, "VirtualBox::UnregisterMachine() failed\n");
+
+            if (!pMachine.isNull())
+            {
+                rc = pMachine->DeleteSettings();
+                if (FAILED(rc)) throw MyError(rc, "Machine::DeleteSettings() failed\n");
+            }
+        }
+    }
+    catch (MyError &e)
+    {
+        rc = e.m_rc;
+        RTPrintf("%s", e.m_str.c_str());
+    }
+
+    // clean up the VMDK copies that we made in copyDummyDiskImage()
     for (std::list<Utf8Str>::const_iterator it = llFiles2Delete.begin();
          it != llFiles2Delete.end();
@@ -326,6 +385,9 @@
     }
 
+    pVirtualBox.setNull();
+
     RTPrintf("Shutting down COM...\n");
     com::Shutdown();
+    RTPrintf ("tstOVF all done!\n");
 
     return rc;
