Windows登录用户名-完整的用户名 [英] Windows Login User Name - Full user name

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

问题描述



我正在开发一个简单的数据库,并且试图从Windows登录名中获取用户名.

我已经尝试过Environment.UserName,但是返回用户登录名的方式却如此.我们正在使用的用户登录名是员工ID,而不是姓名.

但是,Windows确实会在开始菜单上和您保存文档时显示全名.我不太确定如何检索此信息?

在此先感谢

Marco

解决方案

尝试:

 System.Security.Principal.IPrincipal currUser;
currUser = System.Web.HttpContext.Current.User; 



我记得很多,当我使用它时,如果您正在寻找的话,它通常会以域名/用户名的形式显示全名.

更新:
在这里看看: MSDN链接HttpContext.User属性 [ ^ ],请尝试一下! com/KB/dotnet/UserName.aspx [ ^ ]

现在我已经做到了:

 导入 System.DirectoryServices.AccountManagement
公共  Form1

    私人  Form1_Load( ByVal 发​​件人 As 系统.对象 ByVal  e  As  System.EventArgs)句柄  MyBase  .Load
         Dim  LogonUserFName  As  字符串 = UserPrincipal.Current .给定的名称
         Dim  LogonUserSName  As  字符串 = UserPrincipal.Current .姓
         Dim  LogonUserID  As  字符串 = UserPrincipal.Current .SamAccountName

        MsgBox(LogonUserFName& " & logonUserSName&  " & LogonUserID)
    结束 
结束  



我应该再搜索10分钟;)


在这里,您走了...

  Dim  DomainUser  As  字符串 = My.User.Name.Replace("  /")
 Dim  ADEntry  As   New  System.DirectoryServices. DirectoryEntry(" & DomainUser)
'  MsgBox(ADEntry.Properties("FullName").Value) 


Hi,

I''m developing a simple database and I''m trying to get the user name from the windows login.

I have tried Environment.UserName, how ever that returns the user login name. The user login that we are using is an employee ID and not a name.

However Windows does display the full name on the start menu and when you save documents. I''m not quite sure how do I retrieve this information?

Thanks in advance

Marco

解决方案

Try:

System.Security.Principal.IPrincipal currUser;      
currUser = System.Web.HttpContext.Current.User;



As much I remember, when I used it, it used to show full name as in domainname/username, if this is what you are looking for.

UPDATE:
Have a look here: MSDN link HttpContext.User Property [^], try it!


I just ran across this from http://www.codeproject.com/KB/dotnet/UserName.aspx[^]

Now I have done this:

Imports System.DirectoryServices.AccountManagement
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim LogonUserFName As String = UserPrincipal.Current.GivenName
        Dim LogonUserSName As String = UserPrincipal.Current.Surname
        Dim LogonUserID As String = UserPrincipal.Current.SamAccountName

        MsgBox(LogonUserFName & " " & logonUserSName & " " & LogonUserID)
    End Sub
End Class



I should have searched for 10 minutes longer ;)


Here you go...

Dim DomainUser As String = My.User.Name.Replace("\", "/")
Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://" & DomainUser)
'MsgBox(ADEntry.Properties("FullName").Value)


这篇关于Windows登录用户名-完整的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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