|
1、函数法:
MsgBox Environ("COMPUTERNAME")
2、利用外部链接库
MsgBox CreateObject("WScript.Network").computername
或者:
MsgBox CreateObject("Shell.LocalMachine").MachineNaMe
3、调用API函数
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub computer_name()
Dim computername As String * 255
GetComputerName computername, 255&
MsgBox computername
End Sub
4、读取注册表
Sub computer_name1()
MsgBox CreateObject("wscript.shell").regread("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName")
End Sub
5、调用WMI脚本
Sub computer_name2()
Set obj = GetObject("winmgmts:\\.\root\CIMV2")
Set objitm = obj.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each itm In objitm
MsgBox itm.Name
Next
End Sub