Get logged on user's name or email on Windows 8 using C++ and WinAPIs

眉间皱痕 提交于 2019-12-02 15:44:41

问题


On Windows 7 to retrieve the name of a logged on user I can do this:

LPTSTR pUserName = NULL;
DWORD dwcbSzUserName = 0;

//'dwSessID' = user session ID
if(WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, dwSessID, WTSUserName, &pUserName, &dwcbSzUserName))
{
    //Got user name in 'pUserName'
}

if(pUserName)
    WTSFreeMemory(pUserName);

But on Windows 8 it returns some abbreviated name, for instance, "john_000" when the actual user's name is "John A. Doe".

So what is the way to retrieve the name of the logged on user (and possibly their email) on Windows 8 with C++ using WinAPIs as it's shown at log-on screen?


回答1:


You could try NetUserGetInfo with USER_INFO_23 to get full name.

Something basically like:

    //Got user name in 'pUserName'
    NetUserGetInfo(NULL, pUserName, 23, my_USER_INFO_23);
    //Got display name in my_USER_INFO_23.usri23_full_name


来源:https://stackoverflow.com/questions/11927625/get-logged-on-users-name-or-email-on-windows-8-using-c-and-winapis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!