Index: trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
===================================================================
--- trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp	(revision 47973)
+++ trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp	(revision 47977)
@@ -814,4 +814,5 @@
     AssertPtrReturn(pCache, VERR_INVALID_POINTER);
     AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
+    /* pszDomain is optional. */
 
     int rc = VINF_SUCCESS;
@@ -821,4 +822,7 @@
                     VBOXTRAY_IPC_PIPE_PREFIX, pszUser))
     {
+        bool fReportToHost = false;
+        VBoxGuestUserState userState = VBoxGuestUserState_Unknown;
+
         RTLOCALIPCSESSION hSession;
         rc = RTLocalIpcSessionConnect(&hSession, szPipeName, 0 /* Flags */);
@@ -839,7 +843,7 @@
                 && ipcRes.uLastInput != UINT32_MAX)
             {
-                VBoxGuestUserState userState = (ipcRes.uLastInput * 1000) < g_uVMInfoUserIdleThresholdMS
-                                             ? VBoxGuestUserState_InUse
-                                             : VBoxGuestUserState_Idle;
+                userState = (ipcRes.uLastInput * 1000) < g_uVMInfoUserIdleThresholdMS
+                          ? VBoxGuestUserState_InUse
+                          : VBoxGuestUserState_Idle;
 
                 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "UsageState",
@@ -852,8 +856,7 @@
                  *       new.
                  */
-                if (rc == VINF_SUCCESS)
-                {
-                    VBoxServiceVerbose(4, "User \"%s\" (domain \"%s\") is idle for %RU32s\n",
-                                       pszUser, pszDomain ? pszDomain : "<None>", ipcRes.uLastInput);
+                fReportToHost = rc == VINF_SUCCESS;
+                VBoxServiceVerbose(4, "User \"%s\" (domain \"%s\") is idle for %RU32, fReportToHost=%RTbool\n",
+                                   pszUser, pszDomain ? pszDomain : "<None>", ipcRes.uLastInput, fReportToHost);
 
 #if 0 /* Do we want to write the idle time as well? */
@@ -868,11 +871,8 @@
                     if (RT_SUCCESS(rc))
 #endif
-                        rc = VbglR3GuestUserReportState(pszUser, pszDomain, userState,
-                                                        NULL /* No details */, 0);
-                }
             }
 #ifdef DEBUG
             else if (ipcRes.uLastInput == UINT32_MAX)
-                VBoxServiceVerbose(4, "Last input for user \"%s\" is not available, skipping\n",
+                VBoxServiceVerbose(4, "Last input for user \"%s\" is not supported, skipping\n",
                                    pszUser, rc);
 
@@ -889,17 +889,38 @@
             {
                 case VERR_FILE_NOT_FOUND:
+                {
                     /* No VBoxTray (or too old version which does not support IPC) running
                        for the given user. Not much we can do then. */
-                    VBoxServiceVerbose(4, "User \"%s\" not logged in, no last input available\n",
+                    VBoxServiceVerbose(4, "VBoxTray for user \"%s\" not running (anymore), no last input available\n",
                                        pszUser);
+
+                    /* Overwrite rc from above. */
+                    rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain,
+                                                "UsageState", "Idle");
+
+                    fReportToHost = rc == VINF_SUCCESS;
+                    if (fReportToHost)
+                        userState = VBoxGuestUserState_Idle;
                     break;
+                }
 
                 default:
-                    VBoxServiceVerbose(4, "Error querying last input for user \"%s\", rc=%Rrc\n",
-                                       pszUser, rc);
+                    VBoxServiceError("Error querying last input for user \"%s\", rc=%Rrc\n",
+                                     pszUser, rc);
                     break;
             }
-
-            rc = VINF_SUCCESS;
+        }
+
+        if (fReportToHost)
+        {
+            Assert(userState != VBoxGuestUserState_Unknown);
+            int rc2 = VbglR3GuestUserReportState(pszUser, pszDomain, userState,
+                                                 NULL /* No details */, 0);
+            if (RT_FAILURE(rc2))
+                VBoxServiceError("Error reporting usage state %ld for user \"%s\" to host, rc=%Rrc\n",
+                                 userState, pszUser, rc2);
+
+            if (RT_SUCCESS(rc))
+                rc = rc2;
         }
     }
