Great, I created a user name activex dll and registered it in my system.
Thanks for all your help!
Code below for clsCurrentUser:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsCurrentUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Attribute VB_Ext_KEY = "RVB_UniqueId" ,"39897B570394"
'
Option Base 0
'private variables
'##ModelId=39897B580037
Private Const SIZE As Long = 255
'##ModelId=39897B58005F
Private user_name_buffer As String * SIZE
' Custom error constants:
'##ModelId=39897B580069
Private Const CUSTOM_ERR_SOURCE As String = "clsCurrentUser Object"
'##ModelId=39897B580073
Private Const CUSTOM_ERR_ERRNUMBASE As Long = vbObjectError + 512
'API Function Calls
'##ModelId=39897B5800A5
Private Declare Function getUserName Lib "advapi32.dll" Alias "GetUserNameA"
(ByVal lpBuffer As String, nSize As Long) As Long
'local variable(s) to hold property value(s)
'##ModelId=39897B580091
Private mvarUserName As String
'##ModelId=39897CF50153
Private Sub Class_Terminate()
#If DebugMode Then
'the class is being destroyed
Debug.Print "'" & TypeName(Me) & "' instance " & CStr(mlClassDebugID) &
" is terminating"
#End If
End Sub
'##ModelId=39897CF5013F
Private Sub Class_Initialize()
#If DebugMode Then
'get the next available class ID, and print out
'that the class was created successfully
mlClassDebugID = GetNextClassDebugID()
Debug.Print "'" & TypeName(Me) & "' instance " &
CStr(mlClassDebugID) & " created"
#End If
End Sub
'##ModelId=39897B5800CD
Public Property Get UserName() As String
Attribute UserName.VB_Description = "This property returns the current user
of the Operating System."
'used when retrieving value of a property, on the right side of an
assignment.
'Syntax: Debug.Print X.UserName
Dim succeeded As Long
On Error GoTo UserName_Err
succeeded = getUserName(user_name_buffer, SIZE)
If (succeeded <> 0) Then 'GetUserName succeeded
'may need to remove the empty space
UserName = user_name_buffer
Else
Err.Raise CUSTOM_ERR_ERRNUMBASE, CUSTOM_ERR_SOURCE, "GetUserName failed"
End If
UserName_End:
Exit Property
UserName_Err:
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile,
Err.HelpContext
Resume UserName_End
End Property
Quote:
> I have had instances when Environ("username") returned a blank value and
the
> API returned the correct value.
> -Andy