Index: /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.cpp	(revision 6359)
+++ /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.cpp	(revision 6360)
@@ -33,4 +33,8 @@
     /* ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
     LONG (WINAPI * pfnChangeDisplaySettingsEx)(LPCTSTR lpszDeviceName, LPDEVMODE lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam);
+
+    /* EnumDisplayDevices does not exist in NT. isVBoxDisplayDriverActive et al. are using these functions. */
+    BOOL (WINAPI * pfnEnumDisplayDevices)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags);
+
 } VBOXDISPLAYCONTEXT;
 
@@ -39,13 +43,36 @@
 int VBoxDisplayInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
 {
+    OSVERSIONINFO OSinfo;
+    OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
+    GetVersionEx (&OSinfo);
+
     HMODULE hUser = GetModuleHandle("USER32");
 
     gCtx.pEnv = pEnv;
 
-    if (hUser)
+    if (NULL == hUser)
+    {
+        dprintf(("VBoxService: Could not get module handle of USER32.DLL!\n"));
+        return VERR_NOT_IMPLEMENTED; 
+    }
+    else if (OSinfo.dwMajorVersion >= 5)        /* APIs available only on W2K and up! */
     {
         *(uintptr_t *)&gCtx.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA"); 
-        dprintf(("VBoxService: pChangeDisplaySettingsEx = %p\n", gCtx.pfnChangeDisplaySettingsEx));
-    }
+        dprintf(("VBoxService: pfnChangeDisplaySettingsEx = %p\n", gCtx.pfnChangeDisplaySettingsEx));
+
+        *(uintptr_t *)&gCtx.pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA"); 
+        dprintf(("VBoxService: pfnEnumDisplayDevices = %p\n", gCtx.pfnEnumDisplayDevices));
+    }
+    else if (OSinfo.dwMajorVersion <= 4)            /* Windows NT 4.0 */
+    {
+        /* Nothing to do here yet */
+    }
+    else                                /* Unsupported platform */
+    {
+        dprintf(("VBoxService: Warning, display for platform not handled yet!\n"));
+        return VERR_NOT_IMPLEMENTED; 
+    }
+
+    dprintf(("VBoxService: Display init successful.\n"));
 
     *pfStartThread = true;
@@ -59,47 +86,59 @@
 }
 
-static bool isVBoxDisplayDriverActive (void)
+static bool isVBoxDisplayDriverActive (VBOXDISPLAYCONTEXT *pCtx)
 {
     bool result = false;
 
-    DISPLAY_DEVICE dispDevice;
-
-    FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
-
-    dispDevice.cb = sizeof(DISPLAY_DEVICE);
-
-    INT devNum = 0;
-
-    while (EnumDisplayDevices(NULL,
-                              devNum,
-                              &dispDevice,
-                              0))
-    {
-        dprintf(("DevNum:%d\nName:%s\nString:%s\nID:%s\nKey:%s\nFlags=%08X\n\n",
-                      devNum,
-                      &dispDevice.DeviceName[0],
-                      &dispDevice.DeviceString[0],
-                      &dispDevice.DeviceID[0],
-                      &dispDevice.DeviceKey[0],
-                      dispDevice.StateFlags));
-
-        if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
-        {
-            dprintf(("Primary device.\n"));
-
-            if (strcmp(&dispDevice.DeviceString[0], "VirtualBox Graphics Adapter") == 0)
+    if( pCtx->pfnEnumDisplayDevices ) 
+    {
+        INT devNum = 0;
+        DISPLAY_DEVICE dispDevice;
+        FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
+        dispDevice.cb = sizeof(DISPLAY_DEVICE);
+
+        dprintf(("Checking for active VBox display driver (W2K+)...\n"));
+
+        while (EnumDisplayDevices(NULL,
+                                  devNum,
+                                  &dispDevice,
+                                  0))
+        {
+            dprintf(("DevNum:%d\nName:%s\nString:%s\nID:%s\nKey:%s\nFlags=%08X\n\n",
+                          devNum,
+                          &dispDevice.DeviceName[0],
+                          &dispDevice.DeviceString[0],
+                          &dispDevice.DeviceID[0],
+                          &dispDevice.DeviceKey[0],
+                          dispDevice.StateFlags));
+    
+            if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
             {
-                dprintf(("VBox display driver is active.\n"));
-                result = true;
+                dprintf(("Primary device.\n"));
+    
+                if (strcmp(&dispDevice.DeviceString[0], "VirtualBox Graphics Adapter") == 0)
+                    result = true;
+    
+                break;
             }
-
-            break;
-        }
-
-        FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
-
-        dispDevice.cb = sizeof(DISPLAY_DEVICE);
-
-        devNum++;
+    
+            FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
+    
+            dispDevice.cb = sizeof(DISPLAY_DEVICE);
+    
+            devNum++;
+        }
+    }
+    else    /* This must be NT 4 or something really old, so don't use EnumDisplayDevices() here  ... */
+    {       
+        dprintf(("Checking for active VBox display driver (NT or older)...\n"));
+
+        DEVMODE tempDevMode;
+        ZeroMemory (&tempDevMode, sizeof (tempDevMode));
+        tempDevMode.dmSize = sizeof(DEVMODE);
+        EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &tempDevMode);     /* Get current display device settings */
+
+        /* Check for the short name, because all long stuff would be truncated */
+        if (strcmp((char*)&tempDevMode.dmDeviceName[0], "VBoxDisp") == 0)
+            result = true;
     }
 
@@ -272,7 +311,10 @@
             paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
         }
-dprintf(("calling pfnChangeDisplaySettingsEx %x\n", gCtx.pfnChangeDisplaySettingsEx));     
+
+        dprintf(("calling pfnChangeDisplaySettingsEx %x\n", gCtx.pfnChangeDisplaySettingsEx));     
+
         gCtx.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName, 
-                 &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL); 
+                                        &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL); 
+
         dprintf(("ChangeDisplaySettings position err %d\n", GetLastError ()));
     }
@@ -372,8 +414,12 @@
                          * Only try to change video mode if the active display driver is VBox additions.
                          */
-                        if (isVBoxDisplayDriverActive ())
+                        if (isVBoxDisplayDriverActive (pCtx))
                         {
+                            dprintf(("VBoxDisplayThread : Display driver is active!\n"));
+
                             if (pCtx->pfnChangeDisplaySettingsEx != 0)
                             {
+                                dprintf(("VBoxDisplayThread : Detected W2K or later."));
+
                                 /* W2K or later. */
                                 if (!ResizeDisplayDevice(displayChangeRequest.display,
@@ -387,4 +433,6 @@
                             else
                             {
+                                dprintf(("VBoxDisplayThread : Detected NT.\n"));
+
                                 /* Single monitor NT. */
                                 DEVMODE devMode;
@@ -413,4 +461,5 @@
                                     {
                                         /* All zero values means a forced mode reset. Do nothing. */
+                                        dprintf(("VBoxDisplayThread : Forced mode reset.\n"));
                                     }
 
Index: /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.h	(revision 6359)
+++ /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxDisplay.h	(revision 6360)
@@ -23,4 +23,5 @@
 void               VBoxDisplayDestroy (const VBOXSERVICEENV *pEnv, void *pInstance);
 
+static bool isVBoxDisplayDriverActive (void);
 
 #endif /* __VBOXSERVICEDISPLAY__H */
Index: /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxSeamless.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxSeamless.cpp	(revision 6359)
+++ /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxSeamless.cpp	(revision 6360)
@@ -56,4 +56,16 @@
     gCtx.pEnv = pEnv;
 
+    OSVERSIONINFO OSinfo;
+    OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
+    GetVersionEx (&OSinfo);
+
+    /* We have to jump out here when using NT4, otherwise it complains about
+       a missing API function "UnhookWinEvent" used by the dynamically loaded VBoxHook.dll below */
+    if (OSinfo.dwMajorVersion <= 4)         /* Windows NT 4.0 or older */
+    {
+        dprintf(("VBoxSeamlessInit: Windows NT 4.0 or older not supported!"));
+        return VERR_NOT_SUPPORTED;
+    }
+
     /* Will fail if SetWinEventHook is not present (version < NT4 SP6 apparently) */
     gCtx.hModule = LoadLibrary(VBOXHOOK_DLL_NAME);
@@ -72,5 +84,5 @@
                              &vmmreqGuestCaps, sizeof(vmmreqGuestCaps), &cbReturned, NULL))
         {
-            dprintf(("VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError()));
+            dprintf(("VBoxSeamlessInit: VMMDevReq_ReportGuestCapabilities: error doing IOCTL, last error: %d\n", GetLastError()));
             return VERR_INVALID_PARAMETER;
         }
@@ -82,5 +94,5 @@
     else
     {
-        dprintf(("VBoxSeamlessInit LoadLibrary failed with %d\n", GetLastError()));
+        dprintf(("VBoxSeamlessInit: LoadLibrary failed with %d\n", GetLastError()));
         return VERR_INVALID_PARAMETER;
     }
@@ -405,3 +417,2 @@
 }
 
-
Index: /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp	(revision 6359)
+++ /trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp	(revision 6360)
@@ -30,5 +30,4 @@
 
 #include "helpers.h"
-
 #include <sddl.h>
 
@@ -69,4 +68,16 @@
     pReq->header.size += strlen(pReq->szString);
 
+    printf("%s\n", pReq->szString);
+
+    FILE* pFh = fopen("c:\\VBoxServiceDebug.txt", "at");
+
+    /* Does maybe not work on Vista (write protection when starting without admin rights), 
+       so do this check! */
+    if (NULL != pFh)        
+    {
+        fprintf(pFh, "%s", pReq->szString);
+        fclose(pFh);
+    }
+
     DeviceIoControl(gVBoxDriver, IOCTL_VBOXGUEST_VMMREQUEST, pReq, pReq->header.size,
                     pReq, pReq->header.size, &cbReturned, NULL);
@@ -135,4 +146,6 @@
 static int vboxStartServices (VBOXSERVICEENV *pEnv, VBOXSERVICEINFO *pTable)
 {
+    dprintf(("VBoxService: Starting services...\n"));
+
     pEnv->hStopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
 
@@ -262,5 +275,5 @@
     if (gVBoxDriver == INVALID_HANDLE_VALUE)
     {
-        dprintf(("VBoxService: could not open VBox Guest Additions driver! rc = %d\n", GetLastError()));
+        dprintf(("VBoxService: could not open VBox Guest Additions driver! Please install / start it first! rc = %d\n", GetLastError()));
         status = ERROR_GEN_FAILURE;
     }
@@ -315,5 +328,5 @@
         if (gStopSem == NULL)
         {
-            dprintf(("VBoxService: CreateEvent failed: rc = %d\n", GetLastError()));
+            dprintf(("VBoxService: CreateEvent for Stopping failed: rc = %d\n", GetLastError()));
             return;
         }
@@ -377,9 +390,12 @@
         }
 
-        ghSeamlessNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
-        if (ghSeamlessNotifyEvent == NULL)
-        {
-            dprintf(("VBoxService: CreateEvent failed: rc = %d\n", GetLastError()));
-            return;
+        if (dwMajorVersion >= 5)        /* Only for W2K and up ... */
+        {
+            ghSeamlessNotifyEvent = CreateEvent(&SecAttr, FALSE, FALSE, VBOXHOOK_GLOBAL_EVENT_NAME);
+            if (ghSeamlessNotifyEvent == NULL)
+            {
+                dprintf(("VBoxService: CreateEvent for Seamless failed: rc = %d\n", GetLastError()));
+                return;
+            }
         }
     }
@@ -430,17 +446,30 @@
      * Wait for the stop semaphore to be posted or a window event to arrive
      */
+
+    DWORD dwEventCount = 2;
     HANDLE hWaitEvent[2] = {gStopSem, ghSeamlessNotifyEvent};
+
+    if (0 == ghSeamlessNotifyEvent)         /* If seamless mode is not active / supported, reduce event array count */
+        dwEventCount = 1;                       
+
+    dprintf(("VBoxService: Number of events to wait in main loop: %ld\n", dwEventCount));
+
     while(true)
     {
-        DWORD waitResult = MsgWaitForMultipleObjectsEx(2, hWaitEvent, 500, QS_ALLINPUT, 0);
-        if (waitResult == WAIT_OBJECT_0)
-        {
-            dprintf(("VBoxService: exit\n"));
+        DWORD waitResult = MsgWaitForMultipleObjectsEx(dwEventCount, hWaitEvent, 500, QS_ALLINPUT, 0);
+        waitResult = waitResult - WAIT_OBJECT_0;
+
+        dprintf(("VBoxService: Wait result  = %ld.\n", waitResult));
+
+        if (waitResult == 0)
+        {
+            dprintf(("VBoxService: Event 'Exit' triggered.\n"));
             /* exit */
             break;
         }
-        else
-        if (waitResult == WAIT_OBJECT_0+1)
-        {
+        else if ((waitResult == 1) && (ghSeamlessNotifyEvent!=0))       /* Only jump in, if seamless is active! */
+        {
+            dprintf(("VBoxService: Event 'Seamless' triggered.\n"));
+
             /* seamless window notification */
             VBoxSeamlessCheckWindows();
@@ -504,5 +533,6 @@
     dprintf(("VBoxService: WinMain\n"));
     gInstance = hInstance;
-    VBoxServiceStart ();
+    VBoxServiceStart();
+    
     return 0;
 }
@@ -546,3 +576,2 @@
     return 0;
 }
-
