用vbs实现获取电脑硬件信息的脚本_最新版第1/4页
- 作者: 奇葩不懂爱
- 来源: 51数据库
- 2021-07-08
代码一:
'*******************************************************************************************
'version:3.1
' 调整错误处理方法,错误信息输出到logfile文件,可以查看扫描失败原因
' 如果出现“rpc 服务器不可用”错误,是因为远程主机没开机
' 如果出现“rpc 服务器不可用”之外的错误,可能是由于正在运行的程序造成,请你把此信息告诉我
' 重启后再次扫描就可以排除非“rpc 服务器不可用。”的错误
' 如果扫描到的硬件信息为空,应该是驱动问题(或bios不完善),请自行解决
'version:3.0
' 增加输出bios的发行日期,和主板信息放在一起
'version:2.9
' 修正所有getinfo过程遇错的处理方法,避免返回的数组上限不符合输出要求导致脚本报错。
' 之所以为出现这种情况,是因为win32类检索不到硬件或连接到win32类失败;
' 原来判断是否出现err,忽略了检索不到硬件的情况(连接成功无err,count为0)
' 检索不到硬件多数是因为驱动没装好
'version:2.8
' 增加getideprotocol过程,获取ide控制器使用的协议,只是增加了代码,没有调用
' 计划增加检索其它存储器控制器的过程
'version:2.7
' 检索硬盘/显卡/网卡/声卡的过程增加 deviceid 属性(设备标识符)
' 此属性不被输出,用于脚本内部判断
'version:2.6
' 原来输出搜索到的第一个硬盘
' 改为输出搜索到的第一个interfacetype属性为ide的硬盘的信息
'version:2.5
' 增加sort过程,排序硬件信息
'version:2.4
' 调整输出信息的分类,同类信息尽可能的只使用一个逗号分隔,以便导入xls后在同一列
' 查询到的硬件信息如果是空或0,有可能是相关驱动不完善或未定义此信息,也可能是未安装驱动
' 因为wmi查询就代表了系统知道这些硬件的详细信息,查不到信息就是系统不知道
' 系统不知道硬件的详细信息,代表着性能可能有所缺失,建议找个好驱动安装
' 值得注意的是主板驱动
' (为了更容易理解,此版本的升级信息被编辑过)
'version:2.3
' 取消2.2版增加输出的硬盘接口类型
' 由于stat也归于ide接口,这会导致误解
' ps:脚本只输出搜索到的第一个硬盘
'version:2.2
' getmemoryinfo过程增加memorytype、formfactor、typedetail三个属性
' 输出增加内存类型、封装类型
' 输出增加硬盘容量、接口类型
'version:2.1
' getosinfo过程增加去掉caption属性中带有的逗号“,”的代码
' 原因:在检测2003系统时,读取到的caption属性,带有逗号“,”
' 这会影响输出,因为输出是以逗号“,”为分隔符的
'version:2.0 b5发布版
' getnetworkinfo过程改为使用macaddress属性非空、
' manufacturer属性非"microsoft"判断网卡
'version:2.0 beta4
' getnetworkinfo过程使用netconnectionstatus属性判断网络适配器
' netconnectionstatus属性表明连接状态(2000系统不支持此属性)
' 物理网络适配器才具有此状态(包括停用状态在内)
'version:2.0 beta3
' getnetworkinfo过程增加一个判断
' 忽略读取ipaddress(0)时会产生err类型数据的适配器(对战平台)
'version:2.0 beta2
' getosinfo过程原来使用的name、servicepackmajorversion属性
' 改为使用caption、csdversion属性
' 所有getinfo过程增加错误处理代码,避免正在扫描的时候
' 脚本遇到运行时错误导致脚本退出
'version:2.0 beta1
' 增加扫描失败记录,再次运行脚本只读取失败记录,忽略配置信息
'version:1.1
' getnetworkinfo过程增加一个判断
' 忽略netconnectionid属性(接口名称)为空的适配器
'version:1.0
' 初始版本
option explicit
'**************************************
'作 者: lz-myst qq:8450919
'http://www.51sjk.com/Upload/Articles/1/0/256/256226_20210629002520135.jpg
'http://www.51sjk.com/Upload/Articles/1/0/256/256226_20210629002520150.cn
'e-mail:lzmyst@163.com
'你可以任意编辑、引用脚本的全部或部分代码
'转贴、引用脚本的全部或部分代码请保留版权
'**************************************
'********************************说明开始*************************************
'input格式:起始ip-数量=用户名=密码;起始计算机名-数量=用户名=密码
' 多个配置项用“;”隔开
'例:192.168.0.1-10指明ip范围为192.168.0.1~192.168.0.10,支持跨网段
'例:pc001-10指明范围为pc001~pc010(计算机名可以包含-号)
'与指定格式不相同的,默认为单ip[计算机名],也可以在"未扫描的计算机.txt"里配置
'"硬件信息.txt"是以逗号分隔各项硬件信息,你需要自己导入xls整理、精简
'未扫描到的计算机,会把机号、用户名、密码保存到"未扫描的计算机.txt"
'再次运行脚本将只读取"未扫描的计算机.txt"里的信息(如果存在并且大小不为0)
'********************************说明结束*************************************
dim input, infooutfile, logfile '请按格式给input赋值
'input = "pc021=administrator=cylslynetbar"
input = "pc001-109=administrator=cylslynetbar;pc110-85=administrator=lyjfnetbaradmin"
infooutfile = "硬件信息.txt"
logfile = "未扫描的计算机.txt"
redim arrconfig(0)
dim wshshell, fso, intcount1, intcount2
intcount1 = 0
intcount2 = 0
set wshshell = wscript.createobject("wscript.shell")
set fso = wscript.createobject("scripting.filesystemobject")
readconfig
wshshell.popup "扫描过程会很慢,请耐心等待,完成后会给出提示",,"扫描开始"
linkremoteserver arrconfig
dim lennum1, lennum2
if intcount1 > intcount2 then
lennum1 = 0
lennum2 = len(intcount1) - len(intcount2)
else
lennum1 = len(intcount2) - len(intcount1)
lennum2 = 0
end if
sort infooutfile
wshshell.popup "扫描结果:" & _
vbcrlf & vbtab & "扫描成功:" & space(lennum1) & intcount1 & " 台" & _
vbcrlf & vbtab & "扫描失败:" & space(lennum2) & intcount2 & " 台" & _
vbcrlf & "扫描失败的电脑已做记录,再次运行脚本只扫描记录里的电脑",,"扫描完成"
function readconfig
dim objmatches, objmatche,objlogfile, arrlog, intubarrconfig
if fso.fileexists(logfile) then
if fso.getfile(logfile).size = 0 then
set objmatches = getmatche("([^;=]+)=([^;=]+)=([^;=]+)", input)
for each objmatche in objmatches
getconfig objmatche.submatches(0), objmatche.submatches(1), objmatche.submatches(2)
next
if objmatches.count = 0 then
msgbox "配置信息格式不正确,请修改"
wscript.quit
end if
else
set objlogfile = fso.opentextfile(logfile)
do until objlogfile.atendofstream
arrlog = split(objlogfile.readline,"=")
intubarrconfig = ((ubound(arrconfig)+1)\3+1)*3-1
redim preserve arrconfig(intubarrconfig)
arrconfig(intubarrconfig-2) = arrlog(0)
arrconfig(intubarrconfig-1) = arrlog(1)
arrconfig(intubarrconfig-0) = arrlog(2)
loop
end if
else
set objmatches = getmatche("([^;=]+)=([^;=]+)=([^;=]+)", input)
for each objmatche in objmatches
getconfig objmatche.submatches(0), objmatche.submatches(1), objmatche.submatches(2)
next
if objmatches.count = 0 then
msgbox "配置信息格式不正确,请修改"
wscript.quit
end if
end if
end function
'*********************************************************************************
'目的:连接到远程主机的wmi命名空间
'输入:arrarray数组,包含有计算机名[ip]、用户名、密码
'调用:linkserver过程
' 如果返回swbemlocator对象connectserver方法的实例,调用outinfo过程
' 如果返回err信息(字符串类型),输出计算机名[ip]、用户名、密码及错误信息到logfile文件
' outinfo过程
' 如果返回err信息(字符串类型)输出计算机名[ip]、用户名、密码及错误信息到logfile文件
'传递:swbemlocator对象connectserver方法的实例传递给outinfo过程
' 计算机名[ip]、命名空间、用户名、密码传递给linkserver过程
'*********************************************************************************
function linkremoteserver(arrarray)
dim objerrlog, e, objlinkserver, objconnection, objwbemlocator, objerr
set objwbemlocator = createobject("wbemscripting.swbemlocator")
set objerrlog = fso.createtextfile(logfile,true)
for e = 0 to ubound(arrarray) step 3
set objlinkserver = linkserver(arrconfig(e),"root\cimv2",arrconfig(e+1),arrconfig(e+2))
if err then
objerrlog.writeline arrarray(e) & "=" & arrarray(e+1) & "=" & arrarray(e+2) & "=" & _
"错误编号:" & cstr(err.number) & _
",错误原因:" & cstr(err.description) & _
",错误来源:" & cstr(err.source) & " by linkserver function"
intcount2 = intcount2 + 1
err.clear
else
objerr = outinfo(objlinkserver)
if vartype(objerr) = 8 then
objerrlog.writeline arrarray(e) & "=" & arrarray(e+1) & "=" & arrarray(e+2) & "=" & objerr
intcount2 = intcount2 + 1
end if
end if
next
end function
'******************************************************
'目的:输出硬件信息
'输入:swbemlocator对象connectserver方法的实例
'调用:获取硬件信息的getxxxinfo过程
'传递:swbemlocator对象connectserver方法的实例
'返回:所有调用的getinfo过程都未返回err对象,则返回true
' 某个getinfo过程返回err对象,则返回false
'******************************************************
function outinfo(objremote)
dim outfile, arrinfo, stroutinfo, tmp, a
if fso.fileexists(infooutfile) then
set outfile = fso.opentextfile(infooutfile,8)
else
set outfile = fso.createtextfile(infooutfile)
outfile.writeline "计算机名,系统(初装日期),主板型号(厂商)(发行日期),cpu型号(接口类型),外频,l2容量(速度)," & _
"内存总量,内存速度(位置),内存类型(封装类型),硬盘型号(容量),显卡型号(显存),网卡,ip/mac"
end if
'系统
arrinfo = getosinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
stroutinfo = arrinfo(0) & "," & arrinfo(1) & "(" & arrinfo(2) & "),"
'主板
arrinfo = getboardinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
stroutinfo = stroutinfo & arrinfo(0) & "(" & arrinfo(1) & ")"
'bios
arrinfo = getbiosinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
stroutinfo = stroutinfo & "(" & arrinfo(2) & "),"
'cpu
arrinfo = getcpuinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
stroutinfo = stroutinfo & arrinfo(1) & "(" & arrinfo(8) & ")," & arrinfo(4) & "," & _
arrinfo(6) & "(" & arrinfo(7) & "),"
'内存
arrinfo = getmemoryinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
tmp = 0
for a = 1 to ubound(arrinfo) step 6
tmp = tmp + cint(arrinfo(a))
next
stroutinfo = stroutinfo & arrinfo(0) & "条,共" & tmp & "m,"
tmp = ""
for a = 2 to ubound(arrinfo) step 6
if a = ubound(arrinfo) - 4 then
tmp = tmp & arrinfo(a) & "(" & arrinfo(a+1) & "),"
else
tmp = tmp & arrinfo(a) & "(" & arrinfo(a+1) & ") "
end if
next
stroutinfo = stroutinfo & tmp
tmp = ""
for a = 4 to ubound(arrinfo) step 6
if a = ubound(arrinfo) - 2 then
tmp = tmp & arrinfo(a) & "(" & arrinfo(a+1) & "),"
else
tmp = tmp & arrinfo(a) & "(" & arrinfo(a+1) & ") "
end if
next
stroutinfo = stroutinfo & tmp
'硬盘
tmp = ""
arrinfo = getdiskinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
for a = 1 to ubound(arrinfo) step 5
if arrinfo(a+1) = "ide" then
tmp = arrinfo(a) & "(" & arrinfo(a+2) & "g),"
exit for
end if
next
if tmp = "" then
stroutinfo = stroutinfo & "硬盘型号未检索到,"
else
stroutinfo = stroutinfo & tmp
end if
'显卡
arrinfo = getvideoinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
stroutinfo = stroutinfo & arrinfo(0) & "(" & arrinfo(1) & "m),"
'网卡
arrinfo = getnetworkinfo(objremote)
if vartype(arrinfo) = 8 then
outinfo = arrinfo
exit function
end if
stroutinfo = stroutinfo & arrinfo(1) & "," & arrinfo(2) & space(17-len(arrinfo(2))) & arrinfo(3)
'输出
outfile.writeline stroutinfo
intcount1 = intcount1 + 1
outinfo = true
end function
'*********************************************************
'目的:连接到远程主机的wmi命名空间
'输入:strcomputer:远程主机的计算机名或ip
' strnamespace:命令空间
' strusername:用户名
' strpassword:密码
'返回:连接成功,返回swbemlocator类连接远程主机后的对象的实例
' 连接失败,返回错误对象
'*********************************************************
function linkserver(strcomputer,strnamespace,strusername,strpassword)
dim objwbemlocator
set objwbemlocator = createobject("wbemscripting.swbemlocator")
dim objconnection
on error resume next
set objconnection = objwbemlocator.connectserver _
(strcomputer, strnamespace, strusername, strpassword)
if err then
set linkserver = err
exit function
end if
on error goto 0
objconnection.security_.impersonationlevel = 3
set linkserver = objconnection
end function
'******************************************
'目的:正则表达式
'输入:strpatrn:正则表达式模式
' strstring:要执行正则表达式的字符串
'返回:match对象
'******************************************
function getmatche(strpatrn, strstring)
dim regex
set regex = new regexp
regex.global = true
regex.ignorecase =true
regex.pattern = strpatrn
set getmatche = regex.execute(strstring)
end function
'***************************************
'目的:2、8、16进制转10进制
'输入:strstring:2、8、16进制数
' intnum:进制(2|8|16)
'返回:10进制数
'***************************************
function changetodecimal(strstring, intnum)
changetodecimal = 0
if isnull(strstring) then changetodecimal = 0 : exit function
dim a, m
for a = 1 to len(strstring)
m = lcase(mid(strstring, a, 1))
select case m
case "a" :m = 10
case "b" :m = 11
case "c" :m = 12
case "d" :m = 13
case "e" :m = 14
case "f" :m = 15
end select
changetodecimal = changetodecimal + m * intnum^(len(strstring)-a)
next
end function
1234下一页阅读全文
您可能感兴趣的文章:用vbs控制鼠标的实现代码(获取鼠标坐标、鼠标移动、鼠标单击、鼠标双击、鼠标右击)获取外网ip并发送到指定邮箱的vbs代码[已测]vbs 获取当前目录的实现代码vbs获取当前目录下所有文件夹名字的代码vbs获取当前时间日期的代码vbscript获取文件的创建时间、最后修改时间和最后访问时间的方法vbs中获取脚本当前路径的2个方法通过vbs获取远程host文件并保存到指定目录vbscript获取cpu使用率的方法使用vbs获取雅虎汇率
相关文章
vbs脚本实现修改dns和清空ie临时文件功能
这篇文章主要介绍了vbs脚本实现修改dns和清空ie临时文件功能,本文直接给出实现两种功能的脚本代码,需要的朋友可以参考下2015-02-02- 这篇文章主要介绍了vbs 定时删除功能实现代码,需要的朋友可以参考下2014-05-05
vbs编程教程第一部
2008-01-01
vbs md5加密算法代码
vbs md5加密算法代码,需要的朋友可以参考下。2009-12-12
vbscript 中的字节数据操作函数
vbscript 中的字节数据操作函数...2006-06-06
用vbs实现解除注册表cmd、regedit、taskmgr限制的脚本代码
vbs解除cmd、regedit、taskmgr限制的代码2008-06-06
运行同一目录下的可执行程序的vbs代码
运行同一目录下的可执行程序的vbs代码,需要的朋友可以参考下。2011-01-01- 飘叶千夫指源代码,又称qq刷屏器...2006-10-10
vbs 两数相加取值问题分析
vbs中通过intpu传值进行运算的方法,需要的朋友可以参考下。2011-03-03- 这篇文章主要介绍了vbs脚本实现批量转换文件编码,可以批量对文件在gb2312和utf-8编码间互相转换,需要的朋友可以参考下2014-06-06
推荐阅读

最新评论