在VB中,如何获取本地计算机名称?在线等待,多谢!

解决方案 »

  1.   

    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Dim cpt As String * 255
    Dim CompuName As String
    Dim TempLong As Long
    TempLong = GetComputerName(cpt, 255)
      

  2.   

    直接用winsock控件的localhost属性也行
      

  3.   

    我要的是在VB程序中,怎样获取本地计算机名称,text1.text=本地计算机名
      

  4.   

    首先在 工程->部件 中加载winsock控件,即c:\windows\system32\mswinsck.ocx文件,然后放到窗体上,代码引用:Private Sub Command1_Click()
     dim computername as string
     computername=Winsock1.LocalHostName
     ' msgbox computername
    End Sub
      

  5.   

    先定义一个API函数,如下
    Private   Declare   Function   GetComputerName   Lib   "kernel32"   Alias   "GetComputerNameA"   (ByVal   lpBuffer   As   String,   nSize   As   Long)   As   Long  
      
    Dim cpt As String * 255 
    Dim  CompuName As String 
    Dim  TempLong As  Long 
    Private Sub Command1_Click()
    TempLong = GetComputerName(cpt,   255)  
    CompuName=cpt  '得到你的计算机名了
    end sub
      

  6.   

    Private Sub Form_Load()
    Text1.Text = Environ("computername")
    End Sub
      

  7.   

    用WSHSet WshNetWork = CreateObject("WScript.NetWork")
    Text1 = WshNetwork.ComputerName