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)
直接用winsock控件的localhost属性也行
我要的是在VB程序中,怎样获取本地计算机名称,text1.text=本地计算机名
首先在 工程->部件 中加载winsock控件,即c:\windows\system32\mswinsck.ocx文件,然后放到窗体上,代码引用:Private Sub Command1_Click() dim computername as string computername=Winsock1.LocalHostName ' msgbox computername End Sub
先定义一个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
Private Sub Form_Load() Text1.Text = Environ("computername") End Sub
Dim cpt As String * 255
Dim CompuName As String
Dim TempLong As Long
TempLong = GetComputerName(cpt, 255)
dim computername as string
computername=Winsock1.LocalHostName
' msgbox computername
End Sub
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
Text1.Text = Environ("computername")
End Sub
Text1 = WshNetwork.ComputerName