一个获取计算机硬件信息和安装软件清单的脚本

2024-01-30 12:38

本文主要是介绍一个获取计算机硬件信息和安装软件清单的脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

'==========================================================================
'
' Date:2009/3/19
' Name: 查询软件和硬件列表清单
' Comment: blogs.itecn.net/smileruner
' Author:Smileruner
' www.overmcse.com
' 不支持Win2000及WinNT
'
' 3/19,添加了网卡过滤。
'==========================================================================
'on error resume Nextconst 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"),0strComputer = Inputbox("请输入要查询的计算机名称",,"")If strComputer = "" thenWscript.Echo "未输入值或用户取消,查询退出。"Wscript.Quit
End IfSet objswbemlocator = createobject("wbemscripting.swbemlocator")
Set objswbemservices = objswbemlocator.connectserver(strComputer, "root\cimv2")
If Err.number <> 0 thenWscript.Echo "目标计算机无法连接。错误的计算机名,或目标计算机启用了防火墙,RPC服务不可用。"Err.number.clearWscript.Quit
End If'swbemservices.security_.impersonationleobjvel = 3Set 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 colOsoscaption = Ositem.captionOsVersion = oscaption & Ositem.versionWriteTable "操作系统",OsVersionNext
End Function Function BoardWrite()'函数,写入主板信息Set colBoard = objswbemservices.execquery("select * from win32_baseboard")For Each Bditem In colBoardboardname = Bditem.productWriteTable "主板",boardnameNext
End Function Function CpuWrite()'函数,写入CPU信息Set colCpu =objswbemservices.execquery("select * from win32_processor")For Each item in colCpucpuname =  (trim(item.name))WriteTable "中央处理器",cpunameNext
End Function Function MemoryWrite()'函数,写入内存信息
mtotal        = 0
num         = 0
mill         = 0Set colMemory = objswbemservices.execquery("select * from win32_physicalmemory",,48)For Each objitem In colMemorymill = objitem.capacity/1048576WriteTable "单根内存容量",mill & "M"mtotal = mtotal+millnum = num + 1NextWriteTable "总计内存",num & "条" & "一共" & mtotal & "M"
End Function Function HarddiskWrite()'函数,写入硬盘信息Set colDisk = objswbemservices.execquery("select * from win32_diskdrive", , 48)For Each objitem In colDiskdiskname= objitem.captiondisksize= 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 colCdromcdname = objitem.nameWriteTable "光驱",cdnameNext
End FunctionFunction videoWrite()'函数,写入显示卡信息Set colVideo = objswbemservices.execquery("select * from win32_videocontroller", , 48)For Each objitem in colVideovideoname = (trim(objitem.caption) & (objitem.videomodedescription)) WriteTable "显示卡",videonameNext
End Function Function netcardWrite()'函数,查询网卡信息Set colNetcards = objswbemservices.execquery("select * from win32_networkadapter")For Each objNetcard in colNetcards                        If Not IsNull(objNetcard.NetConnectionID) ThenNetCardName         =  objNetcard.productnameWriteTable "网卡名称",NetCardNameIf objNetcard.NetConnectionStatus = 2 Then                         NetCardMac         =  objNetcard.macaddressWriteTable "网卡Mac",NetCardMacstrQueryIp ="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.IPAddressIpAdrress = CfgAdrressWriteTable "IP地址",IpAdrressNextNext        ElseNetCardMac = "网卡被禁用或未连接。"WriteTable "网卡Mac",NetCardMacIpAdrress = "网卡被禁用或未连接。"    WriteTable "IP地址",IpAdrress        End IfEnd ifNext
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 FunctionFunction NotHotfix(sSubKey)        If Left(sSubkey,2) = "KB" And len(sSubkey) = 8 ThenNotHotfix = 0Else NotHotfix = 1End if
End FunctionFunction getProgNameAndVersion(oReg,sKeyRoot)
Dim sKeyValuesAry, iKeyTypesAry, nCnt, sValue, sDisplayName, sDisplayVersion
oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry, iKeyTypesAryIf NOT IsArray(sKeyValuesAry) Then getProgNameAndVersion = 0Exit Function  End IfFor nCnt = 0 To UBound(sKeyValuesAry)If InStr(1, sKeyValuesAry(nCnt), "DisplayName", vbTextCompare) ThenIf iKeyTypesAry(nCnt) = REG_SZ ThenoReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValueIf sValue<>"" Then sDisplayName = sValue                                sDisplayName = Replace(sDisplayName, "[", "(")sDisplayName = Replace(sDisplayName, "]", ")")End IfEnd IfElseIf InStr(1, sKeyValuesAry(nCnt), "DisplayVersion", vbTextCompare) ThenIf iKeyTypesAry(nCnt) = REG_SZ ThenoReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValueIf sValue<>"" Then sDisplayVersion = sValueEnd IfEnd IfIf (sDisplayName<>"") AND (sDisplayVersion<>"") Then getProgNameAndVersion = sDisplayName & " --版本号: " & sDisplayVersionExit FunctionElse         getProgNameAndVersion = 0                        End IfNextIf sDisplayName<>"" Then getProgNameAndVersion = sDisplayNameExit Function                                        End If
End FunctionFunction 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 

这篇关于一个获取计算机硬件信息和安装软件清单的脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/660267

相关文章

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令

Win安装MySQL8全过程

《Win安装MySQL8全过程》:本文主要介绍Win安装MySQL8全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Win安装mysql81、下载MySQL2、解压文件3、新建文件夹data,用于保存数据库数据文件4、在mysql根目录下新建文件my.ini

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

最详细安装 PostgreSQL方法及常见问题解决

《最详细安装PostgreSQL方法及常见问题解决》:本文主要介绍最详细安装PostgreSQL方法及常见问题解决,介绍了在Windows系统上安装PostgreSQL及Linux系统上安装Po... 目录一、在 Windows 系统上安装 PostgreSQL1. 下载 PostgreSQL 安装包2.

使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

Maven如何手动安装依赖到本地仓库

《Maven如何手动安装依赖到本地仓库》:本文主要介绍Maven如何手动安装依赖到本地仓库问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、下载依赖二、安装 JAR 文件到本地仓库三、验证安装四、在项目中使用该依赖1、注意事项2、额外提示总结一、下载依赖登

C# foreach 循环中获取索引的实现方式

《C#foreach循环中获取索引的实现方式》:本文主要介绍C#foreach循环中获取索引的实现方式,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、手动维护索引变量二、LINQ Select + 元组解构三、扩展方法封装索引四、使用 for 循环替代