vbs查询局域网内电脑的软件和硬件列表清单
下面的代码在windows下容易报毒大家可以放心使用
'========================================================================== ' 'Date:2009/3/19 'Name:查询软件和硬件列表清单 'Author:Smileruner 'www.overmcse.com '不支持Win2000及WinNT ' '3/19,添加了网卡过滤。 '========================================================================== 'onerrorresumeNext constHKEY_LOCAL_MACHINE=&H80000002 constUNINSTALL_ROOT="Software\Microsoft\Windows\CurrentVersion\Uninstall" constREG_SZ=1 'Setwshshell=wscript.createobject("wscript.shell") 'wshshell.run("%comspec%/cregsvr32/sscrrun.dll"),0,true 'wshshell.run("%comspec%/cscconfigwinmgmtstart=auto"),0,true 'wshshell.run("%comspec%/cnetstartwinmgmt"),0 strComputer=Inputbox("请输入要查询的计算机名称",,"") IfstrComputer=""then Wscript.Echo"未输入值或用户取消,查询退出。" Wscript.Quit EndIf Setobjswbemlocator=createobject("wbemscripting.swbemlocator") Setobjswbemservices=objswbemlocator.connectserver(strComputer,"root\cimv2") IfErr.number<>0then Wscript.Echo"目标计算机无法连接。错误的计算机名,或目标计算机启用了防火墙,RPC服务不可用。" Err.number.clear Wscript.Quit EndIf 'swbemservices.security_.impersonationleobjvel=3 Setfso=createobject("scripting.filesystemobject") FileDate=Replace(date(),"/","-") resoultfilepath=strComputer&FileDate&".html" SetresultFile=fso.createtextfile(resoultfilepath,,true) HtmlWriteHead() 'Html文档开始 TableHeadstrComputer,"硬件清单" 'Html表格开始 OsWrite() '写入操作系统信息 BoardWrite() '写入主板信息 CpuWrite() '写入CPU信息 MemoryWrite() '写入内存信息 HarddiskWrite() '写入硬盘信息 CdromWrite() '写入CDROM信息 VideoWrite() '写入显示卡信息 NetcardWrite() '写入网卡信息 TableEnd() 'Html表格结尾 TableHeadstrComputer,"软件清单" 'Html表格开头 Softlist() '写入软件信息 TableEnd() 'Html表格结尾 HtmlWriteEnd() 'Html文档结束 ResultFile.close Wscript.Echo"查询完成!" '=========以下是函数列表========== FunctionOsWrite() '函数,写入操作系统信息 SetcolOs=objswbemservices.execquery("select*fromwin32_operatingsystem",,48) ForEachOsitemIncolOs oscaption=Ositem.caption OsVersion=oscaption&Ositem.version WriteTable"操作系统",OsVersion Next EndFunction FunctionBoardWrite() '函数,写入主板信息 SetcolBoard=objswbemservices.execquery("select*fromwin32_baseboard") ForEachBditemIncolBoard boardname=Bditem.product WriteTable"主板",boardname Next EndFunction FunctionCpuWrite() '函数,写入CPU信息 SetcolCpu=objswbemservices.execquery("select*fromwin32_processor") ForEachitemincolCpu cpuname=(trim(item.name)) WriteTable"中央处理器",cpuname Next EndFunction FunctionMemoryWrite() '函数,写入内存信息 mtotal=0 num=0 mill=0 SetcolMemory=objswbemservices.execquery("select*fromwin32_physicalmemory",,48) ForEachobjitemIncolMemory mill=objitem.capacity/1048576 WriteTable"单根内存容量",mill&"M" mtotal=mtotal+mill num=num+1 Next WriteTable"总计内存",num&"条"&"一共"&mtotal&"M" EndFunction FunctionHarddiskWrite() '函数,写入硬盘信息 SetcolDisk=objswbemservices.execquery("select*fromwin32_diskdrive",,48) ForEachobjitemIncolDisk diskname=objitem.caption disksize=fix(objitem.size/1073741824) WriteTable"硬盘",diskname&"容量:"&disksize&"G" Next EndFunction FunctionCdromWrite() '函数,写入CDROM信息 SetcolCdrom=objswbemservices.execquery("select*fromwin32_cdromdrivewherescsitargetid=0") ForEachobjitemIncolCdrom cdname=objitem.name WriteTable"光驱",cdname Next EndFunction FunctionvideoWrite() '函数,写入显示卡信息 SetcolVideo=objswbemservices.execquery("select*fromwin32_videocontroller",,48) ForEachobjitemincolVideo videoname=(trim(objitem.caption)&(objitem.videomodedescription)) WriteTable"显示卡",videoname Next EndFunction FunctionnetcardWrite() '函数,查询网卡信息 SetcolNetcards=objswbemservices.execquery("select*fromwin32_networkadapter") ForEachobjNetcardincolNetcards IfNotIsNull(objNetcard.NetConnectionID)Then NetCardName=objNetcard.productname WriteTable"网卡名称",NetCardName IfobjNetcard.NetConnectionStatus=2Then NetCardMac=objNetcard.macaddress WriteTable"网卡Mac",NetCardMac strQueryIp="select*fromwin32_networkadapterconfiguration"&_ "whereIPEnabled=true"&_ "andmacaddress='"&objNetcard.macaddress&"'" SetcolNetcardCfgs=objswbemservices.execquery(strQueryIp) ForEachobjNetcardCfgincolNetcardCfgs ForEachCfgAdrressinobjNetcardCfg.IPAddress IpAdrress=CfgAdrress WriteTable"IP地址",IpAdrress Next Next Else NetCardMac="网卡被禁用或未连接。" WriteTable"网卡Mac",NetCardMac IpAdrress="网卡被禁用或未连接。" WriteTable"IP地址",IpAdrress EndIf Endif Next EndFunction Functionsoftlist() '函数,写入软件信息 SetStdOut=WScript.StdOut SetoReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_ strComputer&"\root\default:StdRegProv") strKeyPath=UNINSTALL_ROOT oReg.EnumKeyHKEY_LOCAL_MACHINE,strKeyPath,arrSubKeys ForEachstrSubKeyInarrSubKeys IfNotHotfix(strSubKey)Then SoftNameAndVersion=getProgNameAndVersion(oReg,strKeyPath&"\"&strSubKey) IfSoftNameAndVersion<>"0"Then WriteTable"软件",SoftNameAndVersion EndIf EndIf Next EndFunction FunctionNotHotfix(sSubKey) IfLeft(sSubkey,2)="KB"Andlen(sSubkey)=8Then NotHotfix=0 ElseNotHotfix=1 Endif EndFunction FunctiongetProgNameAndVersion(oReg,sKeyRoot) DimsKeyValuesAry,iKeyTypesAry,nCnt,sValue,sDisplayName,sDisplayVersion oReg.EnumValuesHKEY_LOCAL_MACHINE,sKeyRoot,sKeyValuesAry,iKeyTypesAry IfNOTIsArray(sKeyValuesAry)Then getProgNameAndVersion=0 ExitFunction EndIf FornCnt=0ToUBound(sKeyValuesAry) IfInStr(1,sKeyValuesAry(nCnt),"DisplayName",vbTextCompare)Then IfiKeyTypesAry(nCnt)=REG_SZThen oReg.GetStringValueHKEY_LOCAL_MACHINE,sKeyRoot,sKeyValuesAry(nCnt),sValue IfsValue<>""Then sDisplayName=sValue sDisplayName=Replace(sDisplayName,"[","(") sDisplayName=Replace(sDisplayName,"]",")") EndIf EndIf ElseIfInStr(1,sKeyValuesAry(nCnt),"DisplayVersion",vbTextCompare)Then IfiKeyTypesAry(nCnt)=REG_SZThen oReg.GetStringValueHKEY_LOCAL_MACHINE,sKeyRoot,sKeyValuesAry(nCnt),sValue IfsValue<>""ThensDisplayVersion=sValue EndIf EndIf If(sDisplayName<>"")AND(sDisplayVersion<>"")Then getProgNameAndVersion=sDisplayName&"--版本号:"&sDisplayVersion ExitFunction ElsegetProgNameAndVersion=0 EndIf Next IfsDisplayName<>""Then getProgNameAndVersion=sDisplayName ExitFunction EndIf EndFunction FunctionWriteTable(caption,value) '函数,将数据写入HTML单元格 resultFile.Writeline"" resultFile.Writeline" " EndFunction FunctionHtmlWriteHead() '函数,写入THML文件头 resultFile.Writeline"" resultFile.Writeline"" resultFile.Writeline""&caption&"" resultFile.Writeline" "&value&"" resultFile.Writeline" 软硬件配置清单 " resultFile.Writeline"" resultFile.Writeline"" EndFunction FunctionHtmlWriteEnd() '函数,写入Html文件尾 resultFile.Writeline"" resultFile.Writeline"" EndFunction FunctionTableHead(pcname,str) '函数,写入Html表格结尾 resultFile.Writeline""&pcname&str&"--date:"&now()&"
"&VbCrLf resultFile.Writeline"" resultFile.Writeline" " resultFile.Writeline" " strstyle="资产类型" resultFile.Writeline" 查询结果值" resultFile.Writeline" " EndFunction FunctionTableEnd() '函数,Html表格结尾 resultFile.Writeline"" EndFunction
vbs判断操作系统
strComputer="." SetobjWMIService=GetObject("winmgmts:\\"&strComputer&"\root\cimv2") SetcolItems=objWMIService.ExecQuery("Select*fromWin32_OperatingSystem") ForEachobjItemincolItems strOSVersion=objItem.Version Next wscript.echostrOSversion selectcasestrOSversion case"5.2.3790" wscript.echo"WindowsServer2003" case"5.0.2195" wscript.echo"Windows2000" case"5.1.2600" wscript.echo"WindowsXP" case"6.0.6001" wscript.echo"windowsvisita" Case"6.1.7601" wscript.echo"WindowsServer2008r2" caseelse wscript.echo"idon'tknow" endselect
到此这篇关于vbs查询局域网内电脑的软件和硬件列表清单的文章就介绍到这了,更多相关查询软件和硬件列表清单内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!