1

I have tried using System.Environment.UserName and My.User.Name in VB. But I get the result: ASIA/rz2kl1 (which is my username)

But I want (Doe, John) which is the name associated with username and comes on top of the start menu.

Alex
  • 4,821
  • 16
  • 65
  • 106
  • Why is this tagged F#? It appears to be a vb.net or general .net question rather than one which is F# specific. – John Palmer Jun 07 '13 at 04:38
  • 1
    `userName = "(Doe, John)"` No seriously with out telling us why you expect `(Doe, John)` and not the user name is going to be hard to give you anything helpfull – Rune FS Jun 07 '13 at 04:45

3 Answers3

1

Use GetUserNameEx function.

Retrieves the name of the user or other security principal associated with the calling thread. You can specify the format of the returned name.

If the thread is impersonating a client, GetUserNameEx returns the name of the client.

More documentation can be found here.

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
0

Something like this should be helpful:

    Dim UserName As String = "ASIA\rz2kl1 (Doe, John)"
    Dim ExtractName() As String = UserName.Split()
    Dim Name As String = ExtractName(1) + " " + ExtractName(2)
tinstaafl
  • 6,908
  • 2
  • 15
  • 22
0

Add the following reference Account Management Reference


Add the following import:

Imports System.DirectoryServices.AccountManagement

Finally, add the following line of code:

Dim userFullName As String = UserPrincipal.Current.DisplayName
Alex
  • 4,821
  • 16
  • 65
  • 106