Index: trunk/include/iprt/process.h
===================================================================
--- trunk/include/iprt/process.h	(revision 41918)
+++ trunk/include/iprt/process.h	(revision 41919)
@@ -364,4 +364,19 @@
 RTR3DECL(bool)  RTProcIsRunningByName(const char *pszName);
 
+/**
+ * Query the username of the given process.
+ *
+ * @returns IPRT status code.
+ * @retval VERR_BUFFER_OVERFLOW if the given buffer size is to small for the username.
+ * @param   hProcess     The process handle to query the username for.
+ * @param   pszUser      Where to store the user name on success.
+ * @param   cbUser       The size of the user name buffer.
+ * @param   pcbUser      Where to store the username length on success
+ *                       or the required buffer size if VERR_BUFFER_OVERFLOW
+ *                       is returned.
+ */
+RTR3DECL(int)   RTProcQueryUsername(RTPROCESS hProcess, char *pszUser, size_t cbUser,
+                                    size_t *pcbUser);
+
 #endif /* IN_RING3 */
 
Index: trunk/src/VBox/Runtime/r3/posix/process-posix.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/posix/process-posix.cpp	(revision 41918)
+++ trunk/src/VBox/Runtime/r3/posix/process-posix.cpp	(revision 41919)
@@ -38,4 +38,5 @@
 #include <sys/wait.h>
 #include <signal.h>
+#include <pwd.h>
 
 #include <iprt/process.h>
@@ -146,2 +147,45 @@
 }
 
+
+RTR3DECL(int) RTProcQueryUsername(RTPROCESS hProcess, char *pszUser, size_t cbUser,
+                                  size_t *pcbUser)
+{
+    AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
+    AssertReturn(cbUser > 0, VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pcbUser, VERR_INVALID_POINTER);
+
+    if (hProcess != RTProcSelf())
+        return VERR_NOT_SUPPORTED;
+
+    int32_t cbPwdMax = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (cbPwdMax == -1)
+        return RTErrConvertFromErrno(errno);
+
+    char *pbBuf = (char *)RTMemAllocZ(cbPwdMax);
+    if (!pbBuf)
+        return VERR_NO_MEMORY;
+
+    struct passwd Pwd, *pPwd;
+    int rc = getpwuid_r(geteuid(), &Pwd, pbBuf, cbPwdMax, &pPwd);
+    if (!rc)
+    {
+        size_t cbPwdUser = strlen(pPwd->pw_name) + 1;
+
+        *pcbUser = cbPwdUser;
+
+        if (cbPwdUser > cbUser)
+            rc = VERR_BUFFER_OVERFLOW;
+        else
+        {
+            memcpy(pszUser, pPwd->pw_name, cbPwdUser);
+            rc = VINF_SUCCESS;
+        }
+    }
+    else
+        rc = RTErrConvertFromErrno(rc);
+
+    RTMemFree(pbBuf);
+    return rc;
+}
+
+
Index: trunk/src/VBox/Runtime/r3/win/process-win.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 41918)
+++ trunk/src/VBox/Runtime/r3/win/process-win.cpp	(revision 41919)
@@ -38,4 +38,5 @@
 #include <errno.h>
 #include <Strsafe.h>
+#include <Lmcons.h>
 
 #include <iprt/process.h>
@@ -1424,2 +1425,41 @@
 }
 
+
+RTR3DECL(int) RTProcQueryUsername(RTPROCESS hProcess, char *pszUser, size_t cbUser,
+                                  size_t *pcbUser)
+{
+    AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
+    AssertReturn(cbUser > 0, VERR_INVALID_PARAMETER);
+    AssertPtrReturn(pcbUser, VERR_INVALID_POINTER);
+
+    if (hProcess != RTProcSelf())
+        return VERR_NOT_SUPPORTED;
+
+    RTUTF16 awszUserName[UNLEN + 1];
+    DWORD   cchUserName = UNLEN + 1;
+
+    if (!GetUserNameW(&awszUserName[0], &cchUserName))
+        return RTErrConvertFromWin32(GetLastError());
+
+    char *pszUserName = NULL;
+    int rc = RTUtf16ToUtf8(awszUserName, &pszUserName);
+    if (RT_SUCCESS(rc))
+    {
+        size_t cbUserName = strlen(pszUserName) + 1;
+
+        *pcbUser = cbUserName;
+
+        if (cbUserName > cbUser)
+            rc = VERR_BUFFER_OVERFLOW;
+        else
+        {
+            memcpy(pszUser, pszUserName, cbUserName);
+            rc = VINF_SUCCESS;
+        }
+
+        RTStrFree(pszUserName);
+    }
+
+    return rc;
+}
+
Index: trunk/src/VBox/Runtime/testcase/Makefile.kmk
===================================================================
--- trunk/src/VBox/Runtime/testcase/Makefile.kmk	(revision 41918)
+++ trunk/src/VBox/Runtime/testcase/Makefile.kmk	(revision 41919)
@@ -93,4 +93,5 @@
 	tstRTPrfIO \
 	tstRTProcCreateEx \
+	tstRTProcQueryUsername \
 	tstPrfRT \
 	tstRand \
@@ -451,4 +452,7 @@
 tstRTProcCreateEx_SOURCES = tstRTProcCreateEx.cpp
 
+tstRTProcQueryUsername_TEMPLATE = VBOXR3TSTEXE
+tstRTProcQueryUsername_SOURCES = tstRTProcQueryUsername.cpp
+
 tstRTProcWait_TEMPLATE = VBOXR3TSTEXE
 tstRTProcWait_SOURCES = tstRTProcWait.cpp
