Index: trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/include/VBoxDefs.h	(revision 14578)
@@ -119,5 +119,6 @@
         ChangeGUILanguageEventType,
 #if defined (VBOX_GUI_WITH_SYSTRAY)
-        ChangeGUITrayIconEventType,
+        CanShowTrayIconEventType,
+        ChangeTrayIconEventType,
 #endif
         AddVDMUrlsEventType
@@ -152,4 +153,7 @@
     static const char* GUI_LastVMSelected;
     static const char* GUI_InfoDlgState;
+#ifdef VBOX_GUI_WITH_SYSTRAY
+    static const char* GUI_TrayIconWinID;
+#endif
 };
 
Index: trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGlobal.h	(revision 14578)
@@ -391,9 +391,20 @@
 
 #ifdef VBOX_GUI_WITH_SYSTRAY
-class VBoxChangeGUITrayIconEvent : public QEvent
-{
-public:
-    VBoxChangeGUITrayIconEvent (bool aEnabled)
-        : QEvent ((QEvent::Type) VBoxDefs::ChangeGUITrayIconEventType)
+class VBoxCanShowTrayIconEvent : public QEvent
+{
+public:
+    VBoxCanShowTrayIconEvent (bool aCanShow)
+        : QEvent ((QEvent::Type) VBoxDefs::CanShowTrayIconEventType)
+        , mCanShow (aCanShow)
+        {}
+
+    const bool mCanShow;
+};
+
+class VBoxChangeTrayIconEvent : public QEvent
+{
+public:
+    VBoxChangeTrayIconEvent (bool aEnabled)
+        : QEvent ((QEvent::Type) VBoxDefs::ChangeTrayIconEventType)
         , mEnabled (aEnabled)
         {}
@@ -470,6 +481,9 @@
     QWidget *mainWindow() const { return mMainWindow; }
 
-
     bool isVMConsoleProcess() const { return !vmUuid.isNull(); }
+#ifdef VBOX_GUI_WITH_SYSTRAY
+    bool isTrayIcon() const;
+    bool trayIconInstall();
+#endif
     QUuid managedVMUuid() const { return vmUuid; }
 
@@ -938,5 +952,6 @@
     void snapshotChanged (const VBoxSnapshotEvent &e);
 #ifdef VBOX_GUI_WITH_SYSTRAY
-    void systrayIconChanged (const VBoxChangeGUITrayIconEvent &e);
+    void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
+    void trayIconChanged (const VBoxChangeTrayIconEvent &e);
 #endif
 
@@ -980,4 +995,7 @@
     QUuid vmUuid;
 
+#ifdef VBOX_GUI_WITH_SYSTRAY
+    bool mIsTrayIcon;           /* Is current instance responsible for tray icon? */
+#endif
     QThread *mMediaEnumThread;
     VBoxMediaList mMediaList;
Index: trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSelectorWnd.h	(revision 14578)
@@ -133,5 +133,6 @@
     void snapshotChanged (const VBoxSnapshotEvent &e);
 #ifdef VBOX_GUI_WITH_SYSTRAY
-    void systrayIconChanged (const VBoxChangeGUITrayIconEvent &e);
+    void trayIconCanShow (const VBoxCanShowTrayIconEvent &e);
+    void trayIconChanged (const VBoxChangeTrayIconEvent &e);
 #endif
 
Index: trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDefs.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDefs.cpp	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/VBoxDefs.cpp	(revision 14578)
@@ -45,2 +45,5 @@
 const char* VBoxDefs::GUI_LastVMSelected = "GUI/LastVMSelected";
 const char* VBoxDefs::GUI_InfoDlgState = "GUI/InfoDlgState";
+#ifdef VBOX_GUI_WITH_SYSTRAY
+const char* VBoxDefs::GUI_TrayIconWinID = "GUI/TrayIconWinID";
+#endif
Index: trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGlobal.cpp	(revision 14578)
@@ -654,5 +654,9 @@
     VBoxCallback (VBoxGlobal &aGlobal)
         : mGlobal (aGlobal)
-        , mIsRegDlgOwner (false), mIsUpdDlgOwner (false)
+        , mIsRegDlgOwner (false)
+        , mIsUpdDlgOwner (false)
+#ifdef VBOX_GUI_WITH_SYSTRAY
+        , mIsTrayIconOwner (false)
+#endif
     {
 #if defined (Q_OS_WIN32)
@@ -763,5 +767,21 @@
                     return S_OK;
                 }
-
+#ifdef VBOX_GUI_WITH_SYSTRAY
+                if (sKey == VBoxDefs::GUI_TrayIconWinID)
+                {
+                    if (mIsTrayIconOwner)
+                    {
+                        if (sVal.isEmpty() ||
+                            sVal == QString ("%1")
+                                .arg ((qulonglong) vboxGlobal().mainWindow()->winId()))
+                            *allowChange = TRUE;
+                        else
+                            *allowChange = FALSE;
+                    }
+                    else
+                        *allowChange = TRUE;
+                    return S_OK;
+                }
+#endif
                 /* try to set the global setting to check its syntax */
                 VBoxGlobalSettings gs (false /* non-null */);
@@ -831,8 +851,24 @@
                 if (sKey == "GUI/LanguageID")
                     QApplication::postEvent (&mGlobal, new VBoxChangeGUILanguageEvent (sVal));
-            #ifdef VBOX_GUI_WITH_SYSTRAY
+#ifdef VBOX_GUI_WITH_SYSTRAY
+                if (sKey == VBoxDefs::GUI_TrayIconWinID)
+                {
+                    if (sVal.isEmpty())
+                    {
+                        mIsTrayIconOwner = false;
+                        QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (true));
+                    }
+                    else if (sVal == QString ("%1")
+                             .arg ((qulonglong) vboxGlobal().mainWindow()->winId()))
+                    {
+                        mIsTrayIconOwner = true;
+                        QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (true));
+                    }
+                    else
+                        QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (false));
+                }
                 if (sKey == "GUI/TrayIcon/Enabled")
-                    QApplication::postEvent (&mGlobal, new VBoxChangeGUITrayIconEvent ((sVal.toLower() == "true") ? true : false));
-            #endif
+                    QApplication::postEvent (&mGlobal, new VBoxChangeTrayIconEvent ((sVal.toLower() == "true") ? true : false));
+#endif
 
                 mMutex.lock();
@@ -920,4 +956,7 @@
     bool mIsRegDlgOwner;
     bool mIsUpdDlgOwner;
+#ifdef VBOX_GUI_WITH_SYSTRAY
+    bool mIsTrayIconOwner;
+#endif
 
 #if defined (Q_OS_WIN32)
@@ -1189,4 +1228,7 @@
     , mSelectorWnd (NULL), mConsoleWnd (NULL)
     , mMainWindow (NULL)
+#ifdef VBOX_GUI_WITH_SYSTRAY
+    , mIsTrayIcon (false)
+#endif
 #ifdef VBOX_WITH_REGISTRATION
     , mRegDlg (NULL)
@@ -1357,4 +1399,43 @@
     return *mConsoleWnd;
 }
+
+#ifdef VBOX_GUI_WITH_SYSTRAY
+
+/**
+ *  Returns true if the current instance is responsible of showing/handling
+ *  the tray icon.
+ */
+bool VBoxGlobal::isTrayIcon() const
+{
+    return mIsTrayIcon;
+}
+
+/**
+ *  Tries to install the tray icon using the current instance (singleton).
+ *  Returns true on success, false on failure.
+ */
+bool VBoxGlobal::trayIconInstall()
+{
+    if (false == QSystemTrayIcon::isSystemTrayAvailable())
+        return false;
+
+    AssertMsg (vboxGlobal().mainWindow(),
+               ("Main window must not be null for systray!"));
+
+    mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID,
+                        QString ("%1").arg ((qulonglong) vboxGlobal().mainWindow()->winId()));
+
+    /* The first process which can grab this "mutex" will win ->
+     * It will be the tray icon menu then. */
+    if (mVBox.isOk())
+    {
+        mIsTrayIcon = true;
+        emit trayIconChanged (*(new VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled())));
+    }
+
+    return mIsTrayIcon;
+}
+
+#endif
 
 /**
@@ -5048,11 +5129,15 @@
         }
 #ifdef VBOX_GUI_WITH_SYSTRAY
-        case VBoxDefs::ChangeGUITrayIconEventType:
-        {
-            emit systrayIconChanged (*(VBoxChangeGUITrayIconEvent *) e);
+        case VBoxDefs::CanShowTrayIconEventType:
+        {
+            emit trayIconCanShow (*(VBoxCanShowTrayIconEvent *) e);
             return true;
         }
+        case VBoxDefs::ChangeTrayIconEventType:
+        {
+            emit trayIconChanged (*(VBoxChangeTrayIconEvent *) e);
+            return true;
+        }
 #endif
-
         default:
             break;
Index: trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSelectorWnd.cpp	(revision 14578)
@@ -675,14 +675,12 @@
              this, SLOT (snapshotChanged (const VBoxSnapshotEvent &)));
 #ifdef VBOX_GUI_WITH_SYSTRAY
-    connect (&vboxGlobal(), SIGNAL (systrayIconChanged (const VBoxChangeGUITrayIconEvent &)),
-             this, SLOT (systrayIconChanged (const VBoxChangeGUITrayIconEvent &)));
+    connect (&vboxGlobal(), SIGNAL (trayIconCanShow (const VBoxCanShowTrayIconEvent &)),
+             this, SLOT (trayIconCanShow (const VBoxCanShowTrayIconEvent &)));
+    connect (&vboxGlobal(), SIGNAL (trayIconChanged (const VBoxChangeTrayIconEvent &)),
+             this, SLOT (trayIconChanged (const VBoxChangeTrayIconEvent &)));
 #endif
 
     /* bring the VM list to the focus */
     mVMListView->setFocus();
-
-#ifdef VBOX_GUI_WITH_SYSTRAY
-    mTrayIcon->trayIconShow (settings.trayIconEnabled());
-#endif
 }
 
@@ -1085,5 +1083,6 @@
 
 #ifdef VBOX_GUI_WITH_SYSTRAY
-    mTrayIcon->refresh();
+    if (vboxGlobal().isTrayIcon())
+        mTrayIcon->refresh();
 #endif
 }
@@ -1319,6 +1318,9 @@
 
 #ifdef VBOX_GUI_WITH_SYSTRAY
-    mTrayIcon->retranslateUi();
-    mTrayIcon->refresh();
+    if (vboxGlobal().isTrayIcon())
+    {
+        mTrayIcon->retranslateUi();
+        mTrayIcon->refresh();
+    }
 #endif
 }
@@ -1613,5 +1615,10 @@
 #ifdef VBOX_GUI_WITH_SYSTRAY
 
-void VBoxSelectorWnd::systrayIconChanged (const VBoxChangeGUITrayIconEvent &aEvent)
+void VBoxSelectorWnd::trayIconCanShow (const VBoxCanShowTrayIconEvent &aEvent)
+{
+    emit trayIconChanged (VBoxChangeTrayIconEvent (vboxGlobal().settings().trayIconEnabled()));
+}
+
+void VBoxSelectorWnd::trayIconChanged (const VBoxChangeTrayIconEvent &aEvent)
 {
     mTrayIcon->trayIconShow (aEvent.mEnabled);
@@ -1672,12 +1679,15 @@
     connect (mShowSelectorAction, SIGNAL (triggered()), mParent, SLOT (showWindow()));
     connect (mHideSystrayMenuAction, SIGNAL (triggered()), this, SLOT (trayIconShow()));
-
-    VBoxGlobalSettings settings = vboxGlobal().settings();
-    trayIconShow (settings.trayIconEnabled());
 }
 
 VBoxTrayIcon::~VBoxTrayIcon ()
 {
-    hide();
+    /* Erase dialog handle in config file. */
+    if (vboxGlobal().isTrayIcon())
+    {
+        vboxGlobal().virtualBox().SetExtraData (VBoxDefs::GUI_TrayIconWinID,
+                                                QString::null);
+        hide();
+    }
 }
 
@@ -1715,10 +1725,10 @@
 void VBoxTrayIcon::showSubMenu ()
 {
+    if (!mActive)
+        return;
+
     VBoxVMItem* pItem = NULL;
     QMenu *pMenu = NULL;
     QVariant vID;
-
-    if (!mActive)
-        return;
 
     if ((pMenu = qobject_cast<QMenu*>(sender())))
@@ -1834,9 +1844,9 @@
 void VBoxTrayIcon::hideSubMenu ()
 {
+    if (!mActive)
+        return;
+
     VBoxVMItem* pItem = NULL;
     QVariant vID;
-
-    if (!mActive)
-        return;
 
     if (QMenu *pMenu = qobject_cast<QMenu*>(sender()))
@@ -1928,8 +1938,5 @@
 void VBoxTrayIcon::trayIconShow (bool aShow)
 {
-    if (false == QSystemTrayIcon::isSystemTrayAvailable())
-        return;
-
-    mActive = aShow;    
+    mActive = aShow;
     if (mActive)
     {
Index: trunk/src/VBox/Frontends/VirtualBox4/src/main.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox4/src/main.cpp	(revision 14577)
+++ trunk/src/VBox/Frontends/VirtualBox4/src/main.cpp	(revision 14578)
@@ -374,4 +374,11 @@
                 vboxGlobal().startEnumeratingMedia();
                 vboxGlobal().setMainWindow (&vboxGlobal().selectorWnd());
+#ifdef VBOX_GUI_WITH_SYSTRAY
+                if (   vboxGlobal().trayIconInstall()
+                    && vboxGlobal().isTrayIcon())
+                {
+                    /* Nothing to do here yet. */
+                }
+#endif
                 vboxGlobal().selectorWnd().show();
 #ifdef VBOX_WITH_REGISTRATION_REQUEST
