Attribute VB_Name = "modUser" Option Explicit Private Const MODULE_NAME = "modUser" ' Declare for call to mpr.dll. Private Declare Function apiWNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long Private Const NoError = 0 'The Function call was successful Function fncGetUserName() As String Dim lCallChain As Long lCallChain = fncAddProcedure(ModuleName & "-fncGetUserName") ' Buffer size for the return string. Const lpnLength As Integer = 255 ' Get return buffer space. Dim status As Integer ' For getting user information. Dim lpName, lpUserName As String ' Assign the buffer size constant to lpUserName. lpUserName = Space$(lpnLength + 1) ' Get the log-on name of the person using product. status = apiWNetGetUser(lpName, lpUserName, lpnLength) ' See whether error occurred. If status = NoError Then ' This line removes the null character. Strings in C are null- ' terminated. Strings in Visual Basic are not null-terminated. ' The null character must be removed from the C strings to be used ' cleanly in Visual Basic. lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1) Else ' An error occurred. fncGetUserName = "Unknown" End End If ' Display the name of the person logged on to the machine. fncGetUserName = lpUserName subRemoveProcedureFromCallChain (lCallChain) End Function Public Property Get ModuleName() As String ModuleName = MODULE_NAME End Property