我试图制作一个简单的脚本,显示计算机名称,登录的用户名,IP地址和以太网接口(有线)名称及其MAC:
intCount = 0
strMAC = ""
' We're interested in MAC addresses of physical adapters only
strQuery = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > ''"
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( strQuery, "WQL", 48 )
For Each objItem In colItems
If objItem.AdapterType = "Ethernet 802.3" then
If InStr( strMAC, objItem.MACAddress ) = 0 Then
strMAC = strMAC & ", " & objItem.MACAddress
Name = objItem.Name & vbCRLF
intCount = intCount + 1
End If
End If
Next
' Remove leading comma
If intCount > 0 Then strMAC = Mid( strMAC, 2 )
dim NIC1, Nic, StrIP, CompName
Set NIC1 =
GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(i)
Set WshNetwork = WScript.CreateObject("WScript.Network")
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
CompName = WshNetwork.Computername
Dim WMI, Configs, Config, Adapters, Adapter
Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}root/cimv2")
strUserName = wshNetwork.UserName
MsgBox "IP Adres: "&StrIP & vbNewLine _
& "Computer Name: "&CompName & vbNewLine _
& "Login: "&strUserName & vbNewLine _
& "Interface and MAC: "& Name, & strMAC ,4160,"Information about IP"
wscript.quit
end if
next
但它不起作用,有人可以帮助我吗?
答案 0 :(得分:0)
更改
Set NIC1 =
GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
到一行
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
并删除,在这里:
& "Interface and MAC: "& Name, & strMAC ,4160,"Information about IP"
==>
& "Interface and MAC: "& Name & strMAC ,4160,"Information about IP"