Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 53043)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 53046)
@@ -213,12 +213,7 @@
     prepareMachineLogic();
 
-    /* Now power up the machine.
-     * Actually powerUp does more that just a power up,
-     * so call it regardless of isSeparateProcess setting. */
-    uisession()->powerUp();
-
-    /* Initialization of MachineLogic internals after the powerUp.
-     * This is a hack, maybe more generic approach can be used. */
-    machineLogic()->initializePostPowerUp();
+    /* Try to initialize session UI: */
+    if (!uisession()->initialize())
+        return false;
 
     /* True by default: */
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 53043)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 53046)
@@ -829,5 +829,5 @@
 {
     /* We should check for entering/exiting requested modes: */
-    connect(uisession(), SIGNAL(sigStarted()), this, SLOT(sltCheckForRequestedVisualStateType()));
+    connect(uisession(), SIGNAL(sigInitialized()), this, SLOT(sltCheckForRequestedVisualStateType()));
     connect(uisession(), SIGNAL(sigAdditionsStateChange()), this, SLOT(sltCheckForRequestedVisualStateType()));
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 53043)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 53046)
@@ -156,13 +156,32 @@
 }
 
-void UISession::powerUp()
-{
-    /* Prepare powerup: */
-    bool fPrepared = preparePowerUp();
-    if (!fPrepared)
-        return;
+bool UISession::initialize()
+{
+    /* Preprocess initialization: */
+    if (!preprocessInitialization())
+        return false;
+
+    /* Notify user about mouse&keyboard auto-capturing: */
+    if (vboxGlobal().settings().autoCapture())
+        popupCenter().remindAboutAutoCapture(machineLogic()->activeMachineWindow());
+
+    /* Check if we are in teleportation waiting mode.
+     * In that case no first run wizard is necessary. */
+    m_machineState = machine().GetState();
+    if (   isFirstTimeStarted()
+        && !((   m_machineState == KMachineState_PoweredOff
+              || m_machineState == KMachineState_Aborted
+              || m_machineState == KMachineState_Teleported)
+             && machine().GetTeleporterEnabled()))
+    {
+        UISafePointerWizard pWizard = new UIWizardFirstRun(mainMachineWindow(), machine());
+        pWizard->prepare();
+        pWizard->exec();
+        if (pWizard)
+            delete pWizard;
+    }
 
     /* Apply debug settings from the command line. */
-    if (debugger().isOk())
+    if (!debugger().isNull() && debugger().isOk())
     {
         if (vboxGlobal().isPatmDisabled())
@@ -180,137 +199,101 @@
     }
 
+    /* Power UP if this is NOT separate process: */
     if (!vboxGlobal().isSeparateProcess())
-    {
-        /* Power UP machine: */
-#ifdef VBOX_WITH_DEBUGGER_GUI
-        CProgress progress = vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled() ?
-                             console().PowerUpPaused() : console().PowerUp();
-#else /* !VBOX_WITH_DEBUGGER_GUI */
-        CProgress progress = console().PowerUp();
-#endif /* !VBOX_WITH_DEBUGGER_GUI */
-
-        /* Check for immediate failure: */
-        if (!console().isOk())
-        {
-            if (vboxGlobal().showStartVMErrors())
-                msgCenter().cannotStartMachine(console(), machineName());
-            closeRuntimeUI();
-            return;
-        }
-
-        /* Guard progressbar warnings from auto-closing: */
-        if (uimachine()->machineLogic())
-            uimachine()->machineLogic()->setPreventAutoClose(true);
-
-        /* Show "Starting/Restoring" progress dialog: */
-        if (isSaved())
-        {
-            msgCenter().showModalProgressDialog(progress, machineName(), ":/progress_state_restore_90px.png", 0, 0);
-            /* After restoring from 'saved' state, machine-window(s) geometry should be adjusted: */
-            machineLogic()->adjustMachineWindowsGeometry();
-        }
-        else
-            msgCenter().showModalProgressDialog(progress, machineName(), ":/progress_start_90px.png");
-
-        /* Check for a progress failure: */
-        if (!progress.isOk() || progress.GetResultCode() != 0)
-        {
-            if (vboxGlobal().showStartVMErrors())
-                msgCenter().cannotStartMachine(progress, machineName());
-            closeRuntimeUI();
-            return;
-        }
-
-        /* Allow further auto-closing: */
-        if (uimachine()->machineLogic())
-            uimachine()->machineLogic()->setPreventAutoClose(false);
-    }
-    else
-    {
-        /* Fetch the current mouse state: */
+        if (!powerUp())
+            return false;
+
+    /* Check if we missed a really quick termination after successful startup: */
+    if (isTurnedOff())
+        return false;
+
+    /* Postprocess initialization: */
+    if (!postprocessInitialization())
+        return false;
+
+    /* Fetch corresponding states: */
+    if (vboxGlobal().isSeparateProcess())
+    {
         m_fIsMouseSupportsAbsolute = mouse().GetAbsoluteSupported();
         m_fIsMouseSupportsRelative = mouse().GetRelativeSupported();
         m_fIsMouseSupportsMultiTouch = mouse().GetMultiTouchSupported();
         m_fIsMouseHostCursorNeeded = mouse().GetNeedsHostCursor();
-        /* Fetch the current guest additions state: */
         sltAdditionsChange();
     }
-
-    /* Check if we missed a really quick termination after successful startup, and process it if we did: */
-    if (isTurnedOff())
-    {
-        closeRuntimeUI();
-        return;
-    }
-
-    /* Check if the required virtualization features are active. We get this info only when the session is active. */
-    const bool fIs64BitsGuest = vboxGlobal().virtualBox().GetGuestOSType(guest().GetOSTypeId()).GetIs64Bit();
-    const bool fRecommendVirtEx = vboxGlobal().virtualBox().GetGuestOSType(guest().GetOSTypeId()).GetRecommendedVirtEx();
-    AssertMsg(!fIs64BitsGuest || fRecommendVirtEx, ("Virtualization support missed for 64bit guest!\n"));
-    bool fIsVirtEnabled = debugger().GetHWVirtExEnabled();
-    if (fRecommendVirtEx && !fIsVirtEnabled)
-    {
-        bool fShouldWeClose;
-
-        bool fVTxAMDVSupported = vboxGlobal().host().GetProcessorFeature(KProcessorFeature_HWVirtEx);
-
-        QApplication::processEvents();
-        setPause(true);
-
-        if (fIs64BitsGuest)
-            fShouldWeClose = msgCenter().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
-        else
-            fShouldWeClose = msgCenter().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
-
-        if (fShouldWeClose)
-        {
-            /* At this point the console is powered up.
-             * So we have to close this session again. */
-            CProgress progress = console().PowerDown();
-            if (console().isOk())
-            {
-                /* Guard progressbar warnings from auto-closing: */
-                if (uimachine()->machineLogic())
-                    uimachine()->machineLogic()->setPreventAutoClose(true);
-                /* Show the power down progress dialog */
-                msgCenter().showModalProgressDialog(progress, machineName(), ":/progress_poweroff_90px.png");
-                if (!progress.isOk() || progress.GetResultCode() != 0)
-                    msgCenter().cannotPowerDownMachine(progress, machineName());
-                /* Allow further auto-closing: */
-                if (uimachine()->machineLogic())
-                    uimachine()->machineLogic()->setPreventAutoClose(false);
-            }
-            else
-                msgCenter().cannotPowerDownMachine(console());
-            closeRuntimeUI();
-            return;
-        }
-
-        setPause(false);
-    }
+    machineLogic()->initializePostPowerUp();
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
+    /* Log whether 2D video acceleration is enabled: */
     LogRel(("2D video acceleration is %s.\n",
            machine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable()
-                 ? "enabled"
-                 : "disabled"));
+           ? "enabled" : "disabled"));
 #endif /* VBOX_WITH_VIDEOHWACCEL */
 
-/* Check if HID LEDs sync is enabled and add a log message about it. */
+/* Log whether HID LEDs sync is enabled: */
 #if defined(Q_WS_MAC) || defined(Q_WS_WIN)
-    if(uimachine()->machineLogic()->isHidLedsSyncEnabled())
-        LogRel(("HID LEDs sync is enabled.\n"));
-    else
-        LogRel(("HID LEDs sync is disabled.\n"));
-#else
+    LogRel(("HID LEDs sync is %s.\n",
+            uimachine()->machineLogic()->isHidLedsSyncEnabled()
+            ? "enabled" : "disabled"));
+#else /* !Q_WS_MAC && !Q_WS_WIN */
     LogRel(("HID LEDs sync is not supported on this platform.\n"));
-#endif
+#endif /* !Q_WS_MAC && !Q_WS_WIN */
 
 #ifdef VBOX_GUI_WITH_PIDFILE
     vboxGlobal().createPidfile();
-#endif
-
-    /* Warn listeners about machine was started: */
-    emit sigStarted();
+#endif /* VBOX_GUI_WITH_PIDFILE */
+
+    /* Warn listeners about we are initialized: */
+    emit sigInitialized();
+
+    /* True by default: */
+    return true;
+}
+
+bool UISession::powerUp()
+{
+    /* Power UP machine: */
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    CProgress progress = vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled() ?
+                         console().PowerUpPaused() : console().PowerUp();
+#else /* !VBOX_WITH_DEBUGGER_GUI */
+    CProgress progress = console().PowerUp();
+#endif /* !VBOX_WITH_DEBUGGER_GUI */
+
+    /* Check for immediate failure: */
+    if (!console().isOk() || progress.isNull())
+    {
+        if (vboxGlobal().showStartVMErrors())
+            msgCenter().cannotStartMachine(console(), machineName());
+        return false;
+    }
+
+    /* Guard progressbar warnings from auto-closing: */
+    if (uimachine()->machineLogic())
+        uimachine()->machineLogic()->setPreventAutoClose(true);
+
+    /* Show "Starting/Restoring" progress dialog: */
+    if (isSaved())
+    {
+        msgCenter().showModalProgressDialog(progress, machineName(), ":/progress_state_restore_90px.png", 0, 0);
+        /* After restoring from 'saved' state, machine-window(s) geometry should be adjusted: */
+        machineLogic()->adjustMachineWindowsGeometry();
+    }
+    else
+        msgCenter().showModalProgressDialog(progress, machineName(), ":/progress_start_90px.png");
+
+    /* Check for progress failure: */
+    if (!progress.isOk() || progress.GetResultCode() != 0)
+    {
+        if (vboxGlobal().showStartVMErrors())
+            msgCenter().cannotStartMachine(progress, machineName());
+        return false;
+    }
+
+    /* Allow further auto-closing: */
+    if (uimachine()->machineLogic())
+        uimachine()->machineLogic()->setPreventAutoClose(false);
+
+    /* True by default: */
+    return true;
 }
 
@@ -891,5 +874,5 @@
     , m_fAllCloseActionsRestricted(false)
     /* Common flags: */
-    , m_fIsStarted(false)
+    , m_fInitialized(false)
     , m_fIsFirstTimeStarted(false)
     , m_fIsGuestResizeIgnored(false)
@@ -1101,5 +1084,5 @@
 void UISession::prepareConnections()
 {
-    connect(this, SIGNAL(sigStarted()), this, SLOT(sltMarkStarted()));
+    connect(this, SIGNAL(sigInitialized()), this, SLOT(sltMarkInitialized()));
     connect(this, SIGNAL(sigCloseRuntimeUI()), this, SLOT(sltCloseRuntimeUI()));
 
@@ -1682,26 +1665,6 @@
 }
 
-bool UISession::preparePowerUp()
-{
-    /* Notify user about mouse&keyboard auto-capturing: */
-    if (vboxGlobal().settings().autoCapture())
-        popupCenter().remindAboutAutoCapture(machineLogic()->activeMachineWindow());
-
-    /* Check if we are in teleportation waiting mode.
-     * In that case no first run wizard is necessary. */
-    m_machineState = machine().GetState();
-    if (   isFirstTimeStarted()
-        && !((   m_machineState == KMachineState_PoweredOff
-              || m_machineState == KMachineState_Aborted
-              || m_machineState == KMachineState_Teleported)
-             && machine().GetTeleporterEnabled()))
-    {
-        UISafePointerWizard pWizard = new UIWizardFirstRun(mainMachineWindow(), machine());
-        pWizard->prepare();
-        pWizard->exec();
-        if (pWizard)
-            delete pWizard;
-    }
-
+bool UISession::preprocessInitialization()
+{
 #ifdef VBOX_WITH_NETFLT
     /* Skip further checks if VM in saved state */
@@ -1758,14 +1721,53 @@
     if (!failedInterfaceNames.isEmpty())
     {
-        if (msgCenter().UIMessageCenter::cannotStartWithoutNetworkIf(machineName(), failedInterfaceNames.join(", ")))
+        if (msgCenter().cannotStartWithoutNetworkIf(machineName(), failedInterfaceNames.join(", ")))
             machineLogic()->openNetworkSettingsDialog();
         else
-        {
-            closeRuntimeUI();
             return false;
-        }
     }
 #endif /* VBOX_WITH_NETFLT */
 
+    /* True by default: */
+    return true;
+}
+
+bool UISession::postprocessInitialization()
+{
+    /* Check if the required virtualization features are active. We get this info only when the session is active. */
+    const bool fIs64BitsGuest = vboxGlobal().virtualBox().GetGuestOSType(guest().GetOSTypeId()).GetIs64Bit();
+    const bool fRecommendVirtEx = vboxGlobal().virtualBox().GetGuestOSType(guest().GetOSTypeId()).GetRecommendedVirtEx();
+    AssertMsg(!fIs64BitsGuest || fRecommendVirtEx, ("Virtualization support missed for 64bit guest!\n"));
+    bool fIsVirtEnabled = debugger().GetHWVirtExEnabled();
+    if (fRecommendVirtEx && !fIsVirtEnabled)
+    {
+        /* Check whether vt-x / amd-v supported: */
+        bool fVTxAMDVSupported = vboxGlobal().host().GetProcessorFeature(KProcessorFeature_HWVirtEx);
+
+        /* Pause VM: */
+        setPause(true);
+
+        /* Ask the user about further actions: */
+        bool fShouldWeClose;
+        if (fIs64BitsGuest)
+            fShouldWeClose = msgCenter().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
+        else
+            fShouldWeClose = msgCenter().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
+
+        /* If user asked to close VM: */
+        if (fShouldWeClose)
+        {
+            /* Prevent auto-closure during power off sequence: */
+            machineLogic()->setPreventAutoClose(true);
+            /* Power off VM: */
+            bool fServerCrashed = false;
+            powerOff(false, fServerCrashed);
+            return false;
+        }
+
+        /* Resume VM: */
+        setPause(false);
+    }
+
+    /* True by default: */
     return true;
 }
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 53043)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 53046)
@@ -90,5 +90,6 @@
 
     /* API: Runtime UI stuff: */
-    void powerUp();
+    bool initialize();
+    bool powerUp();
     bool saveState();
     bool shutdown();
@@ -181,5 +182,5 @@
     bool wasPaused() const { return machineStatePrevious() == KMachineState_Paused ||
                                     machineStatePrevious() == KMachineState_TeleportingPausedVM; }
-    bool isStarted() const { return m_fIsStarted; }
+    bool isInitialized() const { return m_fInitialized; }
     bool isFirstTimeStarted() const { return m_fIsFirstTimeStarted; }
     bool isGuestResizeIgnored() const { return m_fIsGuestResizeIgnored; }
@@ -285,5 +286,5 @@
 
     /* Session signals: */
-    void sigStarted();
+    void sigInitialized();
 
 public slots:
@@ -300,5 +301,5 @@
 
     /** Marks machine started. */
-    void sltMarkStarted() { m_fIsStarted = true; }
+    void sltMarkInitialized() { m_fInitialized = true; }
 
     /* Handler: Close Runtime UI stuff: */
@@ -371,5 +372,6 @@
     WId winId() const;
     void setPointerShape(const uchar *pShapeData, bool fHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight);
-    bool preparePowerUp();
+    bool preprocessInitialization();
+    bool postprocessInitialization();
     int countOfVisibleWindows();
 
@@ -470,5 +472,5 @@
 
     /* Common flags: */
-    bool m_fIsStarted : 1;
+    bool m_fInitialized : 1;
     bool m_fIsFirstTimeStarted : 1;
     bool m_fIsGuestResizeIgnored : 1;
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 53043)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 53046)
@@ -285,6 +285,6 @@
         uisession()->setRequestedVisualState(UIVisualStateType_Normal);
 
-        /* If session started already => push mode-change directly: */
-        if (uisession()->isStarted())
+        /* If session already initialized => push mode-change directly: */
+        if (uisession()->isInitialized())
             sltCheckForRequestedVisualStateType();
     }
