VirtualBox

Ignore:
Timestamp:
Mar 22, 2023 10:13:00 AM (23 months ago)
Author:
vboxsync
Message:

IPRT/process: Added RTPROC_FLAGS_CWD to RTProcCreateEx(), to be able to set the current working directory for created processes. bugref:8053

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/process-win.cpp

    r98103 r99109  
    16131613                                  STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
    16141614                                  uint32_t fFlags, const char *pszExec, uint32_t idDesiredSession,
    1615                                   HANDLE hUserToken)
     1615                                  HANDLE hUserToken, PRTUTF16 pwszCwd)
    16161616{
    16171617    /*
     
    18041804                                                                     *        on XP and up. */
    18051805                                                                    pwszzBlock,   /* lpEnvironment */
    1806                                                                     NULL,         /* pCurrentDirectory */
     1806                                                                    pwszCwd,       /* pCurrentDirectory */
    18071807                                                                    pStartupInfo,
    18081808                                                                    pProcInfo);
     
    19421942                                  RTENV hEnv, DWORD dwCreationFlags,
    19431943                                  STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
    1944                                   uint32_t fFlags, const char *pszExec)
     1944                                  uint32_t fFlags, const char *pszExec, PRTUTF16 pwszCwd)
    19451945{
    19461946    /* The CreateProcessWithLogonW API was introduced with W2K and later.  It uses a service
     
    20422042                                                dwCreationFlags | (fCreatedSuspended ? CREATE_SUSPENDED : 0),
    20432043                                                pwszzBlock,
    2044                                                 NULL,                       /* pCurrentDirectory */
     2044                                                pwszCwd,                     /* pCurrentDirectory */
    20452045                                                pStartupInfo,
    20462046                                                pProcInfo);
     
    20932093                                 STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo,
    20942094                                 uint32_t fFlags, const char *pszExec, uint32_t idDesiredSession,
    2095                                  HANDLE hUserToken)
     2095                                 HANDLE hUserToken, PRTUTF16 pwszCwd)
    20962096{
    20972097    /*
     
    21052105        AssertPtr(pwszUser);
    21062106        int rc = rtProcWinCreateAsUser1(pwszUser, pwszPassword, ppwszExec, pwszCmdLine,
    2107                                         hEnv, dwCreationFlags, pStartupInfo, pProcInfo, fFlags, pszExec);
     2107                                        hEnv, dwCreationFlags, pStartupInfo, pProcInfo, fFlags, pszExec, pwszCwd);
    21082108        if (RT_SUCCESS(rc))
    21092109            return rc;
    21102110    }
    21112111    return rtProcWinCreateAsUser2(pwszUser, pwszPassword, ppwszExec, pwszCmdLine, hEnv, dwCreationFlags,
    2112                                   pStartupInfo, pProcInfo, fFlags, pszExec, idDesiredSession, hUserToken);
     2112                                  pStartupInfo, pProcInfo, fFlags, pszExec, idDesiredSession, hUserToken, pwszCwd);
    21132113}
    21142114
     
    22622262                               const char *pszPassword, void *pvExtraData, PRTPROCESS phProcess)
    22632263{
     2264    int rc;
     2265
    22642266    /*
    22652267     * Input validation
     
    22812283        ==           (RTPROC_FLAGS_DESIRED_SESSION_ID | RTPROC_FLAGS_SERVICE))
    22822284    {
     2285        AssertReturn(!(fFlags & RTPROC_FLAGS_CWD), VERR_INVALID_PARAMETER);
    22832286        AssertPtrReturn(pvExtraData, VERR_INVALID_POINTER);
    22842287        idDesiredSession = *(uint32_t *)pvExtraData;
     
    22942297     * Initialize the globals.
    22952298     */
    2296     int rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL);
     2299    rc = RTOnce(&g_rtProcWinInitOnce, rtProcWinInitOnce, NULL);
    22972300    AssertRCReturn(rc, rc);
    22982301    if (   pszAsUser
     
    24332436                                       !(fFlags & RTPROC_FLAGS_UNQUOTED_ARGS)
    24342437                                       ? RTGETOPTARGV_CNV_QUOTE_MS_CRT : RTGETOPTARGV_CNV_UNQUOTED);
     2438    PRTUTF16 pwszExec = NULL;
    24352439    if (RT_SUCCESS(rc))
    2436     {
    2437         PRTUTF16 pwszExec;
    24382440        rc = RTPathWinFromUtf8(&pwszExec, pszExec, 0 /*fFlags*/);
    2439         if (RT_SUCCESS(rc))
    2440         {
     2441    PRTUTF16 pwszCwd = NULL;
     2442    if (RT_SUCCESS(rc) && (fFlags & RTPROC_FLAGS_CWD))
     2443        rc = RTPathWinFromUtf8(&pwszCwd, (const char *)pvExtraData, 0);
     2444    if (RT_SUCCESS(rc))
     2445    {
    24412446            /*
    24422447             * Get going...
     
    24702475                                       dwCreationFlags,
    24712476                                       pwszzBlock,
    2472                                        NULL,         /* pCurrentDirectory */
     2477                                       pwszCwd,       /* pCurrentDirectory */
    24732478                                       &StartupInfo,
    24742479                                       &ProcInfo))
     
    24962501                        rc = rtProcWinCreateAsUser(pwszUser, pwszPassword, &pwszExec, pwszCmdLine, hEnv, dwCreationFlags,
    24972502                                                   &StartupInfo, &ProcInfo, fFlags, pszExec, idDesiredSession,
    2498                                                    hUserToken);
     2503                                                   hUserToken, pwszCwd);
    24992504
    25002505                        if (pwszPassword && *pwszPassword)
     
    25242529                rc = VINF_SUCCESS;
    25252530            }
    2526             RTPathWinFree(pwszExec);
    2527         }
    2528         RTUtf16Free(pwszCmdLine);
    2529     }
     2531    }
     2532    RTPathWinFree(pwszExec);
     2533    RTPathWinFree(pwszCwd);
     2534    RTUtf16Free(pwszCmdLine);
    25302535
    25312536    if (g_pfnSetHandleInformation)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette