'==========================================================================
' Name: 查询软件和硬件列表清单
' 不支持Win2000及WinNT'
'==========================================================================
'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

strIPPattern = "((2[0-4]\d|25[0-5]|1?\d\d?)\.){3}(2[0-4]\d|25[0-5]|1?\d\d?)"
Set objNet = createobject("Wscript.Network")
Set objRegExp = New RegExp
objregexp.Pattern = strIPPattern
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
If InStr(IPConfig.Caption(i),"VMware") = 0 And InStr(IPConfig.Caption(i),"Microsoft") = 0 Then
If InStr(IPConfig.Caption(i),"169.254") = 0 And InStr(IPConfig.Caption(i),"0.0.0.0") = 0 Then
If objregexp.Test(IPConfig.IPAddress(i)) = True Then
strIP = IPConfig.IPAddress(i)
End If
End If
End If
Next
End If
Next
strUser = objnet.UserName
Set objNetwork = CreateObject("WScript.Network")

'==========================================================================
strComputer = objNetwork.ComputerName

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

查询软件和硬件列表清单[将文章里代码另存为 list.vbs,双击运行就会出现一个html页面]...相关推荐

  1. 公众号文章排版神器,Markdown一键排版,微信公号文章里代码的美化排版

    自己经常在简书,掘金上面写一些技术文章,喜欢用Markdown编辑器.最近需要把自己的一些技术博客文章发表到微信公众号文章里. 刚开始偷懒,就直接把用markdown写的技术博客复制粘贴到公号里(大多 ...

  2. java 清单文件 生成,使用批处理文件生成文件列表清单

    使用批处理文件生成文件列表清单 使用批处理文件生成文件列表清单,友友们都会遇到这样的情况:想要复制一个文件夹下所有文件的名字,或者将所有文件的名字列出一个清单,用手工复制的话吃力不讨好还容易出差错. ...

  3. 数据库的未来 - HTAP,软件、硬件、云生态的融合

    标签 PostgreSQL , GPU , FPGA , CPU , TPU , PL/language , 科研 , 嵌入式计算 , UDF , CUDA , 数据库嵌入式编程 , 流式计算 , 科 ...

  4. 计算机基础-了解软硬件-00:文章内容规划、了解软件和硬件的区别

    文章目录 文章内容规划 软件和硬件的区别(前言) 文章内容规划 软件和硬件的区别 了解计算机内有哪些硬件 了解CPU 挑选CPU 了解散热器.导热硅脂 了解主板.挑选主板 了解内存条 挑选内存条 了解 ...

  5. 软件测试报告怎么写?内部文章一目了然!

    测试报告编写 1. 概述 测试范围 测试人员.时间.功能 测试环境 服务端硬件环境 客户端软件环境 2. 测试过程评估 1. 测试总体评估 2. 用例统计 3. 测试用例执行情况分析 4. 测试对象质 ...

  6. asp.net怎么实现按条件查询_Display Posts : 按条件显示WordPress文章的最强插件

    转自丘壑博客 WordPress本质上是一个内容管理系统(CMS),是显示.创建.发布和维护内容的软件. 本文介绍的插件 Display Posts 主要就是用来扩展WordPress关于显示内容这部 ...

  7. 【微信小程序控制硬件③】 从软件到硬件搭建一个微信小程序控制esp8266的项目,自定义通讯协议,为面试职位和比赛项目加分!

    微信物联网生态主要分在微信硬件开发平台与腾讯物联开发平台,前者已经停止维护,但依然有着很大的学习价值,而后者作为主推的平台,集成很多功能,包括从微信小程序实现配网到控制: 为了兼顾更多的朋友和自己的学 ...

  8. 2018最新精选的Go框架,库和软件的精选列表 二

    2018最新精选的Go框架,库和软件的精选列表 二 地理 地理工具和服务器 geocache - 适用于基于地理定位的应用程序的内存缓存. pbf - OpenStreetMap PBF golang ...

  9. 2018最新精选的Go框架,库和软件的精选列表 二 https://awesome-go.com/

    地理 地理工具和服务器 geocache - 适用于基于地理定位的应用程序的内存缓存. pbf - OpenStreetMap PBF golang编码器/解码器. S2几何 - Go中的S2几何库. ...

最新文章

  1. python类的继承 被继承类放在类后面的括号中
  2. web api 限制单个IP在一定时间内访问次数
  3. 二叉树的建立和遍历的各种问题
  4. python_redis模块
  5. ThinkPHP的易忽视点小结
  6. buuctf (misc)神秘龙卷风 [brainfuck密码,压缩包密码爆破]
  7. flume案例-flume级联-组件分析
  8. 面试题——面经题目(1)
  9. 新加坡科技设计大学招收全奖博士,以及Research Assistant/Postdoc
  10. 《大屏可视化数据》该怎么设计?
  11. 邮件服务器IMail教程(2)
  12. PHP异步调用实现方式
  13. opencv注释中的@brief、@code/@endcode、@param、@sa 以及 如何在pycharm中看到opencv函数的完整注释
  14. 电压信号与电流信号的转换
  15. linux 搜狗输入法使用技巧,在Deepin 20系统中使用官方搜狗输入法的技巧
  16. bugku bingo题解
  17. 云服务器总是自动关机,云服务器出现死机的情况是什么原因?
  18. UNITY 模拟手机滑屏功能
  19. 计算机管理员注销,肿么注销计算机管理员
  20. 开机提示小娜无法在本计算机运行,win10 20h2提示此应用无法在你的电脑上运行解决方法...

热门文章

  1. 如何引用XML文件生成C#类
  2. JavaScript模拟实现“实例成员”和“静态成员”
  3. 2011下半年信息系统项目管理师考后感
  4. IK Analyzer 中文分词器
  5. size_t 和int 无符号整型和有符号整型
  6. mysql数据库的三级模式_数据库的三级模式和两级映射
  7. python零基础教学plc_利用Python构建电脑和PLC通信的方法
  8. 火车票能不能选座_在火车站买火车票可以选座位吗?
  9. python语言翻译成汇编语言_计原 || 1计算机语言发展与计算机层次结构
  10. linux平均负载什么意思_在Linux中什么是平均负载?