Index: /trunk/src/VBox/Main/src-server/win/HostPowerWin.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/win/HostPowerWin.cpp	(revision 49937)
+++ /trunk/src/VBox/Main/src-server/win/HostPowerWin.cpp	(revision 49938)
@@ -54,6 +54,6 @@
         /* Is this allowed from another thread? */
         SetWindowLongPtr(mHwnd, 0, 0);
-        /* Send the quit message and wait for it be processed. */
-        SendMessage(mHwnd, WM_QUIT, 0, 0);
+        /* Poke the thread out of the event loop and wait for it to clean up. */
+        PostMessage(mHwnd, WM_QUIT, 0, 0);
         RTThreadWait(mThread, 5000, NULL);
         mThread = NIL_RTTHREAD;
@@ -114,8 +114,17 @@
 
             MSG msg;
-            while (GetMessage(&msg, NULL, 0, 0))
+            BOOL fRet;
+            while ((fRet = GetMessage(&msg, NULL, 0, 0)) != 0)
             {
-                TranslateMessage(&msg);
-                DispatchMessage(&msg);
+                if (fRet != -1)
+                {
+                    TranslateMessage(&msg);
+                    DispatchMessage(&msg);
+                }
+                else
+                {
+                    // handle the error and possibly exit
+                    break;
+                }
             }
         }
Index: /trunk/src/VBox/Main/src-server/win/svcmain.cpp
===================================================================
--- /trunk/src/VBox/Main/src-server/win/svcmain.cpp	(revision 49937)
+++ /trunk/src/VBox/Main/src-server/win/svcmain.cpp	(revision 49938)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2004-2012 Oracle Corporation
+ * Copyright (C) 2004-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -57,5 +57,5 @@
 
 const DWORD dwTimeOut = 5000; /* time for EXE to be idle before shutting down */
-const DWORD dwPause = 1000; /* time to wait for threads to finish up */
+const DWORD dwPause = 100; /* time to wait for threads to finish up */
 
 /* Passed to CreateThread to monitor the shutdown event */
Index: /trunk/src/VBox/Runtime/common/log/log.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 49937)
+++ /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 49938)
@@ -293,4 +293,12 @@
     { "user",     sizeof("user"    ) - 1,  RTLOGDEST_USER },
 };
+
+/**
+ * Log rotation backoff table, important on Windows host, especially for
+ * VBoxSVC release logging. Only a medium term solution, until a proper fix
+ * for log file handling is available. 10 seconds total.
+ */
+static const uint32_t s_aLogBackoff[] =
+{ 10, 10, 10, 20, 50, 100, 200, 200, 200, 200, 500, 500, 500, 500, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };
 
 
@@ -2610,5 +2618,5 @@
 static int rtlogFileOpen(PRTLOGGER pLogger, char *pszErrorMsg, size_t cchErrorMsg)
 {
-    uint32_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_WRITE;
+    uint32_t fOpen = RTFILE_O_WRITE | RTFILE_O_DENY_NONE;
     if (pLogger->fFlags & RTLOGFLAGS_APPEND)
         fOpen |= RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND;
@@ -2618,5 +2626,18 @@
         fOpen |= RTFILE_O_WRITE_THROUGH;
 
-    int rc = RTFileOpen(&pLogger->pInt->hFile, pLogger->pInt->szFilename, fOpen);
+    int rc;
+    int cBackoff = 0;
+    do
+    {
+        rc = RTFileOpen(&pLogger->pInt->hFile, pLogger->pInt->szFilename, fOpen);
+        if (rc == VERR_SHARING_VIOLATION)
+        {
+            if (cBackoff >= RT_ELEMENTS(s_aLogBackoff))
+                break;
+            RTThreadSleep(s_aLogBackoff[cBackoff]);
+            cBackoff++;
+        }
+    }
+    while (rc == VERR_SHARING_VIOLATION);
     if (RT_FAILURE(rc))
     {
@@ -2710,6 +2731,22 @@
             char szNewName[sizeof(pLogger->pInt->szFilename) + 32];
             RTStrPrintf(szNewName, sizeof(szNewName), "%s.%u", pLogger->pInt->szFilename, i + 1);
-            if (   RTFileRename(szOldName, szNewName, RTFILEMOVE_FLAGS_REPLACE)
-                == VERR_FILE_NOT_FOUND)
+
+
+
+            int rc;
+            int cBackoff = 0;
+            do
+            {
+	        rc = RTFileRename(szOldName, szNewName, RTFILEMOVE_FLAGS_REPLACE);
+                if (rc == VERR_SHARING_VIOLATION)
+                {
+                    if (cBackoff >= RT_ELEMENTS(s_aLogBackoff))
+                        break;
+                    RTThreadSleep(s_aLogBackoff[cBackoff]);
+                    cBackoff++;
+                }
+            }
+            while (rc == VERR_SHARING_VIOLATION);
+            if (rc == VERR_FILE_NOT_FOUND)
                 RTFileDelete(szNewName);
         }
