0

I want to read out the full name of an user. I am developing a WPF application for Windows with .NET 5.

I tried it with this line of code:

String Fullname = UserPrincipal.Current.DisplayName;

That worked fine on my PC, but when I wanted to test it on a company PC, it doesn't work.

Is there an alternative to the UserPrincipal?

I am new to programming and really don't know where to search.

JHBonarius
  • 10,824
  • 3
  • 22
  • 41
  • 2
    What version of the framework are you targetting? (.NET Full, .NET Core, .NET 5?). What kind of application are you developing (UWP, Console, Win, Web)? What does "corporate" mean (Active Directory Joined?). Hard to answer based on your question. – Alexander Schmidt Mar 22 '21 at 14:27
  • Sorry for not writing more details, I am creating a WPF Application with .NET 5. I dont know what you mean with corporate – Samuel Hanni Mar 22 '21 at 14:54
  • 1
    UserPrincipal is in System.DirectoryServices.AccountManagement. So, when you get UserPrincipal.Current - you get current Principal of loged on user, which execute your app. And this Principal get from Active Directory. First of all you must check DisplayName field in Active Directory for user. Your company PC must be included in AD. – Maxim Mar 22 '21 at 15:15
  • Can you please explain what you mean by "it doesn't work"? Does it throw an exception? Does it return some unexpected value? – Keith Stein Mar 23 '21 at 13:48

0 Answers0