Index: /trunk/doc/manual/en_US/SDKRef.xml
===================================================================
--- /trunk/doc/manual/en_US/SDKRef.xml	(revision 42381)
+++ /trunk/doc/manual/en_US/SDKRef.xml	(revision 42382)
@@ -3530,4 +3530,16 @@
       <itemizedlist>
         <listitem>
+          <para>The <xref linkend="LockType" xreflabel="LockType" />
+          enumeration now has an additional value <computeroutput>VM</computeroutput>
+          which tells <xref linkend="IMachine__lockMachine"
+          xreflabel="IMachine::lockMachine()" /> to create a full-blown
+          object structure for running a VM. This was the previous behavior
+          with <computeroutput>Write</computeroutput>, which now only creates
+          the minimal object structure to save time and resources (at the
+          moment the Console object is still created, but all sub-objects
+          such as Display, Keyboard, Mouse, Guest are not.</para>
+        </listitem>
+
+        <listitem>
           <para>Machines can be put in groups (actually an array of groups).
           The primary group affects the default placement of files belonging
Index: /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 42381)
+++ /trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 42382)
@@ -43,5 +43,5 @@
 #include <VBox/VBoxVideo.h>
 
-#ifdef VBOX_WITH_VIDEO_REC 
+#ifdef VBOX_WITH_VIDEO_REC
 #include <cstdlib>
 #include <cerrno>
@@ -827,5 +827,5 @@
 
         // open a session
-        CHECK_ERROR_BREAK(m, LockMachine(session, LockType_Write));
+        CHECK_ERROR_BREAK(m, LockMachine(session, LockType_VM));
         fSessionOpened = true;
 
Index: /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 42381)
+++ /trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp	(revision 42382)
@@ -1415,5 +1415,5 @@
     AssertReleaseRC(vrc);
 
-    rc = pMachine->LockMachine(pSession, LockType_Write);
+    rc = pMachine->LockMachine(pSession, LockType_VM);
     if (FAILED(rc))
     {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp	(revision 42381)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotDetailsDlg.cpp	(revision 42382)
@@ -112,5 +112,5 @@
 
     /* We need a session when we manipulate the snapshot data of a machine. */
-    CSession session = vboxGlobal().openSession(mSnapshot.GetMachine().GetId(), true);
+    CSession session = vboxGlobal().openExistingSession(mSnapshot.GetMachine().GetId());
     if (session.isNull())
         return;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 42381)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 42382)
@@ -469,6 +469,6 @@
     AssertMsg(!m_pVirtualMachine, ("Machine already started"));
 
-    /* Create session: */
-    CSession session = vboxGlobal().openSession(strMachineId);
+    /* Create VM session: */
+    CSession session = vboxGlobal().openSession(strMachineId, KLockType_VM);
     if (session.isNull())
         return false;
@@ -1813,9 +1813,10 @@
  *
  *  @param aId          Machine ID.
- *  @param aExisting    @c true to open an existing session with the machine
- *                      which is already running, @c false to open a new direct
- *                      session.
- */
-CSession VBoxGlobal::openSession(const QString &aId, bool aExisting /* = false */)
+ *  @param aLockType    @c KLockType_Shared to open an existing session with
+ *                      the machine which is already running, @c KLockType_Write
+ *                      to open a new direct session, @c KLockType_VM to open
+ *                      a new session for running a VM in this process.
+ */
+CSession VBoxGlobal::openSession(const QString &aId, KLockType aLockType /* = KLockType_Shared */)
 {
     CSession session;
@@ -1830,6 +1831,5 @@
     if (!foundMachine.isNull())
     {
-        foundMachine.LockMachine(session,
-                                 (aExisting) ? KLockType_Shared : KLockType_Write);
+        foundMachine.LockMachine(session, aLockType);
         if (session.GetType() == KSessionType_Shared)
         {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 42381)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 42382)
@@ -239,8 +239,8 @@
 #endif
 
-    CSession openSession(const QString &aId, bool aExisting = false);
+    CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
 
     /** Shortcut to openSession (aId, true). */
-    CSession openExistingSession(const QString &aId) { return openSession (aId, true); }
+    CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
 
     void startEnumeratingMedia();
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp	(revision 42381)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp	(revision 42382)
@@ -645,5 +645,9 @@
     /* Open a direct session (this call will handle all errors) */
     bool busy = mSessionState != KSessionState_Unlocked;
-    CSession session = vboxGlobal().openSession (mMachineId, busy /* aExisting */);
+    CSession session;
+    if (busy)
+        session = vboxGlobal().openExistingSession(mMachineId);
+    else
+        session = vboxGlobal().openSession(mMachineId);
     if (session.isNull())
         return;
@@ -779,6 +783,9 @@
 
     /* Open a session to work with corresponding VM: */
-    CSession session = vboxGlobal().openSession(mMachineId,
-                                                mSessionState != KSessionState_Unlocked /* connect to existing */);
+    CSession session;
+    if (mSessionState != KSessionState_Unlocked)
+        session = vboxGlobal().openExistingSession(mMachineId);
+    else
+        session = vboxGlobal().openSession(mMachineId);
     fIsValid = !session.isNull();
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp	(revision 42381)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp	(revision 42382)
@@ -748,5 +748,5 @@
 
     /* Prepare session: */
-    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openSession(m_strMachineId, true /* shared */);
+    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openExistingSession(m_strMachineId);
     /* Check that session was created: */
     if (m_session.isNull())
@@ -787,6 +787,10 @@
 
     /* Prepare session: */
-    bool fSessionShared = dialogType() != SettingsDialogType_Offline;
-    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openSession(m_strMachineId, fSessionShared);
+    if (dialogType() == SettingsDialogType_Wrong)
+        m_session = CSession();
+    else if (dialogType() != SettingsDialogType_Offline)
+        m_session = vboxGlobal().openExistingSession(m_strMachineId);
+    else
+        m_session = vboxGlobal().openSession(m_strMachineId);
     /* Check that session was created: */
     if (m_session.isNull())
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 42381)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 42382)
@@ -961,5 +961,5 @@
   <enum
     name="LockType"
-    uuid="138b53f8-db4b-47c5-b32b-4ef52f769413"
+    uuid="168a6a8e-12fd-4878-a1f9-38a750a56089"
     >
     <desc>
@@ -971,4 +971,8 @@
     <const name="Shared" value="1">
       <desc>Request only a shared read lock for remote-controlling the machine.</desc>
+    </const>
+    <const name="VM" value="3">
+      <desc>Lock the machine for writing, and create objects necessary for
+        running a VM in this process.</desc>
     </const>
   </enum>
@@ -16396,4 +16400,5 @@
       </desc>
       <param name="machine" type="IMachine" dir="in"/>
+      <param name="lockType" type="LockType" dir="in"/>
     </method>
 
Index: /trunk/src/VBox/Main/include/ConsoleImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 42381)
+++ /trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 42382)
@@ -114,5 +114,5 @@
 
     // public initializers/uninitializers for internal purposes only
-    HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
+    HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
     void uninit();
 
Index: /trunk/src/VBox/Main/include/SessionImpl.h
===================================================================
--- /trunk/src/VBox/Main/include/SessionImpl.h	(revision 42381)
+++ /trunk/src/VBox/Main/include/SessionImpl.h	(revision 42382)
@@ -81,5 +81,5 @@
     STDMETHOD(GetPID)(ULONG *aPid);
     STDMETHOD(GetRemoteConsole)(IConsole **aConsole);
-    STDMETHOD(AssignMachine)(IMachine *aMachine);
+    STDMETHOD(AssignMachine)(IMachine *aMachine, LockType_T aLockType);
     STDMETHOD(AssignRemoteMachine)(IMachine *aMachine, IConsole *aConsole);
     STDMETHOD(UpdateMachineState)(MachineState_T aMachineState);
Index: /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 42381)
+++ /trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 42382)
@@ -434,5 +434,5 @@
 /////////////////////////////////////////////////////////////////////////////
 
-HRESULT Console::init(IMachine *aMachine, IInternalMachineControl *aControl)
+HRESULT Console::init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType)
 {
     AssertReturn(aMachine && aControl, E_INVALIDARG);
@@ -450,13 +450,14 @@
     unconst(mControl) = aControl;
 
-    /* Cache essential properties and objects */
+    /* Cache essential properties and objects, and create child objects */
 
     rc = mMachine->COMGETTER(State)(&mMachineState);
     AssertComRCReturnRC(rc);
 
-    rc = mMachine->COMGETTER(VRDEServer)(unconst(mVRDEServer).asOutParam());
-    AssertComRCReturnRC(rc);
-
-    /* Create associated child COM objects */
+#ifdef VBOX_WITH_EXTPACK
+    unconst(mptrExtPackManager).createObject();
+    rc = mptrExtPackManager->initExtPackManager(NULL, VBOXEXTPACKCTX_VM_PROCESS);
+        AssertComRCReturnRC(rc);
+#endif
 
     // Event source may be needed by other children
@@ -465,42 +466,4 @@
     AssertComRCReturnRC(rc);
 
-    unconst(mGuest).createObject();
-    rc = mGuest->init(this);
-    AssertComRCReturnRC(rc);
-
-    unconst(mKeyboard).createObject();
-    rc = mKeyboard->init(this);
-    AssertComRCReturnRC(rc);
-
-    unconst(mMouse).createObject();
-    rc = mMouse->init(this);
-    AssertComRCReturnRC(rc);
-
-    unconst(mDisplay).createObject();
-    rc = mDisplay->init(this);
-    AssertComRCReturnRC(rc);
-
-    unconst(mVRDEServerInfo).createObject();
-    rc = mVRDEServerInfo->init(this);
-    AssertComRCReturnRC(rc);
-
-#ifdef VBOX_WITH_EXTPACK
-    unconst(mptrExtPackManager).createObject();
-    rc = mptrExtPackManager->initExtPackManager(NULL, VBOXEXTPACKCTX_VM_PROCESS);
-    AssertComRCReturnRC(rc);
-#endif
-
-    /* Grab global and machine shared folder lists */
-
-    rc = fetchSharedFolders(true /* aGlobal */);
-    AssertComRCReturnRC(rc);
-    rc = fetchSharedFolders(false /* aGlobal */);
-    AssertComRCReturnRC(rc);
-
-    /* Create other child objects */
-
-    unconst(mConsoleVRDPServer) = new ConsoleVRDPServer(this);
-    AssertReturn(mConsoleVRDPServer, E_FAIL);
-
     mcAudioRefs = 0;
     mcVRDPClients = 0;
@@ -508,56 +471,93 @@
     mcGuestCredentialsProvided = false;
 
-    /* Figure out size of meAttachmentType vector */
-    ComPtr<IVirtualBox> pVirtualBox;
-    rc = aMachine->COMGETTER(Parent)(pVirtualBox.asOutParam());
-    AssertComRC(rc);
-    ComPtr<ISystemProperties> pSystemProperties;
-    if (pVirtualBox)
-        pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
-    ChipsetType_T chipsetType = ChipsetType_PIIX3;
-    aMachine->COMGETTER(ChipsetType)(&chipsetType);
-    ULONG maxNetworkAdapters = 0;
-    if (pSystemProperties)
-        pSystemProperties->GetMaxNetworkAdapters(chipsetType, &maxNetworkAdapters);
-    meAttachmentType.resize(maxNetworkAdapters);
-    for (ULONG slot = 0; slot < maxNetworkAdapters; ++slot)
-        meAttachmentType[slot] = NetworkAttachmentType_Null;
-
-
-    // VirtualBox 4.0: We no longer initialize the VMMDev instance here,
-    // which starts the HGCM thread. Instead, this is now done in the
-    // power-up thread when a VM is actually being powered up to avoid
-    // having HGCM threads all over the place every time a session is
-    // opened, even if that session will not run a VM.
-    //     unconst(m_pVMMDev) = new VMMDev(this);
-    //     AssertReturn(mVMMDev, E_FAIL);
-
-    unconst(mAudioSniffer) = new AudioSniffer(this);
-    AssertReturn(mAudioSniffer, E_FAIL);
+    /* Now the VM specific parts */
+    if (aLockType == LockType_VM)
+    {
+        rc = mMachine->COMGETTER(VRDEServer)(unconst(mVRDEServer).asOutParam());
+        AssertComRCReturnRC(rc);
+
+        unconst(mGuest).createObject();
+        rc = mGuest->init(this);
+        AssertComRCReturnRC(rc);
+
+        unconst(mKeyboard).createObject();
+        rc = mKeyboard->init(this);
+        AssertComRCReturnRC(rc);
+
+        unconst(mMouse).createObject();
+        rc = mMouse->init(this);
+        AssertComRCReturnRC(rc);
+
+        unconst(mDisplay).createObject();
+        rc = mDisplay->init(this);
+        AssertComRCReturnRC(rc);
+
+        unconst(mVRDEServerInfo).createObject();
+        rc = mVRDEServerInfo->init(this);
+        AssertComRCReturnRC(rc);
+
+        /* Grab global and machine shared folder lists */
+
+        rc = fetchSharedFolders(true /* aGlobal */);
+        AssertComRCReturnRC(rc);
+        rc = fetchSharedFolders(false /* aGlobal */);
+        AssertComRCReturnRC(rc);
+
+        /* Create other child objects */
+
+        unconst(mConsoleVRDPServer) = new ConsoleVRDPServer(this);
+        AssertReturn(mConsoleVRDPServer, E_FAIL);
+
+        /* Figure out size of meAttachmentType vector */
+        ComPtr<IVirtualBox> pVirtualBox;
+        rc = aMachine->COMGETTER(Parent)(pVirtualBox.asOutParam());
+        AssertComRC(rc);
+        ComPtr<ISystemProperties> pSystemProperties;
+        if (pVirtualBox)
+            pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam());
+        ChipsetType_T chipsetType = ChipsetType_PIIX3;
+        aMachine->COMGETTER(ChipsetType)(&chipsetType);
+        ULONG maxNetworkAdapters = 0;
+        if (pSystemProperties)
+            pSystemProperties->GetMaxNetworkAdapters(chipsetType, &maxNetworkAdapters);
+        meAttachmentType.resize(maxNetworkAdapters);
+        for (ULONG slot = 0; slot < maxNetworkAdapters; ++slot)
+            meAttachmentType[slot] = NetworkAttachmentType_Null;
+
+        // VirtualBox 4.0: We no longer initialize the VMMDev instance here,
+        // which starts the HGCM thread. Instead, this is now done in the
+        // power-up thread when a VM is actually being powered up to avoid
+        // having HGCM threads all over the place every time a session is
+        // opened, even if that session will not run a VM.
+        //     unconst(m_pVMMDev) = new VMMDev(this);
+        //     AssertReturn(mVMMDev, E_FAIL);
+
+        unconst(mAudioSniffer) = new AudioSniffer(this);
+        AssertReturn(mAudioSniffer, E_FAIL);
 #ifdef VBOX_WITH_USB_VIDEO
-    unconst(mUsbWebcamInterface) = new UsbWebcamInterface(this);
-    AssertReturn(mUsbWebcamInterface, E_FAIL);
+        unconst(mUsbWebcamInterface) = new UsbWebcamInterface(this);
+        AssertReturn(mUsbWebcamInterface, E_FAIL);
 #endif
 #ifdef VBOX_WITH_USB_CARDREADER
-    unconst(mUsbCardReader) = new UsbCardReader(this);
-    AssertReturn(mUsbCardReader, E_FAIL);
+        unconst(mUsbCardReader) = new UsbCardReader(this);
+        AssertReturn(mUsbCardReader, E_FAIL);
 #endif
 
-    /* VirtualBox events registration. */
-    {
-        ComPtr<IEventSource> pES;
-        rc = pVirtualBox->COMGETTER(EventSource)(pES.asOutParam());
-        AssertComRC(rc);
-        ComObjPtr<VmEventListenerImpl> aVmListener;
-        aVmListener.createObject();
-        aVmListener->init(new VmEventListener(), this);
-        mVmListener = aVmListener;
-        com::SafeArray<VBoxEventType_T> eventTypes;
-        eventTypes.push_back(VBoxEventType_OnNATRedirect);
-        eventTypes.push_back(VBoxEventType_OnHostPciDevicePlug);
-        rc = pES->RegisterListener(aVmListener, ComSafeArrayAsInParam(eventTypes), true);
-        AssertComRC(rc);
-    }
-
+        /* VirtualBox events registration. */
+        {
+            ComPtr<IEventSource> pES;
+            rc = pVirtualBox->COMGETTER(EventSource)(pES.asOutParam());
+            AssertComRC(rc);
+            ComObjPtr<VmEventListenerImpl> aVmListener;
+            aVmListener.createObject();
+            aVmListener->init(new VmEventListener(), this);
+            mVmListener = aVmListener;
+            com::SafeArray<VBoxEventType_T> eventTypes;
+            eventTypes.push_back(VBoxEventType_OnNATRedirect);
+            eventTypes.push_back(VBoxEventType_OnHostPciDevicePlug);
+            rc = pES->RegisterListener(aVmListener, ComSafeArrayAsInParam(eventTypes), true);
+            AssertComRC(rc);
+        }
+    }
 
     /* Confirm a successful initialization when it's the case */
Index: /trunk/src/VBox/Main/src-client/SessionImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/SessionImpl.cpp	(revision 42381)
+++ /trunk/src/VBox/Main/src-client/SessionImpl.cpp	(revision 42382)
@@ -300,5 +300,5 @@
 }
 
-STDMETHODIMP Session::AssignMachine(IMachine *aMachine)
+STDMETHODIMP Session::AssignMachine(IMachine *aMachine, LockType_T aLockType)
 {
     LogFlowThisFuncEnter();
@@ -337,5 +337,5 @@
     AssertComRCReturn(rc, rc);
 
-    rc = mConsole->init(aMachine, mControl);
+    rc = mConsole->init(aMachine, mControl, aLockType);
     AssertComRCReturn(rc, rc);
 
@@ -358,6 +358,9 @@
         /* some cleanup */
         mControl.setNull();
-        mConsole->uninit();
-        mConsole.setNull();
+        if (!mConsole.isNull())
+        {
+            mConsole->uninit();
+            mConsole.setNull();
+        }
     }
 
@@ -531,4 +534,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onNetworkAdapterChange(networkAdapter, changeAdapter);
@@ -545,4 +549,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onSerialPortChange(serialPort);
@@ -559,4 +564,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onParallelPortChange(parallelPort);
@@ -573,4 +579,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onStorageControllerChange();
@@ -587,4 +594,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onMediumChange(aMediumAttachment, aForce);
@@ -601,4 +609,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onCPUChange(aCPU, aRemove);
@@ -615,4 +624,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onCPUExecutionCapChange(aExecutionCap);
@@ -629,4 +639,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onVRDEServerChange(aRestart);
@@ -643,4 +654,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onUSBControllerChange();
@@ -657,4 +669,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onSharedFolderChange(aGlobal);
@@ -671,4 +684,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onClipboardModeChange(aClipboardMode);
@@ -701,4 +715,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onUSBDeviceAttach(aDevice, aError, aMaskedIfs);
@@ -716,4 +731,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onUSBDeviceDetach(aId, aError);
@@ -728,4 +744,5 @@
 
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     if (mState != SessionState_Locked)
@@ -753,4 +770,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onBandwidthGroupChange(aBandwidthGroup);
@@ -767,4 +785,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     return mConsole->onStorageDeviceChange(aMediumAttachment, aRemove);
@@ -796,4 +815,10 @@
     if (aIsSetter && (aFlags != NULL) && !VALID_PTR(aFlags))
         return E_INVALIDARG;
+
+    /* If this session is not in a VM process fend off the call. The caller
+     * handles this correctly, by doing the operation in VBoxSVC. */
+    if (!mConsole)
+        return E_ACCESSDENIED;
+
     if (!aIsSetter)
         return mConsole->getGuestProperty(aName, aRetValue, aRetTimestamp, aRetFlags);
@@ -830,4 +855,10 @@
     if (ComSafeArrayOutIsNull(aFlags))
         return E_POINTER;
+
+    /* If this session is not in a VM process fend off the call. The caller
+     * handles this correctly, by doing the operation in VBoxSVC. */
+    if (!mConsole)
+        return E_ACCESSDENIED;
+
     return mConsole->enumerateGuestProperties(aPatterns,
                                               ComSafeArrayOutArg(aNames),
@@ -856,4 +887,5 @@
                         Global::stringifySessionState(mState));
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
     CheckComArgNotNull(aMediumAttachment);
     CheckComArgSafeArrayNotNull(aChildrenToReparent);
@@ -874,4 +906,5 @@
     AssertReturn(mState == SessionState_Locked, VBOX_E_INVALID_VM_STATE);
     AssertReturn(mType == SessionType_WriteLock, VBOX_E_INVALID_OBJECT_STATE);
+    AssertReturn(mConsole, VBOX_E_INVALID_OBJECT_STATE);
 
     mConsole->enableVMMStatistics(aEnable);
@@ -940,6 +973,9 @@
     if (mType == SessionType_WriteLock)
     {
-        mConsole->uninit();
-        mConsole.setNull();
+        if (!mConsole.isNull())
+        {
+            mConsole->uninit();
+            mConsole.setNull();
+        }
     }
     else
Index: /trunk/src/VBox/Main/src-server/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 42381)
+++ /trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 42382)
@@ -3304,5 +3304,5 @@
 
             LogFlowThisFunc(("Calling AssignMachine()...\n"));
-            rc = pSessionControl->AssignMachine(sessionMachine);
+            rc = pSessionControl->AssignMachine(sessionMachine, lockType);
             LogFlowThisFunc(("AssignMachine() returned %08X\n", rc));
 
@@ -3419,7 +3419,7 @@
     {
         /*
-        *  tell the client watcher thread to update the set of
-        *  machines that have open sessions
-        */
+         *  tell the client watcher thread to update the set of
+         *  machines that have open sessions
+         */
         mParent->updateClientWatcher();
 
@@ -7239,5 +7239,5 @@
     /* inform the session that it will be a remote one */
     LogFlowThisFunc(("Calling AssignMachine (NULL)...\n"));
-    HRESULT rc = aControl->AssignMachine(NULL);
+    HRESULT rc = aControl->AssignMachine(NULL, LockType_Write);
     LogFlowThisFunc(("AssignMachine (NULL) returned %08X\n", rc));
 
