vbs查询局域网内电脑的软件和硬件列表清单
程序员文章站
2022-06-10 07:54:26
下面的代码在windows下容易报毒大家可以放心使用vbs判断操作系统到此这篇关于vbs查询局域网内电脑的软件和硬件列表清单的文章就介绍到这了,更多相关查询软件和硬件列表清单内容请搜索萬仟网以前的文章...
下面的代码在windows下容易报毒大家可以放心使用
'========================================================================== ' ' date:2009/3/19 ' name: 查询软件和硬件列表清单 ' author:smileruner ' www.overmcse.com ' 不支持win2000及winnt ' ' 3/19,添加了网卡过滤。 '========================================================================== 'on error resume next const hkey_local_machine = &h80000002 const uninstall_root = "software\microsoft\windows\currentversion\uninstall" const reg_sz = 1 'set wshshell=wscript.createobject("wscript.shell") ' wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,true ' wshshell.run ("%comspec% /c sc config winmgmt start= auto"),0,true ' wshshell.run ("%comspec% /c net start winmgmt"),0 strcomputer = inputbox("请输入要查询的计算机名称",,"") if strcomputer = "" then wscript.echo "未输入值或用户取消,查询退出。" wscript.quit end if set objswbemlocator = createobject("wbemscripting.swbemlocator") set objswbemservices = objswbemlocator.connectserver(strcomputer, "root\cimv2") if err.number <> 0 then wscript.echo "目标计算机无法连接。错误的计算机名,或目标计算机启用了防火墙,rpc服务不可用。" err.number.clear wscript.quit end if 'swbemservices.security_.impersonationleobjvel = 3 set fso=createobject("scripting.filesystemobject") filedate = replace(date(), "/", "-") resoultfilepath= strcomputer & filedate & ".html" set resultfile= fso.createtextfile(resoultfilepath,,true) htmlwritehead() 'html文档开始 tablehead strcomputer,"硬件清单" 'html表格开始 oswrite() '写入操作系统信息 boardwrite() '写入主板信息 cpuwrite() '写入cpu信息 memorywrite() '写入内存信息 harddiskwrite() '写入硬盘信息 cdromwrite() '写入cdrom信息 videowrite() '写入显示卡信息 netcardwrite() '写入网卡信息 tableend() 'html表格结尾 tablehead strcomputer,"软件清单" 'html表格开头 softlist() '写入软件信息 tableend() 'html表格结尾 htmlwriteend() 'html文档结束 resultfile.close wscript.echo "查询完成!" '=========以下是函数列表========== function oswrite() '函数,写入操作系统信息 set colos =objswbemservices.execquery("select * from win32_operatingsystem",,48) for each ositem in colos oscaption = ositem.caption osversion = oscaption & ositem.version writetable "操作系统",osversion next end function function boardwrite() '函数,写入主板信息 set colboard = objswbemservices.execquery("select * from win32_baseboard") for each bditem in colboard boardname = bditem.product writetable "主板",boardname next end function function cpuwrite() '函数,写入cpu信息 set colcpu =objswbemservices.execquery("select * from win32_processor") for each item in colcpu cpuname = (trim(item.name)) writetable "*处理器",cpuname next end function function memorywrite() '函数,写入内存信息 mtotal = 0 num = 0 mill = 0 set colmemory = objswbemservices.execquery("select * from win32_physicalmemory",,48) for each objitem in colmemory mill = objitem.capacity/1048576 writetable "单根内存容量",mill & "m" mtotal = mtotal+mill num = num + 1 next writetable "总计内存",num & "条" & "一共" & mtotal & "m" end function function harddiskwrite() '函数,写入硬盘信息 set coldisk = objswbemservices.execquery("select * from win32_diskdrive", , 48) for each objitem in coldisk diskname= objitem.caption disksize= fix(objitem.size/1073741824) writetable "硬盘",diskname & " 容量:" & disksize & "g" next end function function cdromwrite() '函数,写入cdrom信息 set colcdrom = objswbemservices.execquery("select * from win32_cdromdrive where scsitargetid=0") for each objitem in colcdrom cdname = objitem.name writetable "光驱",cdname next end function function videowrite() '函数,写入显示卡信息 set colvideo = objswbemservices.execquery("select * from win32_videocontroller", , 48) for each objitem in colvideo videoname = (trim(objitem.caption) & (objitem.videomodedescription)) writetable "显示卡",videoname next end function function netcardwrite() '函数,查询网卡信息 set colnetcards = objswbemservices.execquery("select * from win32_networkadapter") for each objnetcard in colnetcards if not isnull(objnetcard.netconnectionid) then netcardname = objnetcard.productname writetable "网卡名称",netcardname if objnetcard.netconnectionstatus = 2 then netcardmac = objnetcard.macaddress writetable "网卡mac",netcardmac strqueryip ="select * from win32_networkadapterconfiguration" &_ " where ipenabled = true" &_ " and macaddress = '" & objnetcard.macaddress & "'" set colnetcardcfgs = objswbemservices.execquery(strqueryip) for each objnetcardcfg in colnetcardcfgs for each cfgadrress in objnetcardcfg.ipaddress ipadrress = cfgadrress writetable "ip地址",ipadrress next next else netcardmac = "网卡被禁用或未连接。" writetable "网卡mac",netcardmac ipadrress = "网卡被禁用或未连接。" writetable "ip地址",ipadrress end if end if next end function function softlist() '函数,写入软件信息 set stdout = wscript.stdout set oreg=getobject("winmgmts:{impersonationlevel=impersonate}!\\" &_ strcomputer & "\root\default:stdregprov") strkeypath = uninstall_root oreg.enumkey hkey_local_machine, strkeypath, arrsubkeys for each strsubkey in arrsubkeys if nothotfix(strsubkey) then softnameandversion = getprognameandversion(oreg,strkeypath & "\" & strsubkey) if softnameandversion<>"0" then writetable "软件",softnameandversion end if end if next end function function nothotfix(ssubkey) if left(ssubkey,2) = "kb" and len(ssubkey) = 8 then nothotfix = 0 else nothotfix = 1 end if end function function getprognameandversion(oreg,skeyroot) dim skeyvaluesary, ikeytypesary, ncnt, svalue, sdisplayname, sdisplayversion oreg.enumvalues hkey_local_machine, skeyroot, skeyvaluesary, ikeytypesary if not isarray(skeyvaluesary) then getprognameandversion = 0 exit function end if for ncnt = 0 to ubound(skeyvaluesary) if instr(1, skeyvaluesary(ncnt), "displayname", vbtextcompare) then if ikeytypesary(ncnt) = reg_sz then oreg.getstringvalue hkey_local_machine, skeyroot, skeyvaluesary(ncnt), svalue if svalue<>"" then sdisplayname = svalue sdisplayname = replace(sdisplayname, "[", "(") sdisplayname = replace(sdisplayname, "]", ")") end if end if elseif instr(1, skeyvaluesary(ncnt), "displayversion", vbtextcompare) then if ikeytypesary(ncnt) = reg_sz then oreg.getstringvalue hkey_local_machine, skeyroot, skeyvaluesary(ncnt), svalue if svalue<>"" then sdisplayversion = svalue end if end if if (sdisplayname<>"") and (sdisplayversion<>"") then getprognameandversion = sdisplayname & " --版本号: " & sdisplayversion exit function else getprognameandversion = 0 end if next if sdisplayname<>"" then getprognameandversion = sdisplayname exit function end if end function function writetable(caption,value) '函数,将数据写入html单元格 resultfile.writeline "<tr>" resultfile.writeline "<td align=""left"" width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""row""> " & caption & "</td>" resultfile.writeline "<td bgcolor=""#ffffff""> " & value & "</td>" resultfile.writeline "</tr>" end function function htmlwritehead() '函数,写入thml文件头 resultfile.writeline "<html>" resultfile.writeline "<head>" resultfile.writeline "<title>软硬件配置清单</title>" resultfile.writeline "</head>" resultfile.writeline "<body>" end function function htmlwriteend() '函数,写入html文件尾 resultfile.writeline "</body>" resultfile.writeline "</html>" end function function tablehead(pcname,str) '函数,写入html表格结尾 resultfile.writeline "<h3>" & pcname & str & " -- date:"&now()&" </h3>" & vbcrlf resultfile.writeline "<table width=""90%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1"" bgcolor=""#0000ff"">" resultfile.writeline "<tr>" resultfile.writeline "<th width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""col"">资产类型</th>" resultfile.writeline "<th bgcolor=""#ffffff"" scope=""col"">查询结果值</th>" resultfile.writeline "</tr>" strstyle = "<th width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""row"">" end function function tableend() '函数,html表格结尾 resultfile.writeline "</table>" end function
vbs判断操作系统
strcomputer = "." set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2") set colitems = objwmiservice.execquery("select * from win32_operatingsystem") for each objitem in colitems strosversion = objitem.version next wscript.echo strosversion select case strosversion case "5.2.3790" wscript.echo "windows server 2003" case "5.0.2195" wscript.echo "windows 2000" case "5.1.2600" wscript.echo "windows xp" case "6.0.6001" wscript.echo "windows visita" case "6.1.7601" wscript.echo "windows server 2008 r2" case else wscript.echo "i don't know" end select
到此这篇关于vbs查询局域网内电脑的软件和硬件列表清单的文章就介绍到这了,更多相关查询软件和硬件列表清单内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: Nginx虚拟主机的搭建的实现步骤
下一篇: 淘宝怎么购买冰墩墩?淘宝购买冰墩墩教程