Retrieve current username

hugobooze

Active member
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 doesnt 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? :(
 
Code:
    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
 

Similar threads

G
Replies
0
Views
245
Gowrisankarrs
G
I
Replies
0
Views
158
Innovators World Wide
I
T
Replies
0
Views
127
The old Curmudgeon
T
M
Replies
0
Views
117
Mostafa Salaheldien
M
Back
Top