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.
- 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?
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:
Open Registry Editor and navigate to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
Under the ProfileList key, you will see the SIDs. By selecting each one individually, you can look at the value entry and see what username is associated with that particular SID.
referring to the method described by Sheng (using tokens) here is a code on Delphi that we've created to get current MS account id: