Hi,
How does one get the User Name of the User signed onto the
local machine in Windows XP? Is there a function for this?
Does this change for a user logged into a Windows Server
Domain?
Don't think so, since it is retrieved through Windows API
Use the following code:
Private Declare Function WNetGetUser Lib "Mpr" Alias "WNetGetUserA" _
(lpName As Any, ByVal lpUserName As String, lpnLength As Long) As Long
Function GetUserName() As String
Dim UserName As String, cbusername, ret As Long
UserName = Space(256)
cbusername = Len(UserName)
ret = WNetGetUser(ByVal 0&, UserName, cbusername)
If ret = 0 Then
' Success - strip off the null.
UserName = VBA.Left(UserName, InStr(UserName, Chr(0)) - 1)
Else
UserName = ""
End If
GetUserName = UserName
End Function
HTH,
Bogdan Zamfir
_________________________
Independent consultant