关于提取电脑软硬件信息并保存指定位置的VBS
2013-03-22 14:27
393 查看
论坛里有朋友说到这个话题,怎么用脚本来监控电脑内的软硬件信息,把我以前用的脚本拿出来稍稍改动了一下。先发在这里,有修改的话再进行二次改动吧。
'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
Set objswbemlocator = createobject("wbemscripting.swbemlocator")
Set objswbemservices = objswbemlocator.connectserver(strComputer, "root\cimv2")
Set oWshNetwork = WScript.CreateObject("WScript.Network")
strComputer = oWshNetwork.ComputerName
'WScript.Echo strComputer
'swbemservices.security_.impersonationleobjvel = 3
Set fso=createobject("scripting.filesystemobject")
FileDate = Replace(date(), "/", "-")
resoultfilepath= "d:\test\" & 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
'=========以下是函数列表==========
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 本文出自 “@Win” 博客,请务必保留此出处http://winterscn.blog.51cto.com/167048/1160309
'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
Set objswbemlocator = createobject("wbemscripting.swbemlocator")
Set objswbemservices = objswbemlocator.connectserver(strComputer, "root\cimv2")
Set oWshNetwork = WScript.CreateObject("WScript.Network")
strComputer = oWshNetwork.ComputerName
'WScript.Echo strComputer
'swbemservices.security_.impersonationleobjvel = 3
Set fso=createobject("scripting.filesystemobject")
FileDate = Replace(date(), "/", "-")
resoultfilepath= "d:\test\" & 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
'=========以下是函数列表==========
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 本文出自 “@Win” 博客,请务必保留此出处http://winterscn.blog.51cto.com/167048/1160309
相关文章推荐
- 在命令行cmd 下,输入dxdiag 查看关于电脑许多硬件的详细信息
- 在命令行cmd 下,输入dxdiag 查看关于电脑许多硬件的详细信息
- VBS 获取指定电脑的部分信息...
- 在命令行cmd 下,输入dxdiag 查看关于电脑许多硬件的详细信息
- VBS 获取指定电脑的部分信息...
- 存储位置优化——把视图状态信息保存在服务端而非客户端
- JavaScript权威指南_137_第15章_脚本化文档_15.8-文档和元素的几何形状和滚动-关于元素尺寸、位置、溢出的更多信息
- iOS_给保存到系统相册的视频添加位置信息
- Hardware_Info.vbs 获取硬件信息的VBS代码
- Objective - C UIActionSheet 图片相关 将选中图片放在指定位置并适应大小,长按保存
- 关于log4j的日志文件保存位置解决方案
- php上传图片到指定位置路径保存到数据库
- Python分布式爬虫前菜(2):关于提取网页源码中特定信息的技巧
- iOS 关于图片地理位置隐私信息的分析和读取
- 在本地电脑上保存GitHub账号信息,不需要每次提交版本时都输入用户名和密码
- 关于滚动条滚动到指定位置触发jq事件和html锚点
- JAVA中,把电脑里所有的.jpg文件保存到f盘指定目录下,并且文件不重名
- 使用File类列出指定位置下的文件信息,包括该路径子目录下的文件信息
- Linux下查看电脑的硬件配置等信息
- 如何从文件中提取指定位置的数据????