如何获得计算机的机器名

来源:岁月联盟 编辑:zhu 时间:2007-02-01
用API函数GetComputerName可以方便的取得计算机的机器名。
Option Explicit
Private Declare Function GetComputerName Lib "Kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub Command1_Click()
Dim ComputerName As String, i As Long
i = 255
ComputerName = String(i, 0)
GetComputerName ComputerName, i
ComputerName = Left(ComputerName, i)
MsgBox "此电脑的名称是" & ComputerName
End Sub