Code Samples for Businesses, Schools & Developers

Last Updated 11 March 2022


This function uses Windows Management Instrumentation (WMI) to get the full name of the user belonging to the network login profile.

Public Function GetUserFullName() As String

'Win32_NetworkLoginProfile class https://msdn.microsoft.com/en-us/library/aa394221%28v=vs.85%29.aspx

Dim objWin32NLP As Object, objItem As Object

On Error Resume Next

Set objWin32NLP = GetObject("WinMgmts:").instancesof("Win32_NetworkLoginProfile")

If Err.Number <> 0 Then
      MsgBox "Unable to retrieve current user name" & _
            "WMI is not installed", vbExclamation, "Windows Management Instrumentation"
      Exit Function
End If

For Each objItem In objWin32NLP
      If objItem.Flags > 0 Then GetUserFullName = objItem.FullName
Next

End Function



NOTE:
1.   This function may return an empty string if the user chooses not to associate a full name with a user name.
2.   For further details about the information available from the network logon profile, see the: Win32_NetworkLoginProfile class documentation



Colin Riddington           Mendip Data Systems                 Last Updated 11 March 2022

Return to Code Samples Page Return to Top