Windows Dev Center

 locked
How do you retrieve the Windows logged in Username since System.Environment.UserName seems to not be available?

    Question

  • How do you retrieve the Windows logged in Username since System.Environment.UserName seems to not be available?
    Wednesday, April 24, 2013 4:40 AM

Answers

  • Methods which end in "Async" do not return their value directly: they return an IAsyncOperation<T> which will return the value only after that task is run. In your example the System._COM object is this IAsyncOperation<string>.

    To get the value GetDisplayNameAsync returns you need to await it:

    householdMember.LastUpdatedByUserName = await Windows.System.UserProfile.UserInformation.GetDisplayNameAsync();

    See Asynchronous programming in C# and Visual Basic for more information on this. I strongly recommend that you read the topics in Writing code for Windows Store apps (C#/C++/VB). These topics discuss porting from WPF and Silverlight as well as concepts such as async which are used frequently in Windows Store apps.

    You might also want to look at the Account picture name sample 

    --Rob


    Wednesday, April 24, 2013 5:23 PM
    Owner

All replies