Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 45801)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.cpp	(revision 45802)
@@ -80,4 +80,5 @@
 static BOOL vboxDtIsInputDesktop();
 static HANDLE vboxDtGetNotifyEvent();
+static BOOL vboxDtCheckTimer(WPARAM wParam);
 
 /* caps API */
@@ -617,4 +618,14 @@
 }
 
+static void VBoxTrayCheckDt()
+{
+    BOOL fOldAllowedState = VBoxConsoleIsAllowed();
+    if (vboxDtHandleEvent())
+    {
+        if (!VBoxConsoleIsAllowed() != !fOldAllowedState)
+            VBoxConsoleEnable(!fOldAllowedState);
+    }
+}
+
 static int vboxTrayServiceMain(void)
 {
@@ -738,10 +749,5 @@
                                 {
                                     Log(("VBoxTray: Event 'Dt' triggered\n"));
-                                    BOOL fOldAllowedState = VBoxConsoleIsAllowed();
-                                    if (vboxDtHandleEvent())
-                                    {
-                                        if (!VBoxConsoleIsAllowed() != !fOldAllowedState)
-                                            VBoxConsoleEnable(!fOldAllowedState);
-                                    }
+                                    VBoxTrayCheckDt();
                                     fHandled = TRUE;
                                 }
@@ -909,4 +915,6 @@
             if (VBoxCapsCheckTimer(wParam))
                 return 0;
+            if(vboxDtCheckTimer(wParam))
+                return 0;
 
             switch (wParam)
@@ -1158,4 +1166,5 @@
     HANDLE hNotifyEvent;
     BOOL fIsInputDesktop;
+    UINT_PTR idTimer;
     HMODULE hHookModule;
     BOOL (* pfnVBoxHookInstallActiveDesktopTracker)(HMODULE hDll);
@@ -1196,4 +1205,15 @@
     return fIsInputDt;
 }
+
+static BOOL vboxDtCheckTimer(WPARAM wParam)
+{
+    if (wParam != gVBoxDt.idTimer)
+        return FALSE;
+
+    VBoxTrayCheckDt();
+
+    return TRUE;
+}
+
 static int vboxDtInit()
 {
@@ -1210,73 +1230,86 @@
     memset(&gVBoxDt, 0, sizeof (gVBoxDt));
 
-    /* For Vista and up we need to change the integrity of the security descriptor, too. */
-    if (gMajorVersion >= 6)
-    {
-        gVBoxDt.hNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME);
-        if (gVBoxDt.hNotifyEvent != NULL)
-        {
-            gVBoxDt.hHookModule = LoadLibrary(VBOXHOOK_DLL_NAME);
-            if (gVBoxDt.hHookModule)
-            {
-                *(uintptr_t *)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
-                if (!gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker)
+    gVBoxDt.hNotifyEvent = CreateEvent(NULL, FALSE, FALSE, VBOXHOOK_GLOBAL_DT_EVENT_NAME);
+    if (gVBoxDt.hNotifyEvent != NULL)
+    {
+        gVBoxDt.hHookModule = LoadLibrary(VBOXHOOK_DLL_NAME);
+        if (gVBoxDt.hHookModule)
+        {
+            *(uintptr_t *)&gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
+            if (!gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker)
+            {
+                WARN(("VBoxTray: VBoxHookInstallActiveDesktopTracker not found\n"));
+                rc = VERR_NOT_SUPPORTED;
+            }
+
+            *(uintptr_t *)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker  = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
+            if (!gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker)
+            {
+                WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n"));
+                rc = VERR_NOT_SUPPORTED;
+            }
+
+            if (VINF_SUCCESS == rc)
+            {
+                gVBoxDt.hUSER32 = LoadLibrary("User32.dll");
+                if (gVBoxDt.hUSER32)
                 {
-                    WARN(("VBoxTray: VBoxHookInstallActiveDesktopTracker not found\n"));
-                    rc = VERR_NOT_SUPPORTED;
-                }
-
-                *(uintptr_t *)&gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker  = (uintptr_t)GetProcAddress(gVBoxDt.hHookModule, "VBoxHookInstallActiveDesktopTracker");
-                if (!gVBoxDt.pfnVBoxHookRemoveActiveDesktopTracker)
-                {
-                    WARN(("VBoxTray: VBoxHookRemoveActiveDesktopTracker not found\n"));
-                    rc = VERR_NOT_SUPPORTED;
-                }
-
-                if (VINF_SUCCESS == rc)
-                {
-                    gVBoxDt.hUSER32 = LoadLibrary("User32.dll");
-                    if (gVBoxDt.hUSER32)
+                    *(uintptr_t *)&gVBoxDt.pfnGetThreadDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "GetThreadDesktop");
+                    if (!gVBoxDt.pfnGetThreadDesktop)
                     {
-                        *(uintptr_t *)&gVBoxDt.pfnGetThreadDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "GetThreadDesktop");
-                        if (!gVBoxDt.pfnGetThreadDesktop)
+                        WARN(("VBoxTray: GetThreadDesktop not found\n"));
+                        rc = VERR_NOT_SUPPORTED;
+                    }
+
+                    *(uintptr_t *)&gVBoxDt.pfnOpenInputDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "OpenInputDesktop");
+                    if (!gVBoxDt.pfnOpenInputDesktop)
+                    {
+                        WARN(("VBoxTray: OpenInputDesktop not found\n"));
+                        rc = VERR_NOT_SUPPORTED;
+                    }
+
+                    *(uintptr_t *)&gVBoxDt.pfnCloseDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "CloseDesktop");
+                    if (!gVBoxDt.pfnCloseDesktop)
+                    {
+                        WARN(("VBoxTray: CloseDesktop not found\n"));
+                        rc = VERR_NOT_SUPPORTED;
+                    }
+
+                    if (VINF_SUCCESS == rc)
+                    {
+                        BOOL bRc = FALSE;
+                        /* For Vista and up we need to change the integrity of the security descriptor, too. */
+                        if (gMajorVersion >= 6)
                         {
-                            WARN(("VBoxTray: GetThreadDesktop not found\n"));
-                            rc = VERR_NOT_SUPPORTED;
+                            bRc = gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(gVBoxDt.hHookModule);
+                            if (!bRc)
+                            {
+                                DWORD dwErr = GetLastError();
+                                WARN(("VBoxTray: pfnVBoxHookInstallActiveDesktopTracker failed, last error = %08X\n", dwErr));
+                            }
                         }
 
-                        *(uintptr_t *)&gVBoxDt.pfnOpenInputDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "OpenInputDesktop");
-                        if (!gVBoxDt.pfnOpenInputDesktop)
+                        if (!bRc)
                         {
-                            WARN(("VBoxTray: OpenInputDesktop not found\n"));
-                            rc = VERR_NOT_SUPPORTED;
+                            gVBoxDt.idTimer = SetTimer(ghwndToolWindow, TIMERID_VBOXTRAY_DT_TIMER, 500, (TIMERPROC)NULL);
+                            if (!gVBoxDt.idTimer)
+                            {
+                                DWORD dwErr = GetLastError();
+                                WARN(("VBoxTray: SetTimer error %08X\n", dwErr));
+                                rc = RTErrConvertFromWin32(dwErr);
+                            }
                         }
 
-                        *(uintptr_t *)&gVBoxDt.pfnCloseDesktop = (uintptr_t)GetProcAddress(gVBoxDt.hUSER32, "CloseDesktop");
-                        if (!gVBoxDt.pfnCloseDesktop)
+                        if (RT_SUCCESS(rc))
                         {
-                            WARN(("VBoxTray: CloseDesktop not found\n"));
-                            rc = VERR_NOT_SUPPORTED;
-                        }
-
-                        if (VINF_SUCCESS == rc)
-                        {
-                            gVBoxDt.pfnVBoxHookInstallActiveDesktopTracker(gVBoxDt.hHookModule);
                             gVBoxDt.fIsInputDesktop = vboxDtCalculateIsInputDesktop();
                             return VINF_SUCCESS;
                         }
-                        FreeLibrary(gVBoxDt.hUSER32);
                     }
+                    FreeLibrary(gVBoxDt.hUSER32);
                 }
-
-                FreeLibrary(gVBoxDt.hHookModule);
-            }
-            else
-            {
-                DWORD dwErr = GetLastError();
-                WARN(("VBoxTray: CreateEvent for Seamless failed, last error = %08X\n", dwErr));
-                rc = RTErrConvertFromWin32(dwErr);
-            }
-
-            CloseHandle(gVBoxDt.hNotifyEvent);
+            }
+
+            FreeLibrary(gVBoxDt.hHookModule);
         }
         else
@@ -1286,5 +1319,14 @@
             rc = RTErrConvertFromWin32(dwErr);
         }
-    }
+
+        CloseHandle(gVBoxDt.hNotifyEvent);
+    }
+    else
+    {
+        DWORD dwErr = GetLastError();
+        WARN(("VBoxTray: CreateEvent for Seamless failed, last error = %08X\n", dwErr));
+        rc = RTErrConvertFromWin32(dwErr);
+    }
+
 
     memset(&gVBoxDt, 0, sizeof (gVBoxDt));
Index: trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h	(revision 45801)
+++ trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxTray.h	(revision 45802)
@@ -82,4 +82,5 @@
 #define TIMERID_VBOXTRAY_CHECK_HOSTVERSION      1000
 #define TIMERID_VBOXTRAY_CAPS_TIMER             1001
+#define TIMERID_VBOXTRAY_DT_TIMER               1002
 
 /* The environment information for services. */
