怎样获的本机名称?

解决方案 »

  1.   

    private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Longdim m_ComputerName As String
        m_ComputerName = String(255, " ")
        GetComputerName m_ComputerName, 255
        m_ComputerName = Trim(m_ComputerName)
        m_ComputerName = Left(m_ComputerName, Len(m_ComputerName) - 1)
      

  2.   

    添加部件:Microsoft WinSock Controls 6.0
    Winsock 控件text1.text=winsock1.localhostname
      

  3.   

    winsock控件
    Private Sub Command1_Click()
        Text1.Text = Winsock1.LocalIP
        Text2.Text = Winsock1.LocalHostName
        Winsock1.Close
    End Sub
      

  4.   

    Private Function getPcName() As String
        Dim nRet As Long
        Dim lpBuffer As String
        Dim nSize As Long    nSize = 60
        lpBuffer = String(nSize + 1, 0)
        nRet = GetComputerName(lpBuffer, nSize)
        lpBuffer = Left(lpBuffer, nSize)
        getPcName = lpBuffer
    End Function
    前面还要声明一些api函数
      

  5.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    '
    '取计算机名
    '函数:Get_ComputerName
    '参数:无
    '返回值:String,计算机名称
    '例子:
    Public Function Get_ComputerName() As String
        Dim strString As String
        strString = String(255, Chr$(0))
        GetComputerName strString, 255
        strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
        Get_ComputerName = strString
    End Function