ThatRickGuy
Programmer
Hey guys,
I just finished this code that returns the current user's full name. I pulls the full name from the active director using the WMI. It works, but one of my coworkers just asked be "Isn't there an easier way to do that?"
Just wondering if anyone knows of a better way, or some built in environment variable that has the full user name.
-Rick
----------------------
I just finished this code that returns the current user's full name. I pulls the full name from the active director using the WMI. It works, but one of my coworkers just asked be "Isn't there an easier way to do that?"
Just wondering if anyone knows of a better way, or some built in environment variable that has the full user name.
Code:
Public Function LoggedOnUser() As String
Dim sReturn as String
Dim UserAccount As ManagementObject
Dim scope As New ManagementScope("\\localhost\root\cimv2")
scope.Connect()
Dim FNsearcher As New ManagementObjectSearcher( _
scope, _
New Management.ObjectQuery( _
"SELECT * " & _
"FROM Win32_UserAccount " & _
"WHERE Name='" & _
System.Environment.UserName & "'"))
For Each UserAccount In FNsearcher.Get()
sReturn = UserAccount("FullName").ToString
Next UserAccount
Return sreturn
End Function
-Rick
----------------------