Retrieve current username

hugobooze

Freshman
Joined
Jul 22, 2003
Messages
25
Location
Sweden
How do you retrieve the current username in a vb.net-application? (windows login username) In vb6 you declare this function in a module:

Declare Function Wnetgetuser Lib "mpr" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

..and then you just call that function from your code, but I guess it doesn't work that way in vb.net

// Hugo
 
What if you are running a vb.net windows service project? how can you retrieve the current user name? the above code returns local system if you use it? :(
 
Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim user As Security.Principal.WindowsIdentity = Security.Principal.WindowsIdentity.GetCurrent
        MessageBox.Show(user.Name & "   " & user.AuthenticationType)
    End Sub
 
Back
Top