[英]Get logged on user's name or email on Windows 8 using C++ and WinAPIs
On Windows 7 to retrieve the name of a logged on user I can do this:在 Windows 7 上检索登录用户的名称,我可以这样做:
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".但在 Windows 8 上,它返回一些缩写名称,例如,当实际用户的名称是“John A. Doe”时,它返回“john_000”。
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?那么,在登录屏幕上使用 WinAPI 使用 C++ 在 Windows 8 上检索登录用户的名称(可能还有他们的电子邮件)的方法是什么?
You could try NetUserGetInfo with USER_INFO_23 to get full name.您可以使用USER_INFO_23尝试使用NetUserGetInfo来获取全名。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.