问一个VSB的问题
小弟初学者,最近在写一段PING IP和输出PC信息的VBS脚本,现在成果如下PING IP的脚本
strSubNet = "10.10.1."
Set objFSO= CreateObject("Scripting.FileSystemObject")
Set objTS = objfso.CreateTextFile("d:PingResult.txt")
For i = 1 To 254
strComputer = strSubNet & i
blnResult = Ping(strComputer)
If blnResult = True Then
objTS.WriteLine "Ping " & strComputer & " success!"
End If
Next
Next
objTS.Close
WScript.Echo "Done!"
Function Ping(strComputer)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_PingStatus Where Address='" & strComputer & "'")
For Each objItem In colItems
Select case objItem.StatusCode
Case 0
Ping = True
Case Else
Ping = False
End select
Exit For
Next
End Function
然后这个是输出PC信息的
strComputer = "10.10.1.50"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter")
For Each objItem in colItems
'If objItem.PhysicalAdapter Then
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "MACAddress: " & objItem.MACAddress
Wscript.Echo "AdapterType: " & objItem.AdapterType
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo "SystemName: " & objItem.SystemName
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo
'End If
Next
但是不知道怎么把2个代码并起来,我的意图在于在一个程序里做2个功能,就是自动PING 局域网里(公司内部所有电脑)IP一个一个ping下来,ping成功的就输出PC的部分信息,不成功的就跳过,望大神们指导下!