Index: trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp	(revision 99108)
+++ trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp	(revision 99109)
@@ -216,5 +216,5 @@
 static int rtProcPosixCreateInner(const char *pszExec, const char * const *papszArgs, RTENV hEnv, RTENV hEnvToUse,
                                   uint32_t fFlags, const char *pszAsUser, uid_t uid, gid_t gid,
-                                  unsigned cRedirFds, int *paRedirFds, PRTPROCESS phProcess);
+                                  unsigned cRedirFds, int *paRedirFds, void *pvExtraData, PRTPROCESS phProcess);
 
 
@@ -1200,5 +1200,5 @@
                 RTPROCESS hProcess = NIL_RTPROCESS;
                 rc = rtProcPosixCreateInner(pszExec, apszArgs, hEnvToUse, hEnvToUse, 0 /*fFlags*/,
-                                            pszAsUser, uid, gid, RT_ELEMENTS(aRedirFds), aRedirFds, &hProcess);
+                                            pszAsUser, uid, gid, RT_ELEMENTS(aRedirFds), aRedirFds, NULL /*pvExtraData*/, &hProcess);
                 if (RT_SUCCESS(rc))
                 {
@@ -1713,5 +1713,8 @@
         return VERR_PROC_DETACH_NOT_SUPPORTED;
 #endif
-    AssertReturn(pvExtraData == NULL || (fFlags & RTPROC_FLAGS_DESIRED_SESSION_ID), VERR_INVALID_PARAMETER);
+    AssertReturn(pvExtraData == NULL || (fFlags & (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_CWD)),
+                 VERR_INVALID_PARAMETER);
+    AssertReturn((fFlags & (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_CWD)) != (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_CWD),
+                 VERR_INVALID_PARAMETER);
 
     /*
@@ -1895,5 +1898,5 @@
                  */
                 rc = rtProcPosixCreateInner(pszNativeExec, papszArgsConverted, hEnv, hEnvToUse, fFlags, pszAsUser, uid, gid,
-                                            RT_ELEMENTS(aStdFds), aStdFds, phProcess);
+                                            RT_ELEMENTS(aStdFds), aStdFds, pvExtraData, phProcess);
 
             }
@@ -1940,5 +1943,5 @@
 static int rtProcPosixCreateInner(const char *pszNativeExec, const char * const *papszArgs, RTENV hEnv, RTENV hEnvToUse,
                                   uint32_t fFlags, const char *pszAsUser, uid_t uid, gid_t gid,
-                                  unsigned cRedirFds, int *paRedirFds, PRTPROCESS phProcess)
+                                  unsigned cRedirFds, int *paRedirFds, void *pvExtraData, PRTPROCESS phProcess)
 {
     /*
@@ -2037,5 +2040,6 @@
     /** @todo OS/2: implement DETACHED (BACKGROUND stuff), see VbglR3Daemonize.  */
     if (   uid == ~(uid_t)0
-        && gid == ~(gid_t)0)
+        && gid == ~(gid_t)0
+        && !(fFlags & RTPROC_FLAGS_CWD))
     {
         /* Spawn attributes. */
@@ -2187,4 +2191,20 @@
             }
 #endif
+            if (fFlags & RTPROC_FLAGS_CWD)
+            {
+                const char *pszCwd = (const char *)pvExtraData;
+                if (pszCwd && *pszCwd)
+                {
+                    rc = RTPathSetCurrent(pszCwd);
+                    if (RT_FAILURE(rc))
+                    {
+                        /** @todo r=bela What is the right exit code here?? */
+                        if (fFlags & RTPROC_FLAGS_DETACHED)
+                            _Exit(126);
+                        else
+                            /*exit*/_Exit(126);
+                    }
+                }
+            }
 
             /*
Index: trunk/src/VBox/Runtime/r3/win/process-win.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 99108)
+++ trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 99109)
@@ -1613,5 +1613,5 @@
                                   STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
                                   uint32_t fFlags, const char *pszExec, uint32_t idDesiredSession,
-                                  HANDLE hUserToken)
+                                  HANDLE hUserToken, PRTUTF16 pwszCwd)
 {
     /*
@@ -1804,5 +1804,5 @@
                                                                      *        on XP and up. */
                                                                     pwszzBlock,   /* lpEnvironment */
-                                                                    NULL,         /* pCurrentDirectory */
+                                                                    pwszCwd,       /* pCurrentDirectory */
                                                                     pStartupInfo,
                                                                     pProcInfo);
@@ -1942,5 +1942,5 @@
                                   RTENV hEnv, DWORD dwCreationFlags,
                                   STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
-                                  uint32_t fFlags, const char *pszExec)
+                                  uint32_t fFlags, const char *pszExec, PRTUTF16 pwszCwd)
 {
     /* The CreateProcessWithLogonW API was introduced with W2K and later.  It uses a service
@@ -2042,5 +2042,5 @@
                                                 dwCreationFlags | (fCreatedSuspended ? CREATE_SUSPENDED : 0),
                                                 pwszzBlock,
-                                                NULL,                       /* pCurrentDirectory */
+                                                pwszCwd,                     /* pCurrentDirectory */
                                                 pStartupInfo,
                                                 pProcInfo);
@@ -2093,5 +2093,5 @@
                                  STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
                                  uint32_t fFlags, const char *pszExec, uint32_t idDesiredSession,
-                                 HANDLE hUserToken)
+                                 HANDLE hUserToken, PRTUTF16 pwszCwd)
 {
     /*
@@ -2105,10 +2105,10 @@
         AssertPtr(pwszUser);
         int rc = rtProcWinCreateAsUser1(pwszUser, pwszPassword, ppwszExec, pwszCmdLine,
-                                        hEnv, dwCreationFlags, pStartupInfo, pProcInfo, fFlags, pszExec);
+                                        hEnv, dwCreationFlags, pStartupInfo, pProcInfo, fFlags, pszExec, pwszCwd);
         if (RT_SUCCESS(rc))
             return rc;
     }
     return rtProcWinCreateAsUser2(pwszUser, pwszPassword, ppwszExec, pwszCmdLine, hEnv, dwCreationFlags,
-                                  pStartupInfo, pProcInfo, fFlags, pszExec, idDesiredSession, hUserToken);
+                                  pStartupInfo, pProcInfo, fFlags, pszExec, idDesiredSession, hUserToken, pwszCwd);
 }
 
@@ -2262,4 +2262,6 @@
                                const char *pszPassword, void *pvExtraData, PRTPROCESS phProcess)
 {
+    int rc;
+
     /*
      * Input validation
@@ -2281,4 +2283,5 @@
         ==           (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_SERVICE))
     {
+        AssertReturn(!(fFlags & RTPROC_FLAGS_CWD), VERR_INVALID_PARAMETER);
         AssertPtrReturn(pvExtraData, VERR_INVALID_POINTER);
         idDesiredSession = *(uint32_t *)pvExtraData;
@@ -2294,5 +2297,5 @@
      * Initialize the globals.
      */
-    int rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL);
+    rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL);
     AssertRCReturn(rc, rc);
     if (   pszAsUser
@@ -2433,10 +2436,12 @@
                                        !(fFlags & RTPROC_FLAGS_UNQUOTED_ARGS)
                                        ? RTGETOPTARGV_CNV_QUOTE_MS_CRT : RTGETOPTARGV_CNV_UNQUOTED);
+    PRTUTF16 pwszExec = NULL;
     if (RT_SUCCESS(rc))
-    {
-        PRTUTF16 pwszExec;
         rc = RTPathWinFromUtf8(&pwszExec, pszExec, 0 /*fFlags*/);
-        if (RT_SUCCESS(rc))
-        {
+    PRTUTF16 pwszCwd = NULL;
+    if (RT_SUCCESS(rc) && (fFlags & RTPROC_FLAGS_CWD))
+        rc = RTPathWinFromUtf8(&pwszCwd, (const char *)pvExtraData, 0);
+    if (RT_SUCCESS(rc))
+    {
             /*
              * Get going...
@@ -2470,5 +2475,5 @@
                                        dwCreationFlags,
                                        pwszzBlock,
-                                       NULL,         /* pCurrentDirectory */
+                                       pwszCwd,       /* pCurrentDirectory */
                                        &StartupInfo,
                                        &ProcInfo))
@@ -2496,5 +2501,5 @@
                         rc = rtProcWinCreateAsUser(pwszUser, pwszPassword, &pwszExec, pwszCmdLine, hEnv, dwCreationFlags,
                                                    &StartupInfo, &ProcInfo, fFlags, pszExec, idDesiredSession,
-                                                   hUserToken);
+                                                   hUserToken, pwszCwd);
 
                         if (pwszPassword && *pwszPassword)
@@ -2524,8 +2529,8 @@
                 rc = VINF_SUCCESS;
             }
-            RTPathWinFree(pwszExec);
-        }
-        RTUtf16Free(pwszCmdLine);
-    }
+    }
+    RTPathWinFree(pwszExec);
+    RTPathWinFree(pwszCwd);
+    RTUtf16Free(pwszCmdLine);
 
     if (g_pfnSetHandleInformation)
