获取Windows用户显示名称 [英] Get Windows User Display Name

查看:151
本文介绍了获取Windows用户显示名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得已登录用户的的显示名称的?不是的用户名的,但是的显示名称的,如显示在下面的截图 - 和看到任何Windows Vista / 7的电脑开始菜单中的





我尝试了一堆其他问题的不同意见,但他们都表现出的用户名的,不是的显示名称的。你可以看到这些尝试的结果在上面的截图。

 进口System.Security.Principal 
进口系统。线程
进口System.IO
进口系统

类公共Form1的

私人小组Form1_Load的(BYVAL发件人为System.Object的,BYVAL E上系统。 EventArgs的)把手MyBase.Load
MSGBOX(1:&放大器; System.Security.Principal.WindowsIdentity.GetCurrent()。Name.ToString和放大器; vbCrLf&放大器; _
2:&放大器;环境.UserDomainName&放大器; vbCrLf&放大器; _
3:&放大器; WindowsIdentity.GetCurrent()名称和放大器; vbCrLf&放大器; _
4:&放大器; Thread.CurrentPrincipal.Identity.Name&安培; vbCrLf&放大器; _
5:&放大器; Environment.UserName&放大器; vbCrLf&放大器; _
6:&放大器; My.User.Name&放大器; vbCrLf&安培;
7: &放大器; My.Computer.Name)

端子

端类


解决方案

您应该使用的 UserPrincipal.DisplayName

  System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName 

要做到所以,你需要和你的项目添加到 System.DirectoryServices.AccountManagement.dll 引用。


How do I get the display name of the user that is logged in? Not the username, but the display name, such as is shown in the screenshot below - and as seen on the start menu in any Windows Vista/7 computer.

I tried a bunch of different suggestions from other questions, but they all show the username, not the display name. You can see the results of these attempts in the above screenshot.

Imports System.Security.Principal
Imports System.Threading
Imports System.IO
Imports System

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("1: " & System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString & vbCrLf & _
               "2: " & Environment.UserDomainName & vbCrLf & _
               "3: " & WindowsIdentity.GetCurrent().Name & vbCrLf & _
                "4: " & Thread.CurrentPrincipal.Identity.Name & vbCrLf & _
               "5: " & Environment.UserName & vbCrLf & _
               "6: " & My.User.Name & vbCrLf &
                "7: " & My.Computer.Name)

    End Sub

End Class

解决方案

You should use UserPrincipal.DisplayName:

System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName

To do so, you'll need to and add a reference to System.DirectoryServices.AccountManagement.dll from your project.

这篇关于获取Windows用户显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆