Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp	(revision 33763)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp	(revision 33764)
@@ -209,4 +209,7 @@
     RTR3Init();
 
+    /*
+     * Parse the global options
+     */
     bool fShowLogo = false;
     bool fShowHelp = false;
@@ -214,5 +217,4 @@
     int  iCmdArg;
 
-    /* global options */
     for (int i = 1; i < argc || argc <= iCmd; i++)
     {
@@ -275,28 +277,25 @@
 
 
-#ifdef VBOX_ONLY_DOCS
-    int rc = 0;
-#else /* !VBOX_ONLY_DOCS */
+#ifndef VBOX_ONLY_DOCS
+    /*
+     * Initialize COM.
+     */
     using namespace com;
-    HRESULT rc = 0;
-
-    rc = com::Initialize();
-    if (FAILED(rc))
-    {
-        RTMsgError("Failed to initialize COM!");
-        return rc;
-    }
+    HRESULT hrc = com::Initialize();
+    if (FAILED(hrc))
+        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
 
     /*
-     * The input is in the host OS'es codepage (NT guarantees ACP).
-     * For VBox we use UTF-8 and convert to UCS-2 when calling (XP)COM APIs.
-     * For simplicity, just convert the argv[] array here.
+     * The input is ASSUMED to be in the current process codeset (NT guarantees
+     * ACP, unixy systems doesn't guarantee anything).  This loop converts all
+     * the argv[*] strings to UTF-8, which is a tad ugly but who cares.
+     * (As a rule all strings in VirtualBox are UTF-8.)
      */
     for (int i = iCmdArg; i < argc; i++)
     {
-        char *converted;
-        RTStrCurrentCPToUtf8(&converted, argv[i]);
-        if (converted)
-            argv[i] = converted;
+        char *pszConverted;
+        int rc = RTStrCurrentCPToUtf8(&pszConverted, argv[i]);
+        if (RT_SUCCESS(rc))
+            argv[i] = pszConverted;
         else
             /* Conversion was not possible,probably due to invalid characters.
@@ -305,139 +304,142 @@
     }
 
+    RTEXITCODE rcExit = RTEXITCODE_FAILURE;
     do
     {
+    ///////////////////////////////////////////////////////////////////////////
     // scopes all the stuff till shutdown
-    ////////////////////////////////////////////////////////////////////////////
-
-    /* convertfromraw: does not need a VirtualBox instantiation. */
-    if (argc >= iCmdArg && (   !strcmp(argv[iCmd], "convertfromraw")
-                            || !strcmp(argv[iCmd], "convertdd")))
-    {
-        rc = handleConvertFromRaw(argc - iCmdArg, argv + iCmdArg);
-        break;
-    }
-
-    ComPtr<IVirtualBox> virtualBox;
-    ComPtr<ISession> session;
-
-    rc = virtualBox.createLocalObject(CLSID_VirtualBox);
-    if (FAILED(rc))
-        RTMsgError("Failed to create the VirtualBox object!");
-    else
-    {
-        rc = session.createInprocObject(CLSID_Session);
-        if (FAILED(rc))
-            RTMsgError("Failed to create a session object!");
-    }
-
-    if (FAILED(rc))
-    {
-        com::ErrorInfo info;
-        if (!info.isFullAvailable() && !info.isBasicAvailable())
-        {
-            com::GluePrintRCMessage(rc);
-            RTMsgError("Most likely, the VirtualBox COM server is not running or failed to start.");
-        }
+        /*
+         * convertfromraw: does not need a VirtualBox instantiation.
+         */
+        if (argc >= iCmdArg && (   !strcmp(argv[iCmd], "convertfromraw")
+                                || !strcmp(argv[iCmd], "convertdd")))
+        {
+            rcExit = handleConvertFromRaw(argc - iCmdArg, argv + iCmdArg);
+            break;
+        }
+
+        /*
+         * Get the remote VirtualBox object and create a local session object.
+         */
+        ComPtr<IVirtualBox> virtualBox;
+        ComPtr<ISession> session;
+
+        hrc = virtualBox.createLocalObject(CLSID_VirtualBox);
+        if (FAILED(hrc))
+            RTMsgError("Failed to create the VirtualBox object!");
         else
-            com::GluePrintErrorInfo(info);
-        break;
-    }
-
-    HandlerArg handlerArg = { 0, NULL, virtualBox, session };
-
-    /*
-     * All registered command handlers
-     */
-    static const struct
-    {
-        const char *command;
-        USAGECATEGORY help;
-        int (*handler)(HandlerArg *a);
-    } s_commandHandlers[] =
-    {
-        { "internalcommands", 0,                       handleInternalCommands },
-        { "list",             USAGE_LIST,              handleList },
-        { "showvminfo",       USAGE_SHOWVMINFO,        handleShowVMInfo },
-        { "registervm",       USAGE_REGISTERVM,        handleRegisterVM },
-        { "unregistervm",     USAGE_UNREGISTERVM,      handleUnregisterVM },
-        { "createhd",         USAGE_CREATEHD,          handleCreateHardDisk },
-        { "createvdi",        USAGE_CREATEHD,          handleCreateHardDisk }, /* backward compatibility */
-        { "modifyhd",         USAGE_MODIFYHD,          handleModifyHardDisk },
-        { "modifyvdi",        USAGE_MODIFYHD,          handleModifyHardDisk }, /* backward compatibility */
-        { "clonehd",          USAGE_CLONEHD,           handleCloneHardDisk },
-        { "clonevdi",         USAGE_CLONEHD,           handleCloneHardDisk }, /* backward compatibility */
-        { "addiscsidisk",     USAGE_ADDISCSIDISK,      handleAddiSCSIDisk },
-        { "createvm",         USAGE_CREATEVM,          handleCreateVM },
-        { "modifyvm",         USAGE_MODIFYVM,          handleModifyVM },
-        { "startvm",          USAGE_STARTVM,           handleStartVM },
-        { "controlvm",        USAGE_CONTROLVM,         handleControlVM },
-        { "discardstate",     USAGE_DISCARDSTATE,      handleDiscardState },
-        { "adoptstate",       USAGE_ADOPTSTATE,        handleAdoptState },
-        { "snapshot",         USAGE_SNAPSHOT,          handleSnapshot },
-        { "closemedium",      USAGE_CLOSEMEDIUM,       handleCloseMedium },
-        { "storageattach",    USAGE_STORAGEATTACH,     handleStorageAttach },
-        { "storagectl",       USAGE_STORAGECONTROLLER, handleStorageController },
-        { "showhdinfo",       USAGE_SHOWHDINFO,        handleShowHardDiskInfo },
-        { "showvdiinfo",      USAGE_SHOWHDINFO,        handleShowHardDiskInfo }, /* backward compatibility */
-        { "getextradata",     USAGE_GETEXTRADATA,      handleGetExtraData },
-        { "setextradata",     USAGE_SETEXTRADATA,      handleSetExtraData },
-        { "setproperty",      USAGE_SETPROPERTY,       handleSetProperty },
-        { "usbfilter",        USAGE_USBFILTER,         handleUSBFilter },
-        { "sharedfolder",     USAGE_SHAREDFOLDER,      handleSharedFolder },
-        { "vmstatistics",     USAGE_VM_STATISTICS,     handleVMStatistics },
+        {
+            hrc = session.createInprocObject(CLSID_Session);
+            if (FAILED(hrc))
+                RTMsgError("Failed to create a session object!");
+        }
+        if (FAILED(hrc))
+        {
+            com::ErrorInfo info;
+            if (!info.isFullAvailable() && !info.isBasicAvailable())
+            {
+                com::GluePrintRCMessage(hrc);
+                RTMsgError("Most likely, the VirtualBox COM server is not running or failed to start.");
+            }
+            else
+                com::GluePrintErrorInfo(info);
+            break;
+        }
+
+        /*
+         * All registered command handlers
+         */
+        static const struct
+        {
+            const char *command;
+            USAGECATEGORY help;
+            int (*handler)(HandlerArg *a);
+        } s_commandHandlers[] =
+        {
+            { "internalcommands", 0,                       handleInternalCommands },
+            { "list",             USAGE_LIST,              handleList },
+            { "showvminfo",       USAGE_SHOWVMINFO,        handleShowVMInfo },
+            { "registervm",       USAGE_REGISTERVM,        handleRegisterVM },
+            { "unregistervm",     USAGE_UNREGISTERVM,      handleUnregisterVM },
+            { "createhd",         USAGE_CREATEHD,          handleCreateHardDisk },
+            { "createvdi",        USAGE_CREATEHD,          handleCreateHardDisk }, /* backward compatibility */
+            { "modifyhd",         USAGE_MODIFYHD,          handleModifyHardDisk },
+            { "modifyvdi",        USAGE_MODIFYHD,          handleModifyHardDisk }, /* backward compatibility */
+            { "clonehd",          USAGE_CLONEHD,           handleCloneHardDisk },
+            { "clonevdi",         USAGE_CLONEHD,           handleCloneHardDisk }, /* backward compatibility */
+            { "addiscsidisk",     USAGE_ADDISCSIDISK,      handleAddiSCSIDisk },
+            { "createvm",         USAGE_CREATEVM,          handleCreateVM },
+            { "modifyvm",         USAGE_MODIFYVM,          handleModifyVM },
+            { "startvm",          USAGE_STARTVM,           handleStartVM },
+            { "controlvm",        USAGE_CONTROLVM,         handleControlVM },
+            { "discardstate",     USAGE_DISCARDSTATE,      handleDiscardState },
+            { "adoptstate",       USAGE_ADOPTSTATE,        handleAdoptState },
+            { "snapshot",         USAGE_SNAPSHOT,          handleSnapshot },
+            { "closemedium",      USAGE_CLOSEMEDIUM,       handleCloseMedium },
+            { "storageattach",    USAGE_STORAGEATTACH,     handleStorageAttach },
+            { "storagectl",       USAGE_STORAGECONTROLLER, handleStorageController },
+            { "showhdinfo",       USAGE_SHOWHDINFO,        handleShowHardDiskInfo },
+            { "showvdiinfo",      USAGE_SHOWHDINFO,        handleShowHardDiskInfo }, /* backward compatibility */
+            { "getextradata",     USAGE_GETEXTRADATA,      handleGetExtraData },
+            { "setextradata",     USAGE_SETEXTRADATA,      handleSetExtraData },
+            { "setproperty",      USAGE_SETPROPERTY,       handleSetProperty },
+            { "usbfilter",        USAGE_USBFILTER,         handleUSBFilter },
+            { "sharedfolder",     USAGE_SHAREDFOLDER,      handleSharedFolder },
+            { "vmstatistics",     USAGE_VM_STATISTICS,     handleVMStatistics },
 #ifdef VBOX_WITH_GUEST_PROPS
-        { "guestproperty",    USAGE_GUESTPROPERTY,     handleGuestProperty },
+            { "guestproperty",    USAGE_GUESTPROPERTY,     handleGuestProperty },
 #endif
 #ifdef VBOX_WITH_GUEST_CONTROL
-        { "guestcontrol",     USAGE_GUESTCONTROL,      handleGuestControl },
+            { "guestcontrol",     USAGE_GUESTCONTROL,      handleGuestControl },
 #endif
-        { "metrics",          USAGE_METRICS,           handleMetrics },
-        { "import",           USAGE_IMPORTAPPLIANCE,   handleImportAppliance },
-        { "export",           USAGE_EXPORTAPPLIANCE,   handleExportAppliance },
+            { "metrics",          USAGE_METRICS,           handleMetrics },
+            { "import",           USAGE_IMPORTAPPLIANCE,   handleImportAppliance },
+            { "export",           USAGE_EXPORTAPPLIANCE,   handleExportAppliance },
 #ifdef VBOX_WITH_NETFLT
-        { "hostonlyif",       USAGE_HOSTONLYIFS,       handleHostonlyIf },
+            { "hostonlyif",       USAGE_HOSTONLYIFS,       handleHostonlyIf },
 #endif
-        { "dhcpserver",       USAGE_DHCPSERVER,        handleDHCPServer},
-        { "vrde",             USAGE_VRDE,              handleVRDE},
-        { NULL,               0,                       NULL }
-    };
-
-    int commandIndex;
-    for (commandIndex = 0; s_commandHandlers[commandIndex].command != NULL; commandIndex++)
-    {
-        if (!strcmp(s_commandHandlers[commandIndex].command, argv[iCmd]))
-        {
-            handlerArg.argc = argc - iCmdArg;
-            handlerArg.argv = &argv[iCmdArg];
-
-            if (   fShowHelp
-                || (   argc - iCmdArg == 0
-                    && s_commandHandlers[commandIndex].help))
-            {
-                printUsage(s_commandHandlers[commandIndex].help, g_pStdOut);
-                rc = 1; /* error */
-            }
-            else
-                rc = s_commandHandlers[commandIndex].handler(&handlerArg);
-            break;
-        }
-    }
-    if (!s_commandHandlers[commandIndex].command)
-        rc = errorSyntax(USAGE_ALL, "Invalid command '%s'", Utf8Str(argv[iCmd]).c_str());
-
-    /* Although all handlers should always close the session if they open it,
-     * we do it here just in case if some of the handlers contains a bug --
-     * leaving the direct session not closed will turn the machine state to
-     * Aborted which may have unwanted side effects like killing the saved
-     * state file (if the machine was in the Saved state before). */
-    session->UnlockMachine();
-
-    EventQueue::getMainEventQueue()->processEventQueue(0);
+            { "dhcpserver",       USAGE_DHCPSERVER,        handleDHCPServer},
+            { "vrde",             USAGE_VRDE,              handleVRDE},
+            { NULL,               0,                       NULL }
+        };
+
+        HandlerArg  handlerArg = { 0, NULL, virtualBox, session };
+        int         commandIndex;
+        for (commandIndex = 0; s_commandHandlers[commandIndex].command != NULL; commandIndex++)
+        {
+            if (!strcmp(s_commandHandlers[commandIndex].command, argv[iCmd]))
+            {
+                handlerArg.argc = argc - iCmdArg;
+                handlerArg.argv = &argv[iCmdArg];
+
+                if (   fShowHelp
+                    || (   argc - iCmdArg == 0
+                        && s_commandHandlers[commandIndex].help))
+                {
+                    printUsage(s_commandHandlers[commandIndex].help, g_pStdOut);
+                    rcExit = RTEXITCODE_FAILURE; /* error */
+                }
+                else
+                    rcExit = (RTEXITCODE)s_commandHandlers[commandIndex].handler(&handlerArg); /** @todo Change to return RTEXITCODE. */
+                break;
+            }
+        }
+        if (!s_commandHandlers[commandIndex].command)
+            rcExit = errorSyntax(USAGE_ALL, "Invalid command '%s'", Utf8Str(argv[iCmd]).c_str());
+
+        /* Although all handlers should always close the session if they open it,
+         * we do it here just in case if some of the handlers contains a bug --
+         * leaving the direct session not closed will turn the machine state to
+         * Aborted which may have unwanted side effects like killing the saved
+         * state file (if the machine was in the Saved state before). */
+        session->UnlockMachine();
+
+        EventQueue::getMainEventQueue()->processEventQueue(0);
+
     // end "all-stuff" scope
-    ////////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////
     } while (0);
 
     com::Shutdown();
-#endif /* !VBOX_ONLY_DOCS */
 
     /*
@@ -445,6 +447,12 @@
      */
     for (int i = iCmdArg; i < argc; i++)
+    {
         RTStrFree(argv[i]);
-
-    return rc != 0;
+        argv[i] = NULL;
+    }
+
+    return rcExit;
+#else  /* VBOX_ONLY_DOCS */
+    return RTEXITCODE_SUCCESS;
+#endif /* VBOX_ONLY_DOCS */
 }
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h	(revision 33763)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h	(revision 33764)
@@ -144,7 +144,7 @@
 /* VBoxManageHelp.cpp */
 void printUsage(USAGECATEGORY u64Cmd, PRTSTREAM pStrm);
-int errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...);
-int errorGetOpt(USAGECATEGORY u64Cmd, int rc, union RTGETOPTUNION const *pValueUnion);
-int errorArgument(const char *pszFormat, ...);
+RTEXITCODE errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...);
+RTEXITCODE errorGetOpt(USAGECATEGORY u64Cmd, int rc, union RTGETOPTUNION const *pValueUnion);
+RTEXITCODE errorArgument(const char *pszFormat, ...);
 
 void printUsageInternal(USAGECATEGORY u64Cmd, PRTSTREAM pStrm);
@@ -211,4 +211,5 @@
 int handleVMStatistics(HandlerArg *a);
 int handleVRDE(HandlerArg *a);
+int handleExtPack(HandlerArg *a);
 
 /* VBoxManageDisk.cpp */
@@ -216,5 +217,5 @@
 int handleModifyHardDisk(HandlerArg *a);
 int handleCloneHardDisk(HandlerArg *a);
-int handleConvertFromRaw(int argc, char *argv[]);
+RTEXITCODE handleConvertFromRaw(int argc, char *argv[]);
 int handleAddiSCSIDisk(HandlerArg *a);
 int handleShowHardDiskInfo(HandlerArg *a);
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp	(revision 33763)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp	(revision 33764)
@@ -785,5 +785,5 @@
 };
 
-int handleConvertFromRaw(int argc, char *argv[])
+RTEXITCODE handleConvertFromRaw(int argc, char *argv[])
 {
     int rc = VINF_SUCCESS;
@@ -952,5 +952,5 @@
         RTFileClose(File);
 
-    return RT_FAILURE(rc);
+    return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
 }
 
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp	(revision 33763)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp	(revision 33764)
@@ -731,6 +731,7 @@
 /**
  * Print a usage synopsis and the syntax error message.
+ * @returns RTEXITCODE_SYNTAX.
  */
-int errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...)
+RTEXITCODE errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...)
 {
     va_list args;
@@ -745,5 +746,5 @@
     RTStrmPrintf(g_pStdErr, "\nSyntax error: %N\n", pszFormat, &args);
     va_end(args);
-    return 1;
+    return RTEXITCODE_SYNTAX;
 }
 
@@ -751,5 +752,5 @@
  * errorSyntax for RTGetOpt users.
  *
- * @returns 1.
+ * @returns RTEXITCODE_SYNTAX.
  *
  * @param   fUsageCategory  The usage category of the command.
@@ -757,5 +758,5 @@
  * @param   pValueUnion     The value union.
  */
-int errorGetOpt(USAGECATEGORY fUsageCategory, int rc, union RTGETOPTUNION const *pValueUnion)
+RTEXITCODE errorGetOpt(USAGECATEGORY fUsageCategory, int rc, union RTGETOPTUNION const *pValueUnion)
 {
     showLogo(g_pStdErr); // show logo even if suppressed
@@ -768,22 +769,24 @@
 
     if (rc == VINF_GETOPT_NOT_OPTION)
-        return RTMsgError("Invalid parameter '%s'", pValueUnion->psz);
+        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid parameter '%s'", pValueUnion->psz);
     if (rc > 0)
     {
         if (RT_C_IS_PRINT(rc))
-            return RTMsgError("Invalid option -%c", rc);
-        return RTMsgError("Invalid option case %i", rc);
+            return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid option -%c", rc);
+        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid option case %i", rc);
     }
     if (rc == VERR_GETOPT_UNKNOWN_OPTION)
-        return RTMsgError("Unknown option: %s", pValueUnion->psz);
+        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown option: %s", pValueUnion->psz);
     if (pValueUnion->pDef)
-        return RTMsgError("%s: %Rrs", pValueUnion->pDef->pszLong, rc);
-    return RTMsgError("%Rrs", rc);
+        return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%s: %Rrs", pValueUnion->pDef->pszLong, rc);
+    return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%Rrs", rc);
 }
 
 /**
  * Print an error message without the syntax stuff.
+ *
+ * @returns RTEXITCODE_SYNTAX.
  */
-int errorArgument(const char *pszFormat, ...)
+RTEXITCODE errorArgument(const char *pszFormat, ...)
 {
     va_list args;
@@ -791,4 +794,4 @@
     RTMsgErrorV(pszFormat, args);
     va_end(args);
-    return 1;
+    return RTEXITCODE_SYNTAX;
 }
