今天是:
设百科问答网为首页|收藏百科问答网|网站地图
百科问答网 - 帮您解决问题,分享成功经验

vbs收集计算机信息


目的:通过vbs脚本收集 局域网内计算机配置信息
方法:通过vbs脚本读取一文本文件内ip地址
问题:当遇到有ip地址不通时 会重复多次收集已经收集过的机器信息

//收集计算机信息
on error resume next

const input_file_name = "D:\lab\vbs\list.txt"
const for_reading = 1


set objfso = createobject("scripting.filesystemobject")
set objfile = objfso.opentextfile(input_file_name, for_reading)
strcomputers = objfile.readall
objfile.close

arrcomputers = split(strcomputers, vbcrlf)
strUser = "username"
strPwd = "password"
for each strcomputer in arrcomputers
Set objwmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objwmiService = objwmiLocator.ConnectServer(strComputer, "root\cimv2", strUser, strPwd)

Set objComputer = objwmiService.ExecQuery _
("select * from Win32_ComputerSystem ")
For Each objComputer In objComputer
WScript.Echo "ComputerName: " & objComputer.Name

Next

Set objCPUs = objwmiService.ExecQuery _
("select * from Win32_Processor ")
For Each objCPU In objCPUs
WScript.Echo "CPU: " & objCPU.Name

Next

Set objDisks = objwmiService.ExecQuery _
("Select * from Win32_DiskDrive ")
For Each objDisk in objDisks
Wscript.Echo "DiskModel: " & objDisk.model
Next

Set objMemory = objwmiservice.ExecQuery _
("select * from Win32_PhysicalMemory ")
For Each objMemory in objMemory
Wscript.Echo "MemoryModel: " & objMemory.Capacity/1024/1024 &"M"
Next

next




答案或建议:


因为设置了on error resume next , 所以遇到ConnectServer(...)失败,后面的语句依然执行了,这时后面的内容应该就是前一台机器搜集到的信息了。可以试试这样解决:

...
for each strcomputer in arrcomputers
Set objwmiLocator = CreateObject("WbemScripting.SWbemLocator")
Err.Clear
Set objwmiService = objwmiLocator.ConnectServer(strComputer, "root\cimv2", strUser, strPwd)

If Err.Number <> 0 Then
Wscript.echo "An Error Occurred: Erro Number=" & Err.Number & vbCrLf & Err.Description.vbCRLF
Else
Set objComputer = objwmiService.ExecQuery _
("select * from Win32_ComputerSystem ")
For Each objComputer In objComputer
WScript.Echo "ComputerName: " & objComputer.Name

Next

Set objCPUs = objwmiService.ExecQuery _
("select * from Win32_Processor ")
For Each objCPU In objCPUs
WScript.Echo "CPU: " & objCPU.Name

Next

Set objDisks = objwmiService.ExecQuery _
("Select * from Win32_DiskDrive ")
For Each objDisk in objDisks

Wscript.Echo "DiskModel: " & objDisk.model
Next

Set objMemory = objwmiservice.ExecQuery _
("select * from Win32_PhysicalMemory ")
For Each objMemory in objMemory
Wscript.Echo "MemoryModel: " & objMemory.Capacity/1024/1024 &"M"
Next

End If

next



文章转载请保留:http://www.baikewenda.com/tech/soft/8/11/a193476437.htm

推荐内容

敬请注意:百科问答网内容来源于网络或民间经验收集,仅供参考。其中有关健康疾病方面的内容请务必咨询专业医生或及时到医院治疗。
关于我们 - 广告服务 - 联系我们
百科问答网 Copyright ©2005 - 2011 www.baikewenda.com,All Rights Reserved
辽ICP备10007180号