Public Declare Function gethostname Lib "Winsock.dll" (ByVal host_name As String, ByVal namelen As Integer) As Integer'returns your local machines namePublic Function GetLocalHostName() As String
    Dim sName$
    sName = String(256, 0)
    If gethostname(sName, 256) Then
        sName = WSA_NoName
    Else
        If InStr(sName, Chr(0)) Then
            sName = Left(sName, InStr(sName, Chr(0)) - 1)
        End If
    End If
    GetLocalHostName = sName
End Function

解决方案 »

  1.   

    用不着api,用winsock1.localhostname就能得到,还是你想做成模块?
      

  2.   

    to :zqfleaf(啊风)     你写的程序小弟运行了,可是返回错误48 说找不到文件,但winsock.dll就在
    我的winnt\system32下面。这是怎么回事?望不吝赐教。
      

  3.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As LongDim sComputerName As String
    Dim lComputerNameLen As Long
    Dim lresult As Long
    lComputerNameLen = 256
    sComputerName = Space(lComputerNameLen)
    lresult = GetComputerName(sComputerName, lComputerNameLen)
    sComputerName中就是主机的名字字符串.