获得计算机名:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim strString As String
    'Create a buffer
    strString = String(255, Chr$(0))
    'Get the computer name
    GetComputerName strString, 255
    'remove the unnecessary chr$(0)'s
    strString = Left$(strString, InStr(1, strString, Chr$(0)))
    'Show the computer name
    MsgBox strString
End Sub获得本地IP地址,比较烦要用一大队API,所以最好的办法就是放个WINSOCK控件,然后
debug.print winsock1.localip

解决方案 »

  1.   

    获取计算机名称:
    Private Declare Function GetComputerName Lib "kernel32" alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Sub Command1_Click()Dim strName As String, lngLength As Long lngLength = 225
    strName = String(lngLength, Chr(0))
    GetComputerName strName, lngLength
    strName = Left(strName, lngLength)
    msgbox strNameEnd Sub
      

  2.   

    用一个WINSOCK1
    计算机名称=winsock1.localhostname
    IP= winsock1.localhostip
      

  3.   

    获取计算机名称:
    Private Declare Function GetComputerName Lib "kernel32" alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Sub Command1_Click()Dim strName As String, lngLength As Long lngLength = 225
    strName = String(lngLength, Chr(0))
    GetComputerName strName, lngLength
    strName = Left(strName, lngLength)
    msgbox strNameEnd Sub试试
      

  4.   

    感谢您使用微软产品。您可以调用API函数GetHostName获得本机的标准Host Name,再使用Windows Sockets的API函数GetHostByName通过本机的Host Name获得包含本机ip地址的Sockets信息。以下链接提供了详细的示例代码。
    Q160215 HOWTO: Obtain the Host IP Address Using Windows Sockets
    http://support.microsoft.com/support/kb/articles/q160/2/15.asp
    - 微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
    (http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查
    (http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。