Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp	(revision 19036)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp	(revision 19037)
@@ -440,19 +440,47 @@
     if (fModifyCompact)
     {
-#if 1
-        RTPrintf("Error: Compact hard disk operation is not implemented!\n");
-        RTPrintf("The functionality will be restored later.\n");
-        return 1;
-#else
+        bool unknown = false;
         /* the hard disk image might not be registered */
         if (!hardDisk)
         {
-            a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam());
-            if (!hardDisk)
-                return errorArgument("Hard disk image not found");
-        }
-
-        /** @todo implement compacting of images. */
-#endif
+            unknown = true;
+            rc = a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam());
+            if (rc == VBOX_E_FILE_ERROR)
+            {
+                char szFilenameAbs[RTPATH_MAX] = "";
+                int vrc = RTPathAbs(FilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs));
+                if (RT_FAILURE(vrc))
+                {
+                    RTPrintf("Cannot convert filename \"%s\" to absolute path\n", FilenameOrUuid);
+                    return 1;
+                }
+                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, hardDisk.asOutParam()));
+            }
+            else if (FAILED(rc))
+                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam()));
+        }
+        if (SUCCEEDED(rc) && hardDisk)
+        {
+            ComPtr<IProgress> progress;
+            CHECK_ERROR(hardDisk, Compact(progress.asOutParam()));
+            showProgress(progress);
+            progress->COMGETTER(ResultCode)(&rc);
+            if (FAILED(rc))
+            {
+                if (rc == VBOX_E_NOT_SUPPORTED)
+                {
+                    RTPrintf("Error: Compact hard disk operation is not implemented!\n");
+                    RTPrintf("The functionality will be restored later.\n");
+                }
+                else if (rc == E_NOTIMPL)
+                {
+                    RTPrintf("Error: Compact hard disk operation for this format is not implemented yet!\n");
+                }
+                else
+                    com::GluePrintRCMessage(rc);
+            }
+            if (unknown)
+                hardDisk->Close();
+        }
     }
 
@@ -557,8 +585,21 @@
     {
         rc = a->virtualBox->FindHardDisk(src, srcDisk.asOutParam());
-        /* no? well, then it's an unkwnown image */
+        /* no? well, then it's an unknown image */
         if (FAILED (rc))
         {
-            CHECK_ERROR(a->virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, srcDisk.asOutParam()));
+            rc = a->virtualBox->OpenHardDisk(src, AccessMode_ReadWrite, srcDisk.asOutParam());
+            if (rc == VBOX_E_FILE_ERROR)
+            {
+                char szFilenameAbs[RTPATH_MAX] = "";
+                int vrc = RTPathAbs(Utf8Str(src), szFilenameAbs, sizeof(szFilenameAbs));
+                if (RT_FAILURE(vrc))
+                {
+                    RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Utf8Str(src).raw());
+                    return 1;
+                }
+                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, srcDisk.asOutParam()));
+            }
+            else if (FAILED(rc))
+                CHECK_ERROR(a->virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, srcDisk.asOutParam()));
             if (SUCCEEDED (rc))
             {
@@ -1061,5 +1102,18 @@
         if (FAILED (rc))
         {
-            CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam()));
+            rc = a->virtualBox->OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam());
+            if (rc == VBOX_E_FILE_ERROR)
+            {
+                char szFilenameAbs[RTPATH_MAX] = "";
+                int vrc = RTPathAbs(FilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs));
+                if (RT_FAILURE(vrc))
+                {
+                    RTPrintf("Cannot convert filename \"%s\" to absolute path\n", FilenameOrUuid);
+                    return 1;
+                }
+                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, hardDisk.asOutParam()));
+            }
+            else if (FAILED(rc))
+                CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(FilenameOrUuid), AccessMode_ReadWrite, hardDisk.asOutParam()));
             if (SUCCEEDED (rc))
             {
