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.
Warning: undocumented behavior begins. this code can break any time Microsoft pushes a Windows Update.
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.
undocumented behavior ends
The API to list the current user's group names are :
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With