Index: /trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h
===================================================================
--- /trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h	(revision 55591)
+++ /trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h	(revision 55592)
@@ -241,4 +241,51 @@
         return RTEnvFreeUtf8Block(pszzBlock);
     }
+
+    /**
+     * Applies a block on the format returned by queryUtf8Block.
+     *
+     * @returns IPRT status code.
+     * @param   pszzBlock           Pointer to the block.
+     * @param   cbBlock             The size of the block.
+     * @param   fNoEqualMeansUnset  Whether the lack of a '=' (equal) sign in a
+     *                              string means it should be unset (@c true), or if
+     *                              it means the variable should be defined with an
+     *                              empty value (@c false, the default).
+     * @todo move this to RTEnv!
+     */
+    int copyUtf8Block(const char *pszzBlock, size_t cbBlock, bool fNoEqualMeansUnset = false)
+    {
+        int rc = VINF_SUCCESS;
+        while (cbBlock > 0 && *pszzBlock != '\0')
+        {
+            const char *pszEnd = (const char *)memchr(pszzBlock, '\0', cbBlock);
+            if (!pszEnd)
+                return VERR_BUFFER_UNDERFLOW;
+            int rc2;
+            if (fNoEqualMeansUnset || strchr(pszzBlock, '='))
+                rc2 = RTEnvPutEx(m_hEnv, pszzBlock);
+            else
+                rc2 = RTEnvSetEx(m_hEnv, pszzBlock, "");
+            if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
+                rc = rc2;
+
+            /* Advance. */
+            cbBlock -= pszEnd - pszzBlock;
+            if (cbBlock < 2)
+                return VERR_BUFFER_UNDERFLOW;
+            cbBlock--;
+            pszzBlock = pszEnd + 1;
+        }
+
+        /* The remainder must be zero padded. */
+        if (RT_SUCCESS(rc))
+        {
+            if (ASMMemIsAll8(pszzBlock, cbBlock, 0))
+                return VINF_SUCCESS;
+            return VERR_TOO_MUCH_DATA;
+        }
+        return rc;
+    }
+
 
     /**
Index: /trunk/src/VBox/Main/include/GuestSessionImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/GuestSessionImpl.h	(revision 55591)
+++ /trunk/src/VBox/Main/include/GuestSessionImpl.h	(revision 55592)
@@ -515,4 +515,12 @@
             , mRC(rThat.mRC)
         { }
+        ~Data(void)
+        {
+            if (mpBaseEnvironment)
+            {
+                mpBaseEnvironment->releaseConst();
+                mpBaseEnvironment = NULL;
+            }
+        }
     } mData;
 };
Index: /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 55591)
+++ /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 55592)
@@ -325,7 +325,6 @@
     if (mData.mpBaseEnvironment)
     {
-        GuestEnvironment *pBaseEnv = unconst(mData.mpBaseEnvironment);
+        mData.mpBaseEnvironment->releaseConst();
         mData.mpBaseEnvironment = NULL;
-        pBaseEnv->release();
     }
 
@@ -1571,4 +1570,23 @@
         case GUEST_SESSION_NOTIFYTYPE_STARTED:
             sessionStatus = GuestSessionStatus_Started;
+#if 0 /** @todo If we get some environment stuff along with this kind notification: */
+            const char *pszzEnvBlock = ...;
+            uint32_t    cbEnvBlock   = ...;
+            if (!mData.mpBaseEnvironment)
+            {
+                GuestEnvironment *pBaseEnv;
+                try { pBaseEnv = new GuestEnvironment(); } catch (std::bad_alloc &) { pBaseEnv = NULL; }
+                if (pBaseEnv)
+                {
+                    int vrc = pBaseEnv->initNormal();
+                    if (RT_SUCCESS(vrc))
+                        vrc = pBaseEnv->copyUtf8Block(pszzEnvBlock, cbEnvBlock);
+                    if (RT_SUCCESS(vrc))
+                        mData.mpBaseEnvironment = pBaseEnv;
+                    else
+                        pBaseEnv->release();
+                }
+            }
+#endif
             break;
 
