GetUserName

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

I am using VB.NET and need to get the user's name that
has logged onto the user's computer. In VB6 I used an
API call. Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?

Many Thanks,
 
Robert said:
I am using VB.NET and need to get the user's name that
has logged onto the user's computer.

Public Function GetUserName() As String
GetUserName = (SystemInformation.UserName.ToString)
' This will return only the user name
End Function
' If you want the domain name included, use the code:
Imports System
Imports System.Security
Public Module SysInfo
Public Function GetUserName() As String
Principal.WindowsIdentity.GetCurrent.Name
' This will return 'domain\username'
End Function
End Module

or

' You can also call the code direct, such as Text1.Text =
(SystemInformation.UserName.ToString)
 
Robert,
Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?

System.Environment.UserName



Mattias
 
* "Robert said:
I am using VB.NET and need to get the user's name that
has logged onto the user's computer. In VB6 I used an
API call. Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?

'Environment.UserName'.
 
I am using VB.NET and need to get the user's name that
has logged onto the user's computer. In VB6 I used an
API call. Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?

Many Thanks,

System.Environment.UserName
 
Back
Top