473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Apr 7 '06 #1
2 1933
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

"Lars Netzel" <ui****@adf.se> wrote in message
news:uu**************@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

Apr 7 '06 #2
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.In dexOf("\") + 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

Apr 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike | last post by:
Greetings, I am writing an Intranet application in ASP.NET using VB.NET. I am obtaining the username of the user with: uName = User.Identity.Name, which is in the form of DOMAIN\username. I...
2
by: initial_y | last post by:
I want my web program run in full screen IE. Are there any way to adjust IE setting in program? I know a method that add -k at the end of command line, but this is a manual method and only the...
4
by: Benne Smith | last post by:
In our company, i have three servers; 1) a development server (mine only - here i make daily changes and test my stuff) 2) a test server (for the users to test milestone builds - changes weekly)...
2
by: Jesper | last post by:
Hi, I don't know if its possible, but I would like to get the full name of the user. Using string name = System.Environment.UserName; only gives me the login name of the user - however, when...
2
by: Cameron Frasnelly | last post by:
Does anyone know how to get the full Distinguished Name from the Useraname using vb.net??? All the examples show how to manipulate user objects but they have the LDAP path hardcoded??? I need to...
6
by: Brian Henry | last post by:
is there a way to tell when the database connection is retrieveing data? i saw the connectionstate.fetching enumerated value, but of course it's not implemented yet... is there another way to do...
6
by: tsmojver | last post by:
Does anyone know how to retreive the logon account username for a particular windows service? Or the current user that is running this service as a process. C# is the prefered language of choice. ...
1
by: majortool | last post by:
I'm trying to allow full menus based on network usernames. Right now I'm showing the database table for the username "james". Anyone know how to do that programatically? If...
1
by: svsenthilkumar | last post by:
how can i add 10 days with retrieveing date using php i retrieve a date from mysql table,and i add 10 days with that date and compare with today is or not.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.