Tools Links Login

Get the logged on username from Windows 95/98/NT

Get the logged on username from Windows 95/98 and NT

Original Author: Ryan Hartman

API Declarations

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal
lpBuffer As String, nSize As Long) As Long
'inl as 1

Code

gsUserId = ClipNull(GetUser())
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
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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 97 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.