Write a function to get the username of the current login system

xiaoxiao2021-03-06  42

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 '------------------------------------- --------

转载请注明原文地址:https://www.9cbs.com/read-112645.html

New Post(0)