'API 声明:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'定义函数
Public Function ComputerName() As String
Dim Tmpstr As String
Dim l As Long
Tmpstr = String(256, 0)
l = GetComputerName(Tmpstr, 256)
ComputerName = Left(Tmpstr, InStr(1, Tmpstr, vbNullChar) - 1)
End Function
'窗体单击事件 print 计算机名
Private Sub Form_Click()
Print ComputerName
End Sub