我正在尝试在 vbscript 中编写脚本,但作为一个近乎菜鸟和在线教程不起作用,我不得不求助于在这里发帖寻求帮助。
我从不同来源混合和匹配的脚本显示域、用户、计算机名、IP 地址。脚本正在运行。但是在某些环境中,一个用户可能有多个 IP 地址,当在 MsgBox 中显示时,只返回最后一个 IP 地址结果,在许多情况下,这是错误的。
我想知道如何在数组中添加/存储地址,如果有多个结果,则让 MsgBox 显示其他 IP 地址。
谢谢你。
下面附上脚本:
Option Explicit
DIM WshNetwork, strComputer, IPConfigSet, objWMIService, IPConfig, i, j, strIP, title, message, colItems, objItem
DIM arrIPAddress, columnC, strIPAddress, testIP(3)
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration",,48)
For Each objItem in colItems
If isNull(objItem.IPAddress) Then
Else
Wscript.Echo "IPAddress: " & Join(objItem.IPAddress, ",")
strIP = objItem.IPAddress(0)
End If
Next
title = "Who Am I?"
message = "Domain: " & vbTab & vbTab & WshNetwork.UserDomain & VbCrlf & _
"User Name: " & vbTab & UCase(WshNetwork.UserName) & VbCrlf & _
"Computer Name: " & vbTab & WshNetwork.ComputerName & VbCrlf & _
"IP Address1: " & vbTab & strIP
Msgbox message, , title