最简单的方法,用Winsock控件!

解决方案 »

  1.   

    不用控件呢?有没有什么API函数?
      

  2.   

    Public Function GetUserLogonName() As String
    '
    ' This will obtain the users logged on name once from the system. The
    ' second time it is called it returns the static 'sName' variable
    '
        Static sName As String
        Dim lBuffLen As Long
        Dim sBuffer As String
        Dim lRet As Long
        
        
        If Len(sName) > 0 Then
            GetUserLogonName = sName
            Exit Function
        Else
            lBuffLen = 128
            sBuffer = String$(lBuffLen, vbNullChar)
            lRet = GetUserName(sBuffer, lBuffLen)
            If lRet < 0 Then

    ' Handle error from API here
    '
                Exit Function
            End If
            sName = Left$(sBuffer, lBuffLen - 1)
            GetUserLogonName = sName
        End IfEnd Function
      

  3.   

    '??是?得网?中??的名?吧。
    '用API函?吧.保?成功.
    Public Declare Function GetComputerName Lib "Kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Public Function GetComName() As String
        Dim strBuffer As String
        Dim Com As String
        Dim ingLen As Long
        strBuffer = Space(30)
        ingLen = Len(strBuffer)
        Call GetComputerName(strBuffer, ingLen)
        Com = Left$(strBuffer, ingLen)
        GetComName = Com
    End Function