使用 C++ 和 WinAPI 在 Windows 8 上获取登录用户名或电子邮件 [英] Get logged on user's name or email on Windows 8 using C++ and WinAPIs

查看:74
本文介绍了使用 C++ 和 WinAPI 在 Windows 8 上获取登录用户名或电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 7 上检索已登录用户的名称,我可以这样做:

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);

但在 Windows 8 上,它会返回一些缩写名称,例如,当实际用户的名称是John A. Doe"时,它会返回john_000".

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

那么,使用 WinAPI 在 Windows 8 上使用 C++ 检索登录用户的名称(可能还有他们的电子邮件)的方法是什么,如登录屏幕上显示的那样?

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?

推荐答案

你可以试试NetUserGetInfoUSER_INFO_23 获取全名.

You could try NetUserGetInfo with USER_INFO_23 to get full name.

基本上是这样的:

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

这篇关于使用 C++ 和 WinAPI 在 Windows 8 上获取登录用户名或电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆