在 Windows 8 及更高版本上获取由 NetWkstaUserEnum API 返回的给定 Microsoft 帐户的本地登录名 [英] Get the local login name for the given Microsoft Account returned by NetWkstaUserEnum API on Windows 8 and above
问题描述
我正在使用 NetWkstaUserEnum()
获取本地用户名及其域详细信息.
I am using NetWkstaUserEnum()
to get the local users name and its domain details.
直到 Windows 7,它过去只返回登录名并且运行良好.从 Windows 8 开始,添加了 Microsoft 帐户,对于这种类型的帐户,API 开始返回 Microsoft 帐户名而不是本地登录名.
Till Windows 7 it used to return only the login name and it worked fine. From Windows 8 onwards Microsoft Account was added and for this type of account the API started returning the Microsoft Account name instead of the local login name.
例如,它返回 username@outlook.com
而不是 usern_0000
,后者是实际的 Windows 本地登录名.
For example it returned username@outlook.com
instead of usern_0000
which is the actual Windows local login name.
我不能使用 NetUserEnum()
因为它不返回用户的域名.
I cannot use NetUserEnum()
as it does not return the domain name of the user.
所以我需要获取 NetWkstaUserEnum()
API 返回的给定 Microsoft 帐户的本地登录名.
So I need to get the local login name for the given Microsoft Account returned by NetWkstaUserEnum()
API.
任何帮助将不胜感激.
推荐答案
最后我找到了一种方法来获取给定 Microsoft 帐户的 Windows 用户名.它使用 NetUserGetInfo()
来获取给定用户名的 Microsoft 帐户名称.
Finally I was able to locate a way to get the Windows username for the given Microsoft Account.It uses NetUserGetInfo()
to get the Microsoft Account name for the given username.
代码片段:
do
{
ntStatus = NetUserEnum(szSvr, 0, 0, (LPBYTE*)&userInfo0, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
if( (ntStatus == NERR_Success) || (ntStatus == ERROR_MORE_DATA) )
{
tmpinfo = userInfo0;
for( i = 0; (i < dwEntriesRead); i++ )
{
if(tmpinfo != NULL)
{
ntStatus = NetUserGetInfo(szSvr, tmpinfo->usri0_name, 24,(LPBYTE*)&userInfo24);
if(ntStatus == NERR_Success)
{
CString internetPrincipalName = (LPCWSTR) userInfo24->usri24_internet_principal_name;
if(LoginUsrStr.CompareNoCase(internetPrincipalName) == 0)
{
OutputDebugString("@@@@@@ Account Found @@@@@@");
localAccount = (LPCWSTR) tmpinfo->usri0_name;
userFound = TRUE;
break;
}
}
}
tmpinfo++;
}
}
if( userInfo0 != NULL )
{
NetApiBufferFree( userInfo0 ) ;
userInfo0 = NULL ;
}
if( userInfo24 != NULL )
{
NetApiBufferFree( userInfo24 ) ;
userInfo24 = NULL ;
}
} while( userFound == FALSE && ntStatus == ERROR_MORE_DATA ) ;
这篇关于在 Windows 8 及更高版本上获取由 NetWkstaUserEnum API 返回的给定 Microsoft 帐户的本地登录名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!