如何调用函数GetUsername获得登陆者的名称,用信息框显示出来?谢谢了

解决方案 »

  1.   

    Sub TstGetUserName() 'This will test the use of GetUserName.
       Dim UName As String
       Dim UNameLen As Long
       Dim X as Long
       UName = Space(255)
       UNameLen = 255
       X = GetUserName(UName, UNameLen)
       If X <> 0 Then 'We got the user's name
             UName = Left(UName, UNameLen - 1) 'Get all except the last character
             MsgBox "The current user is: " & vbCr & UName
          Else
             MsgBox "Unable to get the user name."
       End If
    End Sub
      

  2.   

    定义:
    'General Declarations area of a Code Module
    Public Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" _
                                (ByVal lpBuffer As String, nSize As Long)