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

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

问题描述

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

  LPTSTR pUserName = NULL; 
DWORD dwcbSzUserName = 0;

//'dwSessID'=用户会话ID
if(WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,dwSessID,WTSUserName,& pUserName,& dwcbSzUserName))
{
/ /在pUserName中获取用户名
}

if(pUserName)
WTSFreeMemory(pUserName);但是在Windows 8它返回一些缩写的名称,例如,john_000当实际用户的名字是John A. Doe。



那么,在Windows 8上使用WinAPI检索登录用户(可能还有他们的电子邮件)的名称的方法是什么

解决方案

您可以尝试 NetUserGetInfo with USER_INFO_23 以获取全名。



基本上如下:

  //在'pUserName '
NetUserGetInfo(NULL,pUserName,23,my_USER_INFO_23);
//在my_USER_INFO_23.usri23_full_name
中显示名称


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?

解决方案

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

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

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