Index: trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp	(revision 42628)
+++ trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp	(revision 42668)
@@ -73,10 +73,20 @@
 typedef struct COPYCONTEXT
 {
-    IGuest *pGuest;
+    COPYCONTEXT() : fVerbose(false), fDryRun(false), fHostToGuest(false)
+    {
+    }
+
+#ifndef VBOX_WITH_GUEST_CONTROL2
+    ComPtr<IGuest> pGuest;
+#else
+    ComPtr<IGuestSession> pGuestSession;
+#endif
     bool fVerbose;
     bool fDryRun;
     bool fHostToGuest;
-    char *pszUsername;
-    char *pszPassword;
+#ifndef VBOX_WITH_GUEST_CONTROL2
+    Utf8Str strUsername;
+    Utf8Str strPassword;
+#endif
 } COPYCONTEXT, *PCOPYCONTEXT;
 
@@ -334,32 +344,32 @@
 static int ctrlExecProcessStatusToExitCode(ExecuteProcessStatus_T enmStatus, ULONG uExitCode)
 {
-    int rc = EXITCODEEXEC_SUCCESS;
+    int vrc = EXITCODEEXEC_SUCCESS;
     switch (enmStatus)
     {
         case ExecuteProcessStatus_Started:
-            rc = EXITCODEEXEC_SUCCESS;
+            vrc = EXITCODEEXEC_SUCCESS;
             break;
         case ExecuteProcessStatus_TerminatedNormally:
-            rc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
+            vrc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
             break;
         case ExecuteProcessStatus_TerminatedSignal:
-            rc = EXITCODEEXEC_TERM_SIGNAL;
+            vrc = EXITCODEEXEC_TERM_SIGNAL;
             break;
         case ExecuteProcessStatus_TerminatedAbnormally:
-            rc = EXITCODEEXEC_TERM_ABEND;
+            vrc = EXITCODEEXEC_TERM_ABEND;
             break;
         case ExecuteProcessStatus_TimedOutKilled:
-            rc = EXITCODEEXEC_TIMEOUT;
+            vrc = EXITCODEEXEC_TIMEOUT;
             break;
         case ExecuteProcessStatus_TimedOutAbnormally:
-            rc = EXITCODEEXEC_TIMEOUT;
+            vrc = EXITCODEEXEC_TIMEOUT;
             break;
         case ExecuteProcessStatus_Down:
             /* Service/OS is stopping, process was killed, so
              * not exactly an error of the started process ... */
-            rc = EXITCODEEXEC_DOWN;
+            vrc = EXITCODEEXEC_DOWN;
             break;
         case ExecuteProcessStatus_Error:
-            rc = EXITCODEEXEC_FAILED;
+            vrc = EXITCODEEXEC_FAILED;
             break;
         default:
@@ -367,5 +377,5 @@
             break;
     }
-    return rc;
+    return vrc;
 }
 #else
@@ -408,41 +418,41 @@
 static int ctrlExecProcessStatusToExitCode(ProcessStatus_T enmStatus, ULONG uExitCode)
 {
-    int rc = EXITCODEEXEC_SUCCESS;
+    int vrc = EXITCODEEXEC_SUCCESS;
     switch (enmStatus)
     {
         case ProcessStatus_Starting:
-            rc = EXITCODEEXEC_SUCCESS;
+            vrc = EXITCODEEXEC_SUCCESS;
             break;
         case ProcessStatus_Started:
-            rc = EXITCODEEXEC_SUCCESS;
+            vrc = EXITCODEEXEC_SUCCESS;
             break;
         case ProcessStatus_Paused:
-            rc = EXITCODEEXEC_SUCCESS;
+            vrc = EXITCODEEXEC_SUCCESS;
             break;
         case ProcessStatus_Terminating:
-            rc = EXITCODEEXEC_SUCCESS;
+            vrc = EXITCODEEXEC_SUCCESS;
             break;
         case ProcessStatus_TerminatedNormally:
-            rc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
+            vrc = !uExitCode ? EXITCODEEXEC_SUCCESS : EXITCODEEXEC_CODE;
             break;
         case ProcessStatus_TerminatedSignal:
-            rc = EXITCODEEXEC_TERM_SIGNAL;
+            vrc = EXITCODEEXEC_TERM_SIGNAL;
             break;
         case ProcessStatus_TerminatedAbnormally:
-            rc = EXITCODEEXEC_TERM_ABEND;
+            vrc = EXITCODEEXEC_TERM_ABEND;
             break;
         case ProcessStatus_TimedOutKilled:
-            rc = EXITCODEEXEC_TIMEOUT;
+            vrc = EXITCODEEXEC_TIMEOUT;
             break;
         case ProcessStatus_TimedOutAbnormally:
-            rc = EXITCODEEXEC_TIMEOUT;
+            vrc = EXITCODEEXEC_TIMEOUT;
             break;
         case ProcessStatus_Down:
             /* Service/OS is stopping, process was killed, so
              * not exactly an error of the started process ... */
-            rc = EXITCODEEXEC_DOWN;
+            vrc = EXITCODEEXEC_DOWN;
             break;
         case ProcessStatus_Error:
-            rc = EXITCODEEXEC_FAILED;
+            vrc = EXITCODEEXEC_FAILED;
             break;
         default:
@@ -450,5 +460,5 @@
             break;
     }
-    return rc;
+    return vrc;
 }
 #endif
@@ -718,7 +728,4 @@
      * Parse arguments.
      */
-    if (pArg->argc < 2) /* At least the command we want to execute in the guest should be present :-). */
-        return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters");
-
     static const RTGETOPTDEF s_aOptions[] =
     {
@@ -755,5 +762,5 @@
     com::SafeArray<IN_BSTR> args;
     com::SafeArray<IN_BSTR> env;
-    Utf8Str                 strUserName;
+    Utf8Str                 strUsername;
     Utf8Str                 strPassword;
     Utf8Str                 strDomain;
@@ -814,5 +821,5 @@
 
             case 'u': /* User name */
-                strUserName = ValueUnion.psz;
+                strUsername = ValueUnion.psz;
                 break;
 
@@ -892,5 +899,5 @@
         return errorSyntax(USAGE_GUESTCONTROL, "No command to execute specified!");
 
-    if (strUserName.isEmpty())
+    if (strUsername.isEmpty())
         return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
 
@@ -924,5 +931,5 @@
                                ComSafeArrayAsInParam(args),
                                ComSafeArrayAsInParam(env),
-                               Bstr(strUserName).raw(),
+                               Bstr(strUsername).raw(),
                                Bstr(strPassword).raw(),
                                cMsTimeout,
@@ -1067,5 +1074,5 @@
 #else
     ComPtr<IGuestSession> pGuestSession;
-    rc = pGuest->CreateSession(Bstr(strUserName).raw(),
+    rc = pGuest->CreateSession(Bstr(strUsername).raw(),
                                Bstr(strPassword).raw(),
                                Bstr(strDomain).raw(),
@@ -1210,39 +1217,43 @@
  * @param   fHostToGuest            Flag indicating if we want to copy from host to guest
  *                                  or vice versa.
- * @param   pszUsername             Username of account to use on the guest side.
- * @param   pszPassword             Password of account to use.
+ * @param   strUsername             Username of account to use on the guest side.
+ * @param   strPassword             Password of account to use.
+ * @param   strDomain               Domain of account to use.
+ * @param   strSessionName          Session name (only for identification purposes).
  * @param   ppContext               Pointer which receives the allocated copy context.
  */
 static int ctrlCopyContextCreate(IGuest *pGuest, bool fVerbose, bool fDryRun,
-                                 bool fHostToGuest,
-                                 const char *pszUsername, const char *pszPassword,
+                                 bool fHostToGuest, const Utf8Str &strUsername,
+                                 const Utf8Str &strPassword, const Utf8Str &strDomain,
+                                 const Utf8Str &strSessionName,
                                  PCOPYCONTEXT *ppContext)
 {
     AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
-    AssertPtrReturn(pszUsername, VERR_INVALID_POINTER);
-    AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
-
-    PCOPYCONTEXT pContext = (PCOPYCONTEXT)RTMemAlloc(sizeof(COPYCONTEXT));
-    AssertPtrReturn(pContext, VERR_NO_MEMORY);
+
+    PCOPYCONTEXT pContext = new COPYCONTEXT();
+    AssertPtrReturn(pContext, VERR_NO_MEMORY); /**< @todo r=klaus cannot happen with new */
+#ifndef VBOX_WITH_GUEST_CONTROL2
+    NOREF(strDomain);
+    NOREF(strSessionName);
     pContext->pGuest = pGuest;
+
+    pContext->strUsername = strUsername;
+    pContext->strPassword = strPassword;
+#else
+    ComPtr<IGuestSession> pGuestSession;
+    HRESULT rc = pGuest->CreateSession(Bstr(strUsername).raw(),
+                                       Bstr(strPassword).raw(),
+                                       Bstr(strDomain).raw(),
+                                       Bstr(strSessionName).raw(),
+                                       pGuestSession.asOutParam());
+    if (FAILED(rc))
+        return ctrlPrintError(pGuest, COM_IIDOF(IGuest));
+
+#endif
+
     pContext->fVerbose = fVerbose;
     pContext->fDryRun = fDryRun;
     pContext->fHostToGuest = fHostToGuest;
 
-    pContext->pszUsername = RTStrDup(pszUsername);
-    if (!pContext->pszUsername)
-    {
-        RTMemFree(pContext);
-        return VERR_NO_MEMORY;
-    }
-
-    pContext->pszPassword = RTStrDup(pszPassword);
-    if (!pContext->pszPassword)
-    {
-        RTStrFree(pContext->pszUsername);
-        RTMemFree(pContext);
-        return VERR_NO_MEMORY;
-    }
-
     *ppContext = pContext;
 
@@ -1259,12 +1270,15 @@
     if (pContext)
     {
-        RTStrFree(pContext->pszUsername);
-        RTStrFree(pContext->pszPassword);
-        RTMemFree(pContext);
-    }
-}
-
-/**
- * Translates a source path to a destintation path (can be both sides,
+#ifndef VBOX_WITH_GUEST_CONTROL2
+#else
+        if (pContext->pGuestSession)
+            pContext->pGuestSession->Close();
+#endif
+        delete pContext;
+    }
+}
+
+/**
+ * Translates a source path to a destination path (can be both sides,
  * either host or guest). The source root is needed to determine the start
  * of the relative source path which also needs to present in the destination
@@ -1302,9 +1316,9 @@
     AssertPtrReturn(pszDestPath, VERR_NO_MEMORY);
 
-    int rc;
+    int vrc;
     if (!RTPathFilename(pszDestPath))
     {
-        rc = RTPathJoin(szTranslated, sizeof(szTranslated),
-                        pszDestPath, &pszSource[srcOff]);
+        vrc = RTPathJoin(szTranslated, sizeof(szTranslated),
+                         pszDestPath, &pszSource[srcOff]);
     }
     else
@@ -1314,14 +1328,14 @@
         {
             RTPathStripFilename(pszDestPath);
-            rc = RTPathJoin(szTranslated, sizeof(szTranslated),
+            vrc = RTPathJoin(szTranslated, sizeof(szTranslated),
                             pszDestPath, pszDestFileName);
             RTStrFree(pszDestFileName);
         }
         else
-            rc = VERR_NO_MEMORY;
+            vrc = VERR_NO_MEMORY;
     }
     RTStrFree(pszDestPath);
 
-    if (RT_SUCCESS(rc))
+    if (RT_SUCCESS(vrc))
     {
         *ppszTranslated = RTStrDup(szTranslated);
@@ -1331,5 +1345,5 @@
 #endif
     }
-    return rc;
+    return vrc;
 }
 
@@ -1432,9 +1446,21 @@
     if (pContext->fHostToGuest) /* We want to create directories on the guest. */
     {
+#ifndef VBOX_WITH_GUEST_CONTROL2
         HRESULT rc = pContext->pGuest->DirectoryCreate(Bstr(pszDir).raw(),
-                                                       Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
+                                                       Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
                                                        0700, DirectoryCreateFlag_Parents);
         if (FAILED(rc))
             vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+#else
+        ComPtr<IGuestDirectory> pDirectory;
+        SafeArray<DirectoryCreateFlag_T> dirCreateFlags;
+        dirCreateFlags.push_back(DirectoryCreateFlag_Parents);
+        HRESULT rc = pContext->pGuestSession->DirectoryCreate(Bstr(pszDir).raw(),
+                                                              0700, ComSafeArrayAsInParam(dirCreateFlags), pDirectory.asOutParam());
+        if (FAILED(rc))
+            vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
+        if (!pDirectory.isNull())
+            pDirectory->Close();
+#endif
     }
     else /* ... or on the host. */
@@ -1465,20 +1491,28 @@
     AssertPtrReturn(fExists, false);
 
-    int rc = VINF_SUCCESS;
+    int vrc = VINF_SUCCESS;
     if (bGuest)
     {
         BOOL fDirExists = FALSE;
+#ifndef VBOX_WITH_GUEST_CONTROL2
         /** @todo Replace with DirectoryExists as soon as API is in place. */
-        HRESULT hr = pContext->pGuest->FileExists(Bstr(pszDir).raw(),
-                                                  Bstr(pContext->pszUsername).raw(),
-                                                  Bstr(pContext->pszPassword).raw(), &fDirExists);
-        if (FAILED(hr))
-            rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+        HRESULT rc = pContext->pGuest->FileExists(Bstr(pszDir).raw(),
+                                                  Bstr(pContext->strUsername).raw(),
+                                                  Bstr(pContext->strPassword).raw(), &fDirExists);
+        if (FAILED(rc))
+            vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
         else
             *fExists = fDirExists ? true : false;
+#else
+        HRESULT rc = pContext->pGuestSession->DirectoryExists(Bstr(pszDir).raw(), &fDirExists);
+        if (FAILED(rc))
+            vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
+        else
+            *fExists = fDirExists ? true : false;
+#endif
     }
     else
         *fExists = RTDirExists(pszDir);
-    return rc;
+    return vrc;
 }
 
@@ -1535,19 +1569,27 @@
     AssertPtrReturn(fExists, false);
 
-    int rc = VINF_SUCCESS;
+    int vrc = VINF_SUCCESS;
     if (bOnGuest)
     {
         BOOL fFileExists = FALSE;
-        HRESULT hr = pContext->pGuest->FileExists(Bstr(pszFile).raw(),
-                                                  Bstr(pContext->pszUsername).raw(),
-                                                  Bstr(pContext->pszPassword).raw(), &fFileExists);
-        if (FAILED(hr))
-            rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+#ifndef VBOX_WITH_GUEST_CONTROL2
+        HRESULT rc = pContext->pGuest->FileExists(Bstr(pszFile).raw(),
+                                                  Bstr(pContext->strUsername).raw(),
+                                                  Bstr(pContext->strPassword).raw(), &fFileExists);
+        if (FAILED(rc))
+            vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
         else
             *fExists = fFileExists ? true : false;
+#else
+        HRESULT rc = pContext->pGuestSession->FileExists(Bstr(pszFile).raw(), &fFileExists);
+        if (FAILED(rc))
+            vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
+        else
+            *fExists = fFileExists ? true : false;
+#endif
     }
     else
         *fExists = RTFileExists(pszFile);
-    return rc;
+    return vrc;
 }
 
@@ -1616,17 +1658,40 @@
     if (pContext->fHostToGuest)
     {
+#ifndef VBOX_WITH_GUEST_CONTROL2
         rc = pContext->pGuest->CopyToGuest(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
-                                           Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
+                                           Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
                                            fFlags, pProgress.asOutParam());
+#else
+        Assert(!fFlags);
+        SafeArray<CopyFileFlag_T> copyFlags;
+        rc = pContext->pGuestSession->CopyTo(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
+                                             ComSafeArrayAsInParam(copyFlags),
+
+                                             pProgress.asOutParam());
+#endif
     }
     else
     {
+#ifndef VBOX_WITH_GUEST_CONTROL2
         rc = pContext->pGuest->CopyFromGuest(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
-                                             Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
+                                             Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
                                              fFlags, pProgress.asOutParam());
+#else
+        Assert(!fFlags);
+        SafeArray<CopyFileFlag_T> copyFlags;
+        rc = pContext->pGuestSession->CopyFrom(Bstr(pszFileSource).raw(), Bstr(pszFileDest).raw(),
+                                               ComSafeArrayAsInParam(copyFlags),
+                                               pProgress.asOutParam());
+#endif
     }
 
     if (FAILED(rc))
+    {
+#ifndef VBOX_WITH_GUEST_CONTROL2
         vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+#else
+        vrc = ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
+#endif
+    }
     else
     {
@@ -1670,7 +1735,7 @@
      */
     char szCurDir[RTPATH_MAX];
-    int rc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
-    if (RT_SUCCESS(rc) && pszSubDir)
-        rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
+    int vrc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
+    if (RT_SUCCESS(vrc) && pszSubDir)
+        vrc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
 
     if (pContext->fVerbose)
@@ -1686,23 +1751,23 @@
      */
     PRTDIR pDir = NULL;
-    if (RT_SUCCESS(rc))
-    {
-        rc = RTDirOpen(&pDir, szCurDir);
-        if (RT_FAILURE(rc))
+    if (RT_SUCCESS(vrc))
+    {
+        vrc = RTDirOpen(&pDir, szCurDir);
+        if (RT_FAILURE(vrc))
             pDir = NULL;
     }
-    if (RT_SUCCESS(rc))
+    if (RT_SUCCESS(vrc))
     {
         /*
          * Enumerate the directory tree.
          */
-        while (RT_SUCCESS(rc))
+        while (RT_SUCCESS(vrc))
         {
             RTDIRENTRY DirEntry;
-            rc = RTDirRead(pDir, &DirEntry, NULL);
-            if (RT_FAILURE(rc))
-            {
-                if (rc == VERR_NO_MORE_FILES)
-                    rc = VINF_SUCCESS;
+            vrc = RTDirRead(pDir, &DirEntry, NULL);
+            if (RT_FAILURE(vrc))
+            {
+                if (vrc == VERR_NO_MORE_FILES)
+                    vrc = VINF_SUCCESS;
                 break;
             }
@@ -1732,11 +1797,11 @@
                         if (pszNewSub)
                         {
-                            rc = ctrlCopyDirToGuest(pContext,
-                                                    pszSource, pszFilter,
-                                                    pszDest, fFlags, pszNewSub);
+                            vrc = ctrlCopyDirToGuest(pContext,
+                                                     pszSource, pszFilter,
+                                                     pszDest, fFlags, pszNewSub);
                             RTStrFree(pszNewSub);
                         }
                         else
-                            rc = VERR_NO_MEMORY;
+                            vrc = VERR_NO_MEMORY;
                     }
                     break;
@@ -1766,9 +1831,9 @@
                     {
                         char *pszDestDir;
-                        rc = ctrlCopyTranslatePath(pszSource, szCurDir,
-                                                   pszDest, &pszDestDir);
-                        if (RT_SUCCESS(rc))
+                        vrc = ctrlCopyTranslatePath(pszSource, szCurDir,
+                                                    pszDest, &pszDestDir);
+                        if (RT_SUCCESS(vrc))
                         {
-                            rc = ctrlCopyDirCreate(pContext, pszDestDir);
+                            vrc = ctrlCopyDirCreate(pContext, pszDestDir);
                             RTStrFree(pszDestDir);
 
@@ -1777,5 +1842,5 @@
                     }
 
-                    if (RT_SUCCESS(rc))
+                    if (RT_SUCCESS(vrc))
                     {
                         char *pszFileSource = RTPathJoinA(szCurDir, DirEntry.szName);
@@ -1783,9 +1848,9 @@
                         {
                             char *pszFileDest;
-                            rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
+                            vrc = ctrlCopyTranslatePath(pszSource, pszFileSource,
                                                        pszDest, &pszFileDest);
-                            if (RT_SUCCESS(rc))
+                            if (RT_SUCCESS(vrc))
                             {
-                                rc = ctrlCopyFileToDest(pContext, pszFileSource,
+                                vrc = ctrlCopyFileToDest(pContext, pszFileSource,
                                                         pszFileDest, 0 /* Flags */);
                                 RTStrFree(pszFileDest);
@@ -1800,5 +1865,5 @@
                     break;
             }
-            if (RT_FAILURE(rc))
+            if (RT_FAILURE(vrc))
                 break;
         }
@@ -1806,5 +1871,5 @@
         RTDirClose(pDir);
     }
-    return rc;
+    return vrc;
 }
 
@@ -1836,10 +1901,10 @@
      */
     char szCurDir[RTPATH_MAX];
-    int rc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
-    if (RT_SUCCESS(rc) && pszSubDir)
-        rc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
-
-    if (RT_FAILURE(rc))
-        return rc;
+    int vrc = RTStrCopy(szCurDir, sizeof(szCurDir), pszSource);
+    if (RT_SUCCESS(vrc) && pszSubDir)
+        vrc = RTPathAppend(szCurDir, sizeof(szCurDir), pszSubDir);
+
+    if (RT_FAILURE(vrc))
+        return vrc;
 
     if (pContext->fVerbose)
@@ -1850,165 +1915,208 @@
     bool fDirCreated = false;
 
+#ifndef VBOX_WITH_GUEST_CONTROL2
     ULONG uDirHandle;
-    HRESULT hr = pContext->pGuest->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),
+    HRESULT rc = pContext->pGuest->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),
                                                  DirectoryOpenFlag_None /* No flags supported yet. */,
-                                                 Bstr(pContext->pszUsername).raw(), Bstr(pContext->pszPassword).raw(),
+                                                 Bstr(pContext->strUsername).raw(), Bstr(pContext->strPassword).raw(),
                                                  &uDirHandle);
-    if (FAILED(hr))
-        rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
-    else
-    {
-        ComPtr <IGuestDirEntry> dirEntry;
-        while (SUCCEEDED(hr = pContext->pGuest->DirectoryRead(uDirHandle, dirEntry.asOutParam())))
-        {
-            GuestDirEntryType_T enmType;
-            dirEntry->COMGETTER(Type)(&enmType);
-
-            Bstr strName;
-            dirEntry->COMGETTER(Name)(strName.asOutParam());
-
-            switch (enmType)
-            {
-                case GuestDirEntryType_Directory:
+    if (FAILED(rc))
+        return ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+    ComPtr<IGuestDirEntry> dirEntry;
+#else
+    ComPtr<IGuestDirectory> pDirectory;
+    HRESULT rc = pContext->pGuestSession->DirectoryOpen(Bstr(szCurDir).raw(), Bstr(pszFilter).raw(),
+                                                 Bstr().raw() /* No flags supported yet. */,
+                                                 pDirectory.asOutParam());
+    if (FAILED(rc))
+        return ctrlPrintError(pContext->pGuestSession, COM_IIDOF(IGuestSession));
+    ComPtr<IFsObjInfo> dirEntry;
+#endif
+    while (true)
+    {
+#ifndef VBOX_WITH_GUEST_CONTROL2
+        rc = pContext->pGuest->DirectoryRead(uDirHandle, dirEntry.asOutParam());
+#else
+        rc = pDirectory->Read(dirEntry.asOutParam());
+#endif
+        if (FAILED(rc))
+            break;
+
+#ifndef VBOX_WITH_GUEST_CONTROL2
+        GuestDirEntryType_T enmType;
+#else
+        FsObjType_T enmType;
+#endif
+        dirEntry->COMGETTER(Type)(&enmType);
+
+        Bstr strName;
+        dirEntry->COMGETTER(Name)(strName.asOutParam());
+
+        switch (enmType)
+        {
+#ifndef VBOX_WITH_GUEST_CONTROL2
+            case GuestDirEntryType_Directory:
+#else
+            case FsObjType_Directory:
+#endif
+            {
+                Assert(!strName.isEmpty());
+
+                /* Skip "." and ".." entries. */
+                if (   !strName.compare(Bstr("."))
+                    || !strName.compare(Bstr("..")))
+                    break;
+
+                if (pContext->fVerbose)
                 {
-                    Assert(!strName.isEmpty());
-
-                    /* Skip "." and ".." entries. */
-                    if (   !strName.compare(Bstr("."))
-                        || !strName.compare(Bstr("..")))
-                        break;
-
-                    if (pContext->fVerbose)
+                    Utf8Str strDir(strName);
+                    RTPrintf("Directory: %s\n", strDir.c_str());
+                }
+
+                if (fFlags & CopyFileFlag_Recursive)
+                {
+                    Utf8Str strDir(strName);
+                    char *pszNewSub = NULL;
+                    if (pszSubDir)
+                        pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str());
+                    else
                     {
-                        Utf8Str strDir(strName);
-                        RTPrintf("Directory: %s\n", strDir.c_str());
+                        pszNewSub = RTStrDup(strDir.c_str());
+                        RTPathStripTrailingSlash(pszNewSub);
                     }
-
-                    if (fFlags & CopyFileFlag_Recursive)
+                    if (pszNewSub)
                     {
-                        Utf8Str strDir(strName);
-                        char *pszNewSub = NULL;
-                        if (pszSubDir)
-                            pszNewSub = RTPathJoinA(pszSubDir, strDir.c_str());
-                        else
-                        {
-                            pszNewSub = RTStrDup(strDir.c_str());
-                            RTPathStripTrailingSlash(pszNewSub);
-                        }
-                        if (pszNewSub)
-                        {
-                            rc = ctrlCopyDirToHost(pContext,
-                                                   pszSource, pszFilter,
-                                                   pszDest, fFlags, pszNewSub);
-                            RTStrFree(pszNewSub);
-                        }
-                        else
-                            rc = VERR_NO_MEMORY;
-                    }
-                    break;
-                }
-
-                case GuestDirEntryType_Symlink:
-                    if (   (fFlags & CopyFileFlag_Recursive)
-                        && (fFlags & CopyFileFlag_FollowLinks))
-                    {
-                        /* Fall through to next case is intentional. */
+                        vrc = ctrlCopyDirToHost(pContext,
+                                                pszSource, pszFilter,
+                                                pszDest, fFlags, pszNewSub);
+                        RTStrFree(pszNewSub);
                     }
                     else
-                        break;
-
-                case GuestDirEntryType_File:
+                        vrc = VERR_NO_MEMORY;
+                }
+                break;
+            }
+
+#ifndef VBOX_WITH_GUEST_CONTROL2
+            case GuestDirEntryType_Symlink:
+#else
+            case FsObjType_Symlink:
+#endif
+                if (   (fFlags & CopyFileFlag_Recursive)
+                    && (fFlags & CopyFileFlag_FollowLinks))
                 {
-                    Assert(!strName.isEmpty());
-
-                    Utf8Str strFile(strName);
-                    if (   pszFilter
-                        && !RTStrSimplePatternMatch(pszFilter, strFile.c_str()))
+                    /* Fall through to next case is intentional. */
+                }
+                else
+                    break;
+
+#ifndef VBOX_WITH_GUEST_CONTROL2
+            case GuestDirEntryType_File:
+#else
+            case FsObjType_File:
+#endif
+            {
+                Assert(!strName.isEmpty());
+
+                Utf8Str strFile(strName);
+                if (   pszFilter
+                    && !RTStrSimplePatternMatch(pszFilter, strFile.c_str()))
+                {
+                    break; /* Filter does not match. */
+                }
+
+                if (pContext->fVerbose)
+                    RTPrintf("File: %s\n", strFile.c_str());
+
+                if (!fDirCreated)
+                {
+                    char *pszDestDir;
+                    vrc = ctrlCopyTranslatePath(pszSource, szCurDir,
+                                                pszDest, &pszDestDir);
+                    if (RT_SUCCESS(vrc))
                     {
-                        break; /* Filter does not match. */
+                        vrc = ctrlCopyDirCreate(pContext, pszDestDir);
+                        RTStrFree(pszDestDir);
+
+                        fDirCreated = true;
                     }
-
-                    if (pContext->fVerbose)
-                        RTPrintf("File: %s\n", strFile.c_str());
-
-                    if (!fDirCreated)
+                }
+
+                if (RT_SUCCESS(vrc))
+                {
+                    char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
+                    if (pszFileSource)
                     {
-                        char *pszDestDir;
-                        rc = ctrlCopyTranslatePath(pszSource, szCurDir,
-                                                   pszDest, &pszDestDir);
-                        if (RT_SUCCESS(rc))
+                        char *pszFileDest;
+                        vrc = ctrlCopyTranslatePath(pszSource, pszFileSource,
+                                                   pszDest, &pszFileDest);
+                        if (RT_SUCCESS(vrc))
                         {
-                            rc = ctrlCopyDirCreate(pContext, pszDestDir);
-                            RTStrFree(pszDestDir);
-
-                            fDirCreated = true;
+                            vrc = ctrlCopyFileToDest(pContext, pszFileSource,
+                                                    pszFileDest, 0 /* Flags */);
+                            RTStrFree(pszFileDest);
                         }
+                        RTStrFree(pszFileSource);
                     }
-
-                    if (RT_SUCCESS(rc))
-                    {
-                        char *pszFileSource = RTPathJoinA(szCurDir, strFile.c_str());
-                        if (pszFileSource)
-                        {
-                            char *pszFileDest;
-                            rc = ctrlCopyTranslatePath(pszSource, pszFileSource,
-                                                       pszDest, &pszFileDest);
-                            if (RT_SUCCESS(rc))
-                            {
-                                rc = ctrlCopyFileToDest(pContext, pszFileSource,
-                                                        pszFileDest, 0 /* Flags */);
-                                RTStrFree(pszFileDest);
-                            }
-                            RTStrFree(pszFileSource);
-                        }
-                        else
-                            rc = VERR_NO_MEMORY;
-                    }
-                    break;
+                    else
+                        vrc = VERR_NO_MEMORY;
                 }
-
-                default:
-                    RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n",
-                             enmType);
-                    break;
-            }
-
-            if (RT_FAILURE(rc))
-                break;
-        }
-
-        if (RT_UNLIKELY(FAILED(hr)))
-        {
-            switch (hr)
-            {
-                case E_ABORT: /* No more directory entries left to process. */
-                    break;
-
-                case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to
-                                           to missing rights. */
-                {
-                    RTPrintf("Warning: Cannot access \"%s\", skipping ...\n",
-                             szCurDir);
-                    break;
-                }
-
-                default:
-                    rc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
-                    break;
-            }
-        }
-
-        HRESULT hr2 = pContext->pGuest->DirectoryClose(uDirHandle);
-        if (FAILED(hr2))
-        {
-            int rc2 = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
-            if (RT_SUCCESS(rc))
-                rc = rc2;
-        }
-        else if (SUCCEEDED(hr))
-            hr = hr2;
-    }
-
-    return rc;
+                break;
+            }
+
+            default:
+                RTPrintf("Warning: Directory entry of type %ld not handled, skipping ...\n",
+                         enmType);
+                break;
+        }
+
+        if (RT_FAILURE(vrc))
+            break;
+    }
+
+    if (RT_UNLIKELY(FAILED(rc)))
+    {
+        switch (rc)
+        {
+            case E_ABORT: /* No more directory entries left to process. */
+                break;
+
+            case VBOX_E_FILE_ERROR: /* Current entry cannot be accessed to
+                                       to missing rights. */
+            {
+                RTPrintf("Warning: Cannot access \"%s\", skipping ...\n",
+                         szCurDir);
+                break;
+            }
+
+            default:
+#ifndef VBOX_WITH_GUEST_CONTROL2
+                vrc = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+#else
+                vrc = ctrlPrintError(pDirectory, COM_IIDOF(IGuestDirectory));
+#endif
+                break;
+        }
+    }
+
+#ifndef VBOX_WITH_GUEST_CONTROL2
+    HRESULT rc2 = pContext->pGuest->DirectoryClose(uDirHandle);
+#else
+    HRESULT rc2 = pDirectory->Close();
+#endif
+    if (FAILED(rc2))
+    {
+#ifndef VBOX_WITH_GUEST_CONTROL2
+        int vrc2 = ctrlPrintError(pContext->pGuest, COM_IIDOF(IGuest));
+#else
+        int vrc2 = ctrlPrintError(pDirectory, COM_IIDOF(IGuestDirectory));
+#endif
+        if (RT_SUCCESS(vrc))
+            vrc = vrc2;
+    }
+    else if (SUCCEEDED(rc))
+        rc = rc2;
+
+    return vrc;
 }
 
@@ -2127,5 +2235,5 @@
     Utf8Str strSource;
     Utf8Str strDest;
-    Utf8Str strUserName;
+    Utf8Str strUsername;
     Utf8Str strPassword;
     Utf8Str strDomain;
@@ -2152,5 +2260,5 @@
 
             case 'u': /* User name */
-                strUserName = ValueUnion.psz;
+                strUsername = ValueUnion.psz;
                 break;
 
@@ -2214,5 +2322,5 @@
                            "No destination specified!");
 
-    if (strUserName.isEmpty())
+    if (strUsername.isEmpty())
         return errorSyntax(USAGE_GUESTCONTROL,
                            "No user name specified!");
@@ -2235,6 +2343,6 @@
     PCOPYCONTEXT pContext;
     vrc = ctrlCopyContextCreate(guest, fVerbose, fDryRun, fHostToGuest,
-                                strUserName.c_str(), strPassword.c_str(),
-                                &pContext);
+                                strUsername.c_str(), strPassword.c_str(),
+                                strDomain.c_str(), "guest copy", &pContext);
     if (RT_FAILURE(vrc))
     {
@@ -2397,5 +2505,5 @@
                  s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST);
 
-    Utf8Str strUserName;
+    Utf8Str strUsername;
     Utf8Str strPassword;
     Utf8Str strDomain;
@@ -2420,5 +2528,5 @@
 
             case 'u': /* User name */
-                strUserName = ValueUnion.psz;
+                strUsername = ValueUnion.psz;
                 break;
 
@@ -2458,5 +2566,5 @@
         return errorSyntax(USAGE_GUESTCONTROL, "No directory to create specified!");
 
-    if (strUserName.isEmpty())
+    if (strUsername.isEmpty())
         return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
 
@@ -2475,5 +2583,5 @@
 
         hrc = guest->DirectoryCreate(Bstr(it->first).raw(),
-                                     Bstr(strUserName).raw(), Bstr(strPassword).raw(),
+                                     Bstr(strUsername).raw(), Bstr(strPassword).raw(),
                                      fDirMode, fFlags);
         if (FAILED(hrc))
@@ -2512,5 +2620,5 @@
                  s_aOptions, RT_ELEMENTS(s_aOptions), 0, RTGETOPTINIT_FLAGS_OPTS_FIRST);
 
-    Utf8Str strUserName;
+    Utf8Str strUsername;
     Utf8Str strPassword;
     Utf8Str strDomain;
@@ -2525,5 +2633,5 @@
         {
             case 'u': /* User name */
-                strUserName = ValueUnion.psz;
+                strUsername = ValueUnion.psz;
                 break;
 
@@ -2571,5 +2679,5 @@
         return errorSyntax(USAGE_GUESTCONTROL, "No element(s) to check specified!");
 
-    if (strUserName.isEmpty())
+    if (strUsername.isEmpty())
         return errorSyntax(USAGE_GUESTCONTROL, "No user name specified!");
 
@@ -2587,5 +2695,5 @@
         BOOL fExists;
         hrc = guest->FileExists(Bstr(it->first).raw(),
-                                Bstr(strUserName).raw(), Bstr(strPassword).raw(),
+                                Bstr(strUsername).raw(), Bstr(strPassword).raw(),
                                 &fExists);
         if (FAILED(hrc))
