从Windows 8桌面应用程序中获取的Microsoft帐户ID [英] Get Microsoft Account Id from Windows 8 desktop application
本文介绍了从Windows 8桌面应用程序中获取的Microsoft帐户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图找出用户登录到Windows 8与微软帐号的活动电子邮件/ ID,假设它不是本地户口,他们进行身份验证的。
Trying to find out the active email / id of the user logged into Windows 8 with a Microsoft Account, assuming it is not a local account they are authenticated as.
- 在试图找到从一个WPF桌面C#应用程序,而不是Windows应用商店的应用程序
- 如发现活的SDK是潜在相关,<一个href="http://msdn.microsoft.com/en-us/library/live/hh826533.aspx#requesting_info_in_c__for_windows_store_apps_and_windows_phone_apps"相对=nofollow>例如。在我的快捷方式的,但我不知道这个API可以从一个完全成熟的.NET应用程序中使用?
- Trying to find that out from a WPF desktop C# application, not a Windows Store app
- Found the Live SDK to be potentially relevant, e.g. the me shortcut, but am not sure this API can be used from a full-fledged .NET application?
推荐答案
警告:无证行为开始
在创建用户的令牌当一组名为Microsoft帐户\ YourAccountId被添加到用户的令牌。你可以用它来查找活动用户的Microsoft帐户。
when your user token is created a group named "Microsoft Account\YourAccountId" is added to the user token. You can use it to find the active user's Microsoft Account.
无证行为结束
该API可列出当前用户的组名是:
The API to list the current user's group names are :
- OpenProcessToken GetCurrentProcess TOKEN_QUERY获得进程令牌
- GetTokenInformation TokenGroups获得团体令牌
- 执行LookupAccountSid获得组名称
这是很容易使用System.Security.Principal类来写一个例子:
It is much easier to write an example using System.Security.Principal classes:
public static string GetAccoutName()
{
var wi= WindowsIdentity.GetCurrent();
var groups=from g in wi.Groups
select new SecurityIdentifier(g.Value)
.Translate(typeof(NTAccount)).Value;
var msAccount = (from g in groups
where g.StartsWith(@"MicrosoftAccount\")
select g).FirstOrDefault();
return msAccount == null ? wi.Name:
msAccount.Substring(@"MicrosoftAccount\".Length);
}
这篇关于从Windows 8桌面应用程序中获取的Microsoft帐户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文