Get logged in user on Windows 8

Here is something that is not obvious on Windows 8 but if you want to get info about the user that is logged in you have to use the UserInformation static class.

Import the Windows.System.UserProfile namespace and then you can get lots of different information about the user that is logged into the OS, such as name, account picture, etc.

Here is a function I wrote that gets the users name.

private async Task<string> GetUserName()
{
    var userName = string.Format("Welcome, {0} {1}", await UserInformation.GetFirstNameAsync(), await UserInformation.GetLastNameAsync());

    return userName;
}
Advertisements

Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s