Get Windows User Name
Get Windows User Name
(OP)
How can I get the actual Windows User-Name on a NT4.0 and WIN95 PC
in a Text variable ?
I need the User including the Domain-Name.
in a Text variable ?
I need the User including the Domain-Name.
RE: Get Windows User Name
pos
RE: Get Windows User Name
Declare Function WNetGetUser Lib "advapi32.dll" Alias "GetUserNameA" (ByVal szUser$, lpnBufferSize%) As Long
and call it like this:
dim uname as string, len as integer
call GetUserNameA(uname,len)
uname should be set to the user name
Mike
RE: Get Windows User Name
Function ClipNull(InString As String) As String
Dim intpos As Integer
If Len(InString) Then
intpos = InStr(InString, vbNullChar)
If intpos > 0 Then
ClipNull = Left(InString, intpos - 1)
Else
ClipNull = InString
End If
End If
End Function
Function GetUser() As String
Dim lpUserID As String
Dim nBuffer As Long
Dim Ret As Long
lpUserID = String(25, 0)
nBuffer = 25
Ret = GetUserName(lpUserID, nBuffer)
If Ret Then
GetUser$ = lpUserID$
End If
End Function
'Call like this
dim strUser as string
strUser = ClipNull(GetUser())