简体   繁体   中英

VB .NET: Logged in user information

I'm writing software in VB .NET (2005) which uses the Windows user information as login credentials - just the username. I've found Environment.UserName which works for the username (as you would expect).

However, I need more information - I need the full name of the user (as shown on the Start Menu). It seems this information is stored... somewhere, as Windows is able to use it for things like permissions on file shares.

I've heard there's calls in user32.dll that can do this, but I'd like a .NET method if it's at all possible. I also have a SID for the user, if that helps at all.

Does anyone know the best way to get this additional information?

It seems the System.DirectoryServices namespace is exactly what I'm looking for.

Always seems that you find the answer right after you ask:)

For future reference:

Dim ent As New DirectoryServices.DirectoryEntry("WinNT://<Domain>/<Username>")
Dim props As DirectoryServices.PropertyCollection = ent.Properties
Debug.Print(props.Item("FullName").Value)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM