取登陆用户名

方法一
'获取用户名的API函数
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    On Error Resume Next
    '获取用户名
    Dim sBuffer As String
    Dim lSize As Long
    sBuffer = Space$(255)
    lSize = Len(sBuffer)
    Call GetUserName(sBuffer, lSize)
    If lSize > 0 Then
        txtUserName.Text = Left$(sBuffer, lSize)
    Else
        txtUserName.Text = vbNullString
    End If
-----------------------------------------------------------------

方法二
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 

Dim st As String * 100 
Dim pln As Long 
pln = 99 
GetUserName st, pln 
MsgBox Left$(st, pln) 



其实两种方法一样



文章来自: 本站原创
引用通告地址: http://www.is21.cn/trackback.asp?tbID=233
Tags:
评论: 0 | 引用: 0 | 查看次数: 2396
发表评论
你没有权限发表留言!