Index: trunk/src/VBox/Runtime/r3/win/process-win.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 39865)
+++ trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 39866)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2010 Oracle Corporation
+ * Copyright (C) 2006-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -52,4 +52,5 @@
 #include <iprt/mem.h>
 #include <iprt/once.h>
+#include <iprt/path.h>
 #include <iprt/pipe.h>
 #include <iprt/string.h>
@@ -264,5 +265,5 @@
 
 
-RTR3DECL(int)   RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess)
+RTR3DECL(int) RTProcCreate(const char *pszExec, const char * const *papszArgs, RTENV Env, unsigned fFlags, PRTPROCESS pProcess)
 {
     return RTProcCreateEx(pszExec, papszArgs, Env, fFlags,
@@ -280,5 +281,5 @@
  * @param   dwError                         Windows error code to map to IPRT code.
  */
-static int rtProcMapErrorCodes(DWORD dwError)
+static int rtProcWinMapErrorCodes(DWORD dwError)
 {
     int rc;
@@ -306,91 +307,91 @@
 
 /**
- * Get the process token (not the process handle like the name might indicate)
- * of the process indicated by @a dwPID if the @a pSID matches.
+ * Get the process token of the process indicated by @a dwPID if the @a pSid
+ * matches.
  *
  * @returns IPRT status code.
  *
- * @param   dwPID           The process identifier.
- * @param   pSID            The secure identifier of the user.
- * @param   phToken         Where to return the token handle - duplicate,
- *                          caller closes it on success.
- */
-static int rtProcGetProcessHandle(DWORD dwPID, PSID pSID, PHANDLE phToken)
-{
-    AssertPtr(pSID);
+ * @param   dwPid           The process identifier.
+ * @param   pSid            The secure identifier of the user.
+ * @param   phToken         Where to return the a duplicate of the process token
+ *                          handle on success. (The caller closes it.)
+ */
+static int rtProcWinGetProcessTokenHandle(DWORD dwPid, PSID pSid, PHANDLE phToken)
+{
+    AssertPtr(pSid);
     AssertPtr(phToken);
 
-    DWORD dwErr;
-    BOOL fRc;
-    bool fFound = false;
-    HANDLE hProc = OpenProcess(MAXIMUM_ALLOWED, TRUE, dwPID);
+    int     rc;
+    HANDLE  hProc = OpenProcess(MAXIMUM_ALLOWED, TRUE, dwPid);
     if (hProc != NULL)
     {
         HANDLE hTokenProc;
-        fRc = OpenProcessToken(hProc,
-                               TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_DUPLICATE
-                               | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_SESSIONID | TOKEN_READ | TOKEN_WRITE,
-                               &hTokenProc);
-        if (fRc)
-        {
-            DWORD dwSize = 0;
-            fRc = GetTokenInformation(hTokenProc, TokenUser, NULL, 0, &dwSize);
-            if (!fRc)
-                dwErr = GetLastError();
+        if (OpenProcessToken(hProc,
+                             TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_DUPLICATE
+                             | TOKEN_ASSIGN_PRIMARY | TOKEN_ADJUST_SESSIONID | TOKEN_READ | TOKEN_WRITE,
+                             &hTokenProc))
+        {
+            SetLastError(NO_ERROR);
+            DWORD   dwSize = 0;
+            BOOL    fRc    = GetTokenInformation(hTokenProc, TokenUser, NULL, 0, &dwSize);
+            DWORD   dwErr  = GetLastError();
             if (   !fRc
                 && dwErr == ERROR_INSUFFICIENT_BUFFER
                 && dwSize > 0)
             {
-                PTOKEN_USER pTokenUser = (PTOKEN_USER)RTMemAlloc(dwSize);
-                AssertPtrReturn(pTokenUser, VERR_NO_MEMORY); /** @todo r=bird: Leaking handles when we're out of memory...  */
-                RT_ZERO(*pTokenUser);
-                if (   GetTokenInformation(hTokenProc,
-                                           TokenUser,
-                                           (LPVOID)pTokenUser,
-                                           dwSize,
-                                           &dwSize))
+                PTOKEN_USER pTokenUser = (PTOKEN_USER)RTMemTmpAllocZ(dwSize);
+                if (pTokenUser)
                 {
-                    if (   IsValidSid(pTokenUser->User.Sid)
-                        && EqualSid(pTokenUser->User.Sid, pSID))
+                    if (GetTokenInformation(hTokenProc,
+                                            TokenUser,
+                                            pTokenUser,
+                                            dwSize,
+                                            &dwSize))
                     {
-                        if (DuplicateTokenEx(hTokenProc, MAXIMUM_ALLOWED,
-                                             NULL, SecurityIdentification, TokenPrimary, phToken))
+                        if (   IsValidSid(pTokenUser->User.Sid)
+                            && EqualSid(pTokenUser->User.Sid, pSid))
                         {
-                            /*
-                             * So we found the process instance which belongs to the user we want to
-                             * to run our new process under. This duplicated token will be used for
-                             * the actual CreateProcessAsUserW() call then.
-                             */
-                            fFound = true;
+                            if (DuplicateTokenEx(hTokenProc, MAXIMUM_ALLOWED,
+                                                 NULL, SecurityIdentification, TokenPrimary, phToken))
+                            {
+                                /*
+                                 * So we found the process instance which belongs to the user we want to
+                                 * to run our new process under. This duplicated token will be used for
+                                 * the actual CreateProcessAsUserW() call then.
+                                 */
+                                rc = VINF_SUCCESS;
+                            }
+                            else
+                                rc = rtProcWinMapErrorCodes(GetLastError());
                         }
                         else
-                            dwErr = GetLastError();
+                            rc = VERR_NOT_FOUND;
                     }
+                    else
+                        rc = rtProcWinMapErrorCodes(GetLastError());
+                    RTMemTmpFree(pTokenUser);
                 }
                 else
-                    dwErr = GetLastError();
-                RTMemFree(pTokenUser);
+                    rc = VERR_NO_MEMORY;
             }
+            else if (fRc || dwErr == NO_ERROR)
+                rc = VERR_IPE_UNEXPECTED_STATUS;
             else
-                dwErr = GetLastError();
+                rc = rtProcWinMapErrorCodes(dwErr);
             CloseHandle(hTokenProc);
         }
         else
-            dwErr = GetLastError();
+            rc = rtProcWinMapErrorCodes(GetLastError());
         CloseHandle(hProc);
     }
     else
-        dwErr = GetLastError();
-    if (fFound)
-        return VINF_SUCCESS;
-    if (dwErr != NO_ERROR)
-        return RTErrConvertFromWin32(dwErr);
-    return VERR_NOT_FOUND; /* No error occurred, but we didn't find the right process. */
-}
-
-
-/**
- * Finds a one of the processes in @a papszNames running with user @a pSID and
- * returns a duplicate handle to its token.
+        rc = rtProcWinMapErrorCodes(GetLastError());
+    return rc;
+}
+
+
+/**
+ * Fallback method for rtProcWinFindTokenByProcess that uses the older NT4
+ * PSAPI.DLL API.
  *
  * @returns Success indicator.
@@ -399,6 +400,102 @@
  * @param   phToken         Where to return the token handle - duplicate,
  *                          caller closes it on success.
- */
-static bool rtProcFindProcessByName(const char * const *papszNames, PSID pSid, PHANDLE phToken)
+ *
+ * @remarks NT4 needs a copy of "PSAPI.dll" (redistributed by Microsoft and not
+ *          part of the OS) in order to get a lookup.  If we don't have this DLL
+ *          we are not able to get a token and therefore no UI will be visible.
+ */
+static bool rtProcWinFindTokenByProcessAndPsApi(const char * const *papszNames, PSID pSid, PHANDLE phToken)
+{
+    bool fFound = false;
+
+    /*
+     * Load PSAPI.DLL and resolve the two symbols we need.
+     */
+    RTLDRMOD hPsApi;
+    int rc = RTLdrLoad("PSAPI.dll", &hPsApi);
+    if (RT_FAILURE_NP(rc))
+        return false;
+    PFNGETMODULEBASENAME    pfnGetModuleBaseName;
+    PFNENUMPROCESSES        pfnEnumProcesses;
+    rc = RTLdrGetSymbol(hPsApi, "EnumProcesses", (void**)&pfnEnumProcesses);
+    if (RT_SUCCESS(rc))
+        rc = RTLdrGetSymbol(hPsApi, "GetModuleBaseName", (void**)&pfnGetModuleBaseName);
+    if (RT_SUCCESS(rc))
+    {
+        /*
+         * Get a list of PID.  We retry if it looks like there are more PIDs
+         * to be returned than what we supplied buffer space for.
+         */
+        DWORD  cbPidsAllocated = 4096;
+        DWORD  cbPidsReturned  = 0;
+        DWORD *paPids;
+        for (;;)
+        {
+            paPids = (DWORD *)RTMemTmpAlloc(cbPidsAllocated);
+            AssertBreakStmt(paPids, rc = VERR_NO_TMP_MEMORY);
+            if (!pfnEnumProcesses(paPids, cbPidsAllocated, &cbPidsReturned))
+            {
+                rc = RTErrConvertFromWin32(GetLastError());
+                AssertMsgFailedBreak(("%Rrc\n", rc));
+            }
+            if (   cbPidsReturned < cbPidsAllocated
+                || cbPidsAllocated >= _512K)
+                break;
+            RTMemTmpFree(paPids);
+            cbPidsAllocated *= 2;
+        }
+        if (RT_SUCCESS(rc))
+        {
+            /*
+             * Search for the process.
+             *
+             * We ASSUME that the caller won't be specifying any names longer
+             * than RTPATH_MAX.
+             */
+            DWORD cbProcName  = RTPATH_MAX;
+            char *pszProcName = (char *)RTMemTmpAlloc(RTPATH_MAX);
+            if (pszProcName)
+            {
+                for (size_t i = 0; papszNames[i] && !fFound; i++)
+                {
+                    const DWORD cPids = cbPidsReturned / sizeof(DWORD);
+                    for (DWORD iPid = 0; iPid < cPids && !fFound; iPid++)
+                    {
+                        HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, paPids[iPid]);
+                        if (hProc)
+                        {
+                            *pszProcName = '\0';
+                            DWORD cbRet = pfnGetModuleBaseName(hProc, 0 /*hModule = exe */, pszProcName, cbProcName);
+                            if (   cbRet > 0
+                                && _stricmp(pszProcName, papszNames[i]) == 0
+                                && RT_SUCCESS(rtProcWinGetProcessTokenHandle(paPids[iPid], pSid, phToken)))
+                                fFound = true;
+                            CloseHandle(hProc);
+                        }
+                    }
+                }
+                RTMemTmpFree(pszProcName);
+            }
+            else
+                rc = VERR_NO_TMP_MEMORY;
+        }
+        RTMemTmpFree(paPids);
+    }
+    RTLdrClose(hPsApi);
+    return fFound;
+}
+
+
+/**
+ * Finds a one of the processes in @a papszNames running with user @a pSid and
+ * returns a duplicate handle to its token.
+ *
+ * @returns Success indicator.
+ * @param   papszNames      The process candidates, in prioritized order.
+ * @param   pSid            The secure identifier of the user.
+ * @param   phToken         Where to return the token handle - duplicate,
+ *                          caller closes it on success.
+ */
+static bool rtProcWinFindTokenByProcess(const char * const *papszNames, PSID pSid, PHANDLE phToken)
 {
     AssertPtr(papszNames);
@@ -406,10 +503,9 @@
     AssertPtr(phToken);
 
-    DWORD dwErr = NO_ERROR;
     bool fFound = false;
 
     /*
      * On modern systems (W2K+) try the Toolhelp32 API first; this is more stable
-     * and reliable. Fallback to EnumProcess on NT4.
+     * and reliable.  Fallback to EnumProcess on NT4.
      */
     RTLDRMOD hKernel32;
@@ -418,114 +514,53 @@
     {
         PFNCREATETOOLHELP32SNAPSHOT pfnCreateToolhelp32Snapshot;
-        rc = RTLdrGetSymbol(hKernel32, "CreateToolhelp32Snapshot", (void**)&pfnCreateToolhelp32Snapshot);
+        PFNPROCESS32FIRST           pfnProcess32First;
+        PFNPROCESS32NEXT            pfnProcess32Next;
+        rc = RTLdrGetSymbol(hKernel32, "CreateToolhelp32Snapshot", (void **)&pfnCreateToolhelp32Snapshot);
         if (RT_SUCCESS(rc))
-        {
-            PFNPROCESS32FIRST pfnProcess32First;
             rc = RTLdrGetSymbol(hKernel32, "Process32First", (void**)&pfnProcess32First);
-            if (RT_SUCCESS(rc))
-            {
-                PFNPROCESS32NEXT pfnProcess32Next;
-                rc = RTLdrGetSymbol(hKernel32, "Process32Next", (void**)&pfnProcess32Next);
-                if (RT_SUCCESS(rc))
+        if (RT_SUCCESS(rc))
+            rc = RTLdrGetSymbol(hKernel32, "Process32Next", (void**)&pfnProcess32Next);
+
+        if (RT_SUCCESS(rc))
+        {
+            HANDLE hSnap = pfnCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+            if (hSnap != INVALID_HANDLE_VALUE)
+            {
+                for (size_t i = 0; papszNames[i] && !fFound; i++)
                 {
-                    HANDLE hSnap = pfnCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
-                    if (hSnap != INVALID_HANDLE_VALUE)
+                    PROCESSENTRY32 procEntry;
+                    procEntry.dwSize = sizeof(PROCESSENTRY32);
+                    if (pfnProcess32First(hSnap, &procEntry))
                     {
-                        for (size_t i = 0; papszNames[i] && !fFound; i++)
+                        do
                         {
-                            PROCESSENTRY32 procEntry;
-                            procEntry.dwSize = sizeof(PROCESSENTRY32);
-                            if (pfnProcess32First(hSnap, &procEntry))
+                            if (   _stricmp(procEntry.szExeFile, papszNames[i]) == 0
+                                && RT_SUCCESS(rtProcWinGetProcessTokenHandle(procEntry.th32ProcessID, pSid, phToken)))
                             {
-                                do
-                                {
-                                    if (   _stricmp(procEntry.szExeFile, papszNames[i]) == 0
-                                        && RT_SUCCESS(rtProcGetProcessHandle(procEntry.th32ProcessID, pSid, phToken)))
-                                    {
-                                        fFound = true;
-                                        break;
-                                    }
-                                } while (pfnProcess32Next(hSnap, &procEntry));
+                                fFound = true;
+                                break;
                             }
-                            else /* Process32First */
-                                dwErr = GetLastError();
-                            if (FAILED(dwErr))
-                                break;
-                        }
-                        CloseHandle(hSnap);
+                        } while (pfnProcess32Next(hSnap, &procEntry));
                     }
-                    else /* hSnap == INVALID_HANDLE_VALUE */
-                        dwErr = GetLastError();
+#ifdef RT_STRICT
+                    else
+                    {
+                        DWORD dwErr = GetLastError();
+                        AssertMsgFailed(("dwErr=%u (%x)\n", dwErr, dwErr));
+                    }
+#endif
                 }
+                CloseHandle(hSnap);
             }
-        }
-        else /* CreateToolhelp32Snapshot / Toolhelp32 API not available. */
-        {
-            /*
-             * NT4 needs a copy of "PSAPI.dll" (redistributed by Microsoft and not
-             * part of the OS) in order to get a lookup. If we don't have this DLL
-             * we are not able to get a token and therefore no UI will be visible.
-             */
-            RTLDRMOD hPSAPI;
-            int rc = RTLdrLoad("PSAPI.dll", &hPSAPI);
-            if (RT_SUCCESS(rc))
-            {
-                PFNENUMPROCESSES pfnEnumProcesses;
-                rc = RTLdrGetSymbol(hPSAPI, "EnumProcesses", (void**)&pfnEnumProcesses);
-                if (RT_SUCCESS(rc))
-                {
-                    PFNGETMODULEBASENAME pfnGetModuleBaseName;
-                    rc = RTLdrGetSymbol(hPSAPI, "GetModuleBaseName", (void**)&pfnGetModuleBaseName);
-                    if (RT_SUCCESS(rc))
-                    {
-                        /** @todo Retry if pBytesReturned equals cbBytes! */
-                        DWORD adwPIDs[4096]; /* Should be sufficient for now. */
-                        DWORD cbBytes = 0;
-                        if (pfnEnumProcesses(adwPIDs, sizeof(adwPIDs), &cbBytes))
-                        {
-                            for (size_t i = 0; papszNames[i] && !fFound; i++)
-                            {
-                                for (DWORD dwIdx = 0; dwIdx < cbBytes/sizeof(DWORD) && !fFound; dwIdx++)
-                                {
-                                    HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
-                                                               FALSE, adwPIDs[dwIdx]);
-                                    if (hProc)
-                                    {
-                                        char *pszProcName = NULL;
-                                        DWORD dwSize = 128;
-                                        do
-                                        {
-                                            RTMemRealloc(pszProcName, dwSize);
-                                            if (pfnGetModuleBaseName(hProc, 0, pszProcName, dwSize) == dwSize)
-                                                dwSize += 128;
-                                            if (dwSize > _4K) /* Play safe. */
-                                                break;
-                                        } while (GetLastError() == ERROR_INSUFFICIENT_BUFFER);
-
-                                        if (pszProcName)
-                                        {
-                                            if (   _stricmp(pszProcName, papszNames[i]) == 0
-                                                && RT_SUCCESS(rtProcGetProcessHandle(adwPIDs[dwIdx], pSid, phToken)))
-                                            {
-                                                fFound = true;
-                                            }
-                                        }
-                                        if (pszProcName)
-                                            RTStrFree(pszProcName);
-                                        CloseHandle(hProc);
-                                    }
-                                }
-                            }
-                        }
-                        else
-                            dwErr = GetLastError();
-                    }
-                }
-                RTLdrClose(hPSAPI);
-            }
+            else /* hSnap == INVALID_HANDLE_VALUE */
+                rc = RTErrConvertFromWin32(GetLastError());
         }
         RTLdrClose(hKernel32);
     }
-    Assert(dwErr == NO_ERROR);
+
+    /* If we couldn't take a process snapshot for some reason or another, fall
+       back on the NT4 compatible API. */
+    if (RT_FAILURE(rc))
+        return rtProcWinFindTokenByProcessAndPsApi(papszNames, pSid, phToken);
     return fFound;
 }
@@ -542,5 +577,5 @@
  * @param   phToken             Pointer to store the logon token.
  */
-static int rtProcUserLogon(PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain, HANDLE *phToken)
+static int rtProcWinUserLogon(PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain, HANDLE *phToken)
 {
     /** @todo Add domain support! */
@@ -559,5 +594,5 @@
                           phToken);
     if (!fRc)
-        return rtProcMapErrorCodes(GetLastError());
+        return rtProcWinMapErrorCodes(GetLastError());
     return VINF_SUCCESS;
 }
@@ -569,5 +604,5 @@
  * @param   hToken      The token (=user) to log off.
  */
-static void rtProcUserLogoff(HANDLE hToken)
+static void rtProcWinUserLogoff(HANDLE hToken)
 {
     CloseHandle(hToken);
@@ -585,35 +620,30 @@
  * @param   ppwszBlock      Pointer to the final output.
  */
-static int rtProcEnvironmentCreateInternal(VOID *pvBlock, RTENV hEnv, PRTUTF16 *ppwszBlock)
-{
-    int rc = VINF_SUCCESS;
+static int rtProcWinEnvironmentCreateInternal(VOID *pvBlock, RTENV hEnv, PRTUTF16 *ppwszBlock)
+{
     RTENV hEnvTemp;
-    rc = RTEnvClone(&hEnvTemp, hEnv);
+    int rc = RTEnvClone(&hEnvTemp, hEnv);
     if (RT_SUCCESS(rc))
     {
-        PRTUTF16 pBlock = (PRTUTF16)pvBlock;
-        while (   pBlock
-               && pBlock != '\0'
+        PCRTUTF16 pwch = (PCRTUTF16)pvBlock;
+        while (   pwch
                && RT_SUCCESS(rc))
         {
-            char *pszEntry;
-            rc = RTUtf16ToUtf8(pBlock, &pszEntry);
-            if (RT_SUCCESS(rc))
-            {
-                /* Don't overwrite values which we already have set to a custom value
-                 * specified in hEnv ... */
-                if (!RTEnvExistEx(hEnv, pszEntry))
-                    rc = RTEnvPutEx(hEnvTemp, pszEntry);
-                RTStrFree(pszEntry);
+            if (*pwch)
+            {
+                char *pszEntry;
+                rc = RTUtf16ToUtf8(pwch, &pszEntry);
+                if (RT_SUCCESS(rc))
+                {
+                    /* Don't overwrite values which we already have set to a custom value
+                     * specified in hEnv ... */
+                    if (!RTEnvExistEx(hEnv, pszEntry))
+                        rc = RTEnvPutEx(hEnvTemp, pszEntry);
+                    RTStrFree(pszEntry);
+                }
             }
-
-            size_t l;
-            /* 32k should be the maximum the environment block can have on Windows. */
-            if (FAILED(StringCbLengthW((LPCWSTR)pBlock, _32K * sizeof(RTUTF16), &l)))
+            pwch += RTUtf16Len(pwch) + 1;
+            if (*pwch)
                 break;
-            pBlock += l / sizeof(RTUTF16);
-            if (pBlock[1] == '\0') /* Did we reach the double zero termination (\0\0)? */
-                break;
-            pBlock++; /* Skip zero termination of current string and advance to next string ... */
         }
 
@@ -627,8 +657,10 @@
 
 /**
+ * Creates the environment block using Userenv.dll.
+ *
  * Builds up the environment block for a specified user (identified by a token),
  * whereas hEnv is an additional set of environment variables which overwrite existing
  * values of the user profile.  ppwszBlock needs to be destroyed after usage
- * calling rtProcEnvironmentDestroy().
+ * calling rtProcWinDestoryEnv().
  *
  * @return  IPRT status code.
@@ -638,5 +670,5 @@
  * @param   ppwszBlock      Pointer to a pointer of the final UTF16 environment block.
  */
-static int rtProcEnvironmentCreateFromToken(HANDLE hToken, RTENV hEnv, PRTUTF16 *ppwszBlock)
+static int rtProcWinCreateEnvFromToken(HANDLE hToken, RTENV hEnv, PRTUTF16 *ppwszBlock)
 {
     RTLDRMOD hUserenv;
@@ -652,9 +684,9 @@
             if (RT_SUCCESS(rc))
             {
-                LPVOID pEnvBlockProfile = NULL;
-                if (pfnCreateEnvironmentBlock(&pEnvBlockProfile, hToken, FALSE /* Don't inherit from parent. */))
+                LPVOID pvEnvBlockProfile = NULL;
+                if (pfnCreateEnvironmentBlock(&pvEnvBlockProfile, hToken, FALSE /* Don't inherit from parent. */))
                 {
-                    rc = rtProcEnvironmentCreateInternal(pEnvBlockProfile, hEnv, ppwszBlock);
-                    pfnDestroyEnvironmentBlock(pEnvBlockProfile);
+                    rc = rtProcWinEnvironmentCreateInternal(pvEnvBlockProfile, hEnv, ppwszBlock);
+                    pfnDestroyEnvironmentBlock(pvEnvBlockProfile);
                 }
                 else
@@ -664,4 +696,5 @@
         RTLdrClose(hUserenv);
     }
+
     /* If we don't have the Userenv-API for whatever reason or something with the
      * native environment block failed, try to return at least our own environment block. */
@@ -676,5 +709,5 @@
  * and domain), whereas hEnv is an additional set of environment variables which overwrite
  * existing values of the user profile.  ppwszBlock needs to be destroyed after usage
- * calling rtProcEnvironmentDestroy().
+ * calling rtProcWinDestoryEnv().
  *
  * @return  IPRT status code.
@@ -686,13 +719,13 @@
  * @param   ppwszBlock      Pointer to a pointer of the final UTF16 environment block.
  */
-static int rtProcEnvironmentCreateFromAccount(PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain,
+static int rtProcWinCreateEnvFromAccount(PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszDomain,
                                               RTENV hEnv, PRTUTF16 *ppwszBlock)
 {
     HANDLE hToken;
-    int rc = rtProcUserLogon(pwszUser, pwszPassword, pwszDomain, &hToken);
+    int rc = rtProcWinUserLogon(pwszUser, pwszPassword, pwszDomain, &hToken);
     if (RT_SUCCESS(rc))
     {
-        rc = rtProcEnvironmentCreateFromToken(hToken, hEnv, ppwszBlock);
-        rtProcUserLogoff(hToken);
+        rc = rtProcWinCreateEnvFromToken(hToken, hEnv, ppwszBlock);
+        rtProcWinUserLogoff(hToken);
     }
     return rc;
@@ -701,10 +734,10 @@
 
 /**
- * Destroys an environment block formerly created by rtProcEnvironmentCreateInternal(),
- * rtProcEnvironmentCreateFromToken() or rtProcEnvironmentCreateFromAccount().
+ * Destroys an environment block formerly created by rtProcWinEnvironmentCreateInternal(),
+ * rtProcWinCreateEnvFromToken() or rtProcWinCreateEnvFromAccount().
  *
  * @param   ppwszBlock      Environment block to destroy.
  */
-static void rtProcEnvironmentDestroy(PRTUTF16 ppwszBlock)
+static void rtProcWinDestoryEnv(PRTUTF16 ppwszBlock)
 {
     RTEnvFreeUtf16Block(ppwszBlock);
@@ -712,5 +745,5 @@
 
 
-static int rtProcCreateAsUserHlp(PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszExec, PRTUTF16 pwszCmdLine,
+static int rtProcWinCreateAsUser(PRTUTF16 pwszUser, PRTUTF16 pwszPassword, PRTUTF16 pwszExec, PRTUTF16 pwszCmdLine,
                                  RTENV hEnv, DWORD dwCreationFlags,
                                  STARTUPINFOW *pStartupInfo, PROCESS_INFORMATION *pProcInfo, uint32_t fFlags)
@@ -736,10 +769,10 @@
              */
             PFNCREATEPROCESSWITHLOGON pfnCreateProcessWithLogonW;
-            rc = RTLdrGetSymbol(hAdvAPI32, "CreateProcessWithLogonW", (void**)&pfnCreateProcessWithLogonW);
+            rc = RTLdrGetSymbol(hAdvAPI32, "CreateProcessWithLogonW", (void **)&pfnCreateProcessWithLogonW);
             if (RT_SUCCESS(rc))
             {
                 PRTUTF16 pwszzBlock;
-                rc = rtProcEnvironmentCreateFromAccount(pwszUser, pwszPassword, NULL /* Domain */,
-                                                        hEnv, &pwszzBlock);
+                rc = rtProcWinCreateEnvFromAccount(pwszUser, pwszPassword, NULL /* Domain */,
+                                                   hEnv, &pwszzBlock);
                 if (RT_SUCCESS(rc))
                 {
@@ -756,6 +789,6 @@
                                                      pProcInfo);
                     if (!fRc)
-                        rc = rtProcMapErrorCodes(GetLastError());
-                    rtProcEnvironmentDestroy(pwszzBlock);
+                        rc = rtProcWinMapErrorCodes(GetLastError());
+                    rtProcWinDestoryEnv(pwszzBlock);
                 }
             }
@@ -799,5 +832,5 @@
         PHANDLE phToken = NULL;
         HANDLE hTokenLogon = INVALID_HANDLE_VALUE;
-        rc = rtProcUserLogon(pwszUser, pwszPassword, NULL /* Domain */, &hTokenLogon);
+        rc = rtProcWinUserLogon(pwszUser, pwszPassword, NULL /* Domain */, &hTokenLogon);
         if (RT_SUCCESS(rc))
         {
@@ -854,5 +887,5 @@
                             NULL
                         };
-                        fFound = rtProcFindProcessByName(s_papszProcNames, pSid, &hTokenUserDesktop);
+                        fFound = rtProcWinFindTokenByProcess(s_papszProcNames, pSid, &hTokenUserDesktop);
                     }
                     else
@@ -907,5 +940,5 @@
                             {
                                 PRTUTF16 pwszzBlock;
-                                rc = rtProcEnvironmentCreateFromToken(*phToken, hEnv, &pwszzBlock);
+                                rc = rtProcWinCreateEnvFromToken(*phToken, hEnv, &pwszzBlock);
                                 if (RT_SUCCESS(rc))
                                 {
@@ -931,5 +964,5 @@
                                     else
                                         dwErr = GetLastError(); /* CreateProcessAsUserW() failed. */
-                                    rtProcEnvironmentDestroy(pwszzBlock);
+                                    rtProcWinDestoryEnv(pwszzBlock);
                                 }
 
@@ -954,5 +987,5 @@
             if (hTokenUserDesktop != INVALID_HANDLE_VALUE)
                 CloseHandle(hTokenUserDesktop);
-            rtProcUserLogoff(hTokenLogon);
+            rtProcWinUserLogoff(hTokenLogon);
         }
     }
@@ -960,5 +993,5 @@
     if (   RT_SUCCESS(rc)
         && dwErr != NO_ERROR)
-        rc = rtProcMapErrorCodes(dwErr);
+        rc = rtProcWinMapErrorCodes(dwErr);
 
     return rc;
@@ -1107,5 +1140,5 @@
                  * Only use the normal CreateProcess stuff if we have no user name
                  * and we are not running from a (Windows) service. Otherwise use
-                 * the more advanced version in rtProcCreateAsUserHlp().
+                 * the more advanced version in rtProcWinCreateAsUser().
                  */
                 if (   pszAsUser == NULL
@@ -1140,5 +1173,5 @@
                         if (RT_SUCCESS(rc))
                         {
-                            rc = rtProcCreateAsUserHlp(pwszUser, pwszPassword,
+                            rc = rtProcWinCreateAsUser(pwszUser, pwszPassword,
                                                        pwszExec, pwszCmdLine, hEnv, dwCreationFlags,
                                                        &StartupInfo, &ProcInfo, fFlags);
