|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Retrieveing full Username from Enviroment?Hi
If I use the code: MsgBox(Environment.UserName) .... I get the username you log into windows with But how do I retrieve that Full Name of that useraccount? Best Regards/ Lars Netzel Possible with native API calls i.e InterOp.. I am not sure of the exact
syntax... Check www.pinvoke.net. You will get some idea VJ Show quoteHide quote "Lars Netzel" <uih***@adf.se> wrote in message news:uuqY7ClWGHA.1192@TK2MSFTNGP04.phx.gbl... > Hi > > If I use the code: > > MsgBox(Environment.UserName) > > ... I get the username you log into windows with > > But how do I retrieve that Full Name of that useraccount? > > Best Regards/ > Lars Netzel > If you are in a domain with Active Directory you could query Active
directory to get the information. Something like: 'Please note that this code is rough and may need a bit of tweaking. 'Hard Coding for simplicity of example Dim strcon as string = "LDAP://mydomain.com" Dim strID as string = "MYID" Dim strpwd as string = "MYPWD" Dim strUserName as string = user.identity.name.Substring(user.identity.name.IndexOf("\") + 1) Dim Root As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry(strcon, strID, strpwd) Dim ds As System.DirectoryServices.DirectorySearcher = New System.DirectoryServices.DirectorySearcher(Root) Dim searchresult As DirectoryServices.SearchResult 'set the AD to filter to only the username we are looking for, then load the ad record ds.Filter = "SAMAccountName=" & strUserName ds.PropertiesToLoad.Add("cn") For Each searchresult In ds.FindAll() strADReturn = searchresult.GetDirectoryEntry.Name Next
How to make a copy of a developing VS05 application to another machine?
Calling dll functions from vb.net with pointer returns! How to declare char string pointer in VB? DataGridView - Property DataPropertyName KeyDown for non Active windows? Sorted array suggestions Playing card suits, vb.net? Seek Method, is it the right thing to use? Graphics for toolbar Version Check of .NET Framework at runtime |
|||||||||||||||||||||||