bayman
the following code certainly works on win98/NT - don't use Win2K at the moment, but it should work ok. the following code uses Win32 API. I have given a function for getting the UserName, and also a function for getting the Computer Name, as i find it is often usefull to have both peices of information.
_______________________________________
Private Declare Function API_GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function API_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetWinComputerName()
Dim strBuf$, lngSize&, lngReturn&
lngSize = 255
strBuf = String(lngSize, " ")
lngReturn = API_GetComputerName(strBuf, lngSize)
strBuf = Left(strBuf, lngSize)
GetWinComputerName = strBuf
End Function
Public Function GetWinUserName()
Dim strBuf$, lngSize&, lngReturn&
lngSize = 255
strBuf = String(lngSize, " ")
lngReturn = API_GetUserName(strBuf, lngSize)
strBuf = Left(strBuf, lngSize - 1)
GetWinUserName = strBuf
End Function
_______________________________________
you can then call either the GetWinUserName() or GetWinComputerName() funcitons to get the info you want. i.e.
Dim strUserName As String
strUserName = GeWinUserName()
Hope that helps
axa