How do I get the first name and last name of the logged in Windows user?

前端 未结 6 1030
独厮守ぢ
独厮守ぢ 2020-12-04 15:53

How I can get my first name last name with c# in my system (logging in windows with Active Directory username and pass)?

Is it possible to do that without going to t

6条回答
  •  半阙折子戏
    2020-12-04 16:14

    There is an easier way to do this:

    using System.DirectoryServices.AccountManagement;
    
    UserPrincipal userPrincipal = UserPrincipal.Current;
    String name = userPrincipal.DisplayName;
    

    enter image description here

提交回复
热议问题