Today, I have to use this in the project, I wrote it, it is convenient, the source code is as follows:
Option expedition
Private Declare Function GetUserName LIB "Advapi32.dll" Alias "getusernamea" (Byval Lpbuffer AS String, nsize as long) AS
LONGPRIVATE DECLARE FUNCTION LSTRLENW LIB "KERNEL32" (Byval LPSTRING As Long) As long
Public Function GetSysLoggedUserName () As String Dim buf As String * 20 If GetUserName (buf, 20) = 1 Then GetSysLoggedUserName = Left $ (buf, lstrlenW (StrPtr (buf))) Exit Function End If GetSysLoggedUserName = "" End Function
'-------------------------------------------' Please indicate the source 'author: Don just fine' E-mail: tanaya@163.com '------------------------------------- --------