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
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
» TC的属性标签怎么保存?
» 如何设置系统的自动更新
» 有用GA-MA78GPM-DS2H主板+XP系统的显存问题
» 笔记本电脑接离等子电视干扰问题
» 用电脑怎么样打开wmlc文件
» WORD怎么把每行第一个字都删掉?
» CAD图像如何能够清晰的复制到WORD文件
» android手机怎么发彩信
» VEGAS或AE怎么做到视频只有一部分有颜色
» 因iastor.sys引起的蓝屏问题
» Win7桌面上的程序快捷方式全都打不开了,怎么办?
» 为什么安装ie9时老是安装失败呢?
» Windows7 中文家庭高级版为什么不能激活?
» maya里按P键和约束里的父子有什么区别啊?
» AfterEffect CS3中怎么抠动态图
推荐内容
·怎样才能让刚买的电脑联上网
·如何在Win7下安装Autocad 2006?
·Excel =8*2 怎样显示为8*2
·Word中如何输入分数?
·QQ怎样在别的组前添加组?
·ReadyFor4GB在win7 sp1下失效的解决方法
·如何用A3拼页进行打印?
·office2007的自定义快速访问工具栏怎么备份?
·QQ聊天记录的挽救方法?
·请问EMULE的搜索记录怎么删除
·什么软件可以临时关闭笔记本电脑的触摸板?
·Word中A4纸打印从中间对折装订怎样设置?
·WIN2003上如何安装ADOBE CS3
·什么软件可以快速播放图片用来抽奖
·怎么删掉WORD(或EXCEL)文件下拉菜单中的文档(或文件)名?
·如何使下载的文件默认为迅雷下载
·如何彻底删除skype的文本聊天记录
·有没有支持书签功能的文本编辑器?
·怎么将CAD格式的图转换为PDF或JPG的格式