GetUserName() return "SYSTEM" FOR SYSTEM PROCESS
-
For getting the user name in, we are call the GetUserName() in the Application context, in which case we get it right if the Application is launched form logged in user. But in case of system process GetUserName() return "SYSTEM" as current user. There is any API or Method to get the current user name in system process? THANKS IN ADVANCE
-
For getting the user name in, we are call the GetUserName() in the Application context, in which case we get it right if the Application is launched form logged in user. But in case of system process GetUserName() return "SYSTEM" as current user. There is any API or Method to get the current user name in system process? THANKS IN ADVANCE
-
Look at regestry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer value Logon User Name
the value at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer a
-
Look at regestry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer value Logon User Name
myshketer wrote:
HKEY_CURRENT_USER
How will that work from a service running as a different "user"? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
For getting the user name in, we are call the GetUserName() in the Application context, in which case we get it right if the Application is launched form logged in user. But in case of system process GetUserName() return "SYSTEM" as current user. There is any API or Method to get the current user name in system process? THANKS IN ADVANCE
For systems with fast user switching (XP+) where more than one user can be logged on at the same time, maybe something like this:
#include <WtsApi32.h> // link to WtsApi32.lib
...
DWORD dwSessionId = WTSGetActiveConsoleSessionId();
if (0xFFFFFFFF != dwSessionId)
{
LPTSTR pUserNameStr = 0;
DWORD dwBytesReturned = 0;if (WTSQuerySessionInformation(WTS\_CURRENT\_SERVER\_HANDLE, dwSessionId, WTSUserName, &pUserNameStr, &dwBytesReturned)) { // ... use pUserNameStr ... WTSFreeMemory(pUserNameStr); }
}
Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: