• 售前

  • 售后

热门帖子
入门百科

vbs查询局域网内电脑的软件和硬件列表清单

[复制链接]
永远就三年疗 显示全部楼层 发表于 2021-8-19 19:37:14 |阅读模式 打印 上一主题 下一主题
下面的代码在windows下容易报毒各人可以放心利用
  1. '==========================================================================
  2. '
  3. ' Date:2009/3/19
  4. ' Name: 查询软件和硬件列表清单
  5. ' Author:Smileruner
  6. ' www.overmcse.com
  7. ' 不支持Win2000及WinNT
  8. '
  9. ' 3/19,添加了网卡过滤。
  10. '==========================================================================
  11. 'on error resume Next
  12. const HKEY_LOCAL_MACHINE = &H80000002
  13. const UNINSTALL_ROOT = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
  14. const REG_SZ = 1
  15. 'Set wshshell=wscript.createobject("wscript.shell")
  16. ' wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,true
  17. ' wshshell.run ("%comspec% /c sc config winmgmt start= auto"),0,true
  18. ' wshshell.run ("%comspec% /c net start winmgmt"),0
  19. strComputer = Inputbox("请输入要查询的计算机名称",,"")
  20. If strComputer = "" then
  21.     Wscript.Echo "未输入值或用户取消,查询退出。"
  22.     Wscript.Quit
  23. End If
  24. Set objswbemlocator = createobject("wbemscripting.swbemlocator")
  25. Set objswbemservices = objswbemlocator.connectserver(strComputer, "root\cimv2")
  26. If Err.number <> 0 then
  27.     Wscript.Echo "目标计算机无法连接。错误的计算机名,或目标计算机启用了防火墙,RPC服务不可用。"
  28.     Err.number.clear
  29.     Wscript.Quit
  30. End If
  31. 'swbemservices.security_.impersonationleobjvel = 3
  32. Set fso=createobject("scripting.filesystemobject")
  33. FileDate = Replace(date(), "/", "-")
  34. resoultfilepath= strComputer & FileDate & ".html"
  35. Set resultFile= fso.createtextfile(resoultfilepath,,true)
  36. HtmlWriteHead()
  37. 'Html文档开始
  38. TableHead strComputer,"硬件清单"
  39. 'Html表格开始
  40. OsWrite()   
  41.             '写入操作系统信息
  42. BoardWrite()
  43.             '写入主板信息
  44. CpuWrite()   
  45.             '写入CPU信息
  46. MemoryWrite()   
  47.             '写入内存信息
  48. HarddiskWrite()
  49.             '写入硬盘信息
  50. CdromWrite()
  51.             '写入CDROM信息
  52. VideoWrite()
  53.             '写入显示卡信息
  54. NetcardWrite()
  55.             '写入网卡信息
  56. TableEnd()
  57.             'Html表格结尾
  58. TableHead strComputer,"软件清单"
  59.             'Html表格开头
  60. Softlist()
  61.             '写入软件信息
  62. TableEnd()
  63.             'Html表格结尾
  64. HtmlWriteEnd()
  65.             'Html文档结束
  66. ResultFile.close
  67. Wscript.Echo "查询完成!"
  68. '=========以下是函数列表==========
  69. Function OsWrite()
  70.         '函数,写入操作系统信息
  71.     Set colOs =objswbemservices.execquery("select * from win32_operatingsystem",,48)
  72.     For Each Ositem In colOs
  73.         oscaption = Ositem.caption
  74.         OsVersion = oscaption & Ositem.version
  75.         WriteTable "操作系统",OsVersion
  76.     Next
  77. End Function
  78. Function BoardWrite()
  79.         '函数,写入主板信息
  80.     Set colBoard = objswbemservices.execquery("select * from win32_baseboard")
  81.     For Each Bditem In colBoard
  82.         boardname = Bditem.product
  83.         WriteTable "主板",boardname
  84.     Next
  85. End Function
  86. Function CpuWrite()
  87.         '函数,写入CPU信息
  88.     Set colCpu =objswbemservices.execquery("select * from win32_processor")
  89.     For Each item in colCpu
  90.         cpuname = (trim(item.name))
  91.         WriteTable "中央处理器",cpuname
  92.     Next
  93. End Function
  94. Function MemoryWrite()
  95.         '函数,写入内存信息
  96. mtotal    = 0
  97. num     = 0
  98. mill     = 0
  99.     Set colMemory = objswbemservices.execquery("select * from win32_physicalmemory",,48)
  100.     For Each objitem In colMemory
  101.         mill = objitem.capacity/1048576
  102.         WriteTable "单根内存容量",mill & "M"
  103.         mtotal = mtotal+mill
  104.         num = num + 1
  105.     Next
  106.     WriteTable "总计内存",num & "条" & "一共" & mtotal & "M"
  107. End Function
  108. Function HarddiskWrite()
  109.         '函数,写入硬盘信息
  110.     Set colDisk = objswbemservices.execquery("select * from win32_diskdrive", , 48)
  111.     For Each objitem In colDisk
  112.         diskname= objitem.caption
  113.         disksize= fix(objitem.size/1073741824)
  114.         WriteTable "硬盘",diskname & " 容量:" & disksize & "G"
  115.     Next
  116. End Function
  117. Function CdromWrite()
  118.         '函数,写入CDROM信息
  119.     Set colCdrom = objswbemservices.execquery("select * from win32_cdromdrive where scsitargetid=0")
  120.     For Each objitem In colCdrom
  121.         cdname = objitem.name
  122.         WriteTable "光驱",cdname
  123.     Next
  124. End Function
  125. Function videoWrite()
  126.         '函数,写入显示卡信息
  127.     Set colVideo = objswbemservices.execquery("select * from win32_videocontroller", , 48)
  128.     For Each objitem in colVideo
  129.         videoname = (trim(objitem.caption) & (objitem.videomodedescription))
  130.         WriteTable "显示卡",videoname
  131.     Next
  132. End Function
  133. Function netcardWrite()
  134.         '函数,查询网卡信息
  135.     Set colNetcards = objswbemservices.execquery("select * from win32_networkadapter")
  136.         For Each objNetcard in colNetcards            
  137.         If Not IsNull(objNetcard.NetConnectionID) Then
  138.             NetCardName     = objNetcard.productname
  139.                 WriteTable "网卡名称",NetCardName
  140.          
  141.             If objNetcard.NetConnectionStatus = 2 Then            
  142.             NetCardMac     = objNetcard.macaddress
  143.             WriteTable "网卡Mac",NetCardMac
  144.             strQueryIp ="select * from win32_networkadapterconfiguration" &_
  145.                      " where IPEnabled = true" &_
  146.                      " and macaddress = '" & objNetcard.macaddress & "'"
  147.             Set colNetcardCfgs = objswbemservices.execquery(strQueryIp)
  148.             For Each objNetcardCfg in colNetcardCfgs        
  149.                 For Each CfgAdrress in objNetcardCfg.IPAddress
  150.                     IpAdrress = CfgAdrress
  151.                     WriteTable "IP地址",IpAdrress
  152.                 Next
  153.             Next   
  154.             Else
  155.             NetCardMac = "网卡被禁用或未连接。"
  156.             WriteTable "网卡Mac",NetCardMac
  157.             IpAdrress = "网卡被禁用或未连接。"  
  158.             WriteTable "IP地址",IpAdrress   
  159.             
  160.             End If
  161.                
  162.         End if
  163.             
  164.         Next
  165. End Function
  166. Function softlist()
  167.         '函数,写入软件信息
  168. Set StdOut = WScript.StdOut
  169. Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" &_
  170. strComputer & "\root\default:StdRegProv")
  171. strKeyPath = UNINSTALL_ROOT
  172. oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
  173. For Each strSubKey In arrSubKeys
  174.     If NotHotfix(strSubKey) Then        
  175.         SoftNameAndVersion = getProgNameAndVersion(oReg,strKeyPath & "" & strSubKey)
  176.         If SoftNameAndVersion<>"0" Then
  177.         WriteTable "软件",SoftNameAndVersion        
  178.         End If
  179.     End If
  180. Next         
  181. End Function
  182. Function NotHotfix(sSubKey)   
  183.     If Left(sSubkey,2) = "KB" And len(sSubkey) = 8 Then
  184.         NotHotfix = 0
  185.     Else NotHotfix = 1
  186.     End if
  187. End Function
  188. Function getProgNameAndVersion(oReg,sKeyRoot)
  189. Dim sKeyValuesAry, iKeyTypesAry, nCnt, sValue, sDisplayName, sDisplayVersion
  190. oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry, iKeyTypesAry
  191.     If NOT IsArray(sKeyValuesAry) Then
  192.         getProgNameAndVersion = 0
  193.         Exit Function
  194.     End If
  195.     For nCnt = 0 To UBound(sKeyValuesAry)
  196.         If InStr(1, sKeyValuesAry(nCnt), "DisplayName", vbTextCompare) Then
  197.             If iKeyTypesAry(nCnt) = REG_SZ Then
  198.                 oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValue
  199.                 If sValue<>"" Then
  200.                     sDisplayName = sValue               
  201.                     sDisplayName = Replace(sDisplayName, "[", "(")
  202.                     sDisplayName = Replace(sDisplayName, "]", ")")
  203.                 End If
  204.             End If
  205.         ElseIf InStr(1, sKeyValuesAry(nCnt), "DisplayVersion", vbTextCompare) Then
  206.             If iKeyTypesAry(nCnt) = REG_SZ Then
  207.                 oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValue
  208.                 If sValue<>"" Then sDisplayVersion = sValue
  209.             End If
  210.         End If
  211.         If (sDisplayName<>"") AND (sDisplayVersion<>"") Then
  212.             getProgNameAndVersion = sDisplayName & " --版本号: " & sDisplayVersion
  213.             Exit Function
  214.         Else     getProgNameAndVersion = 0            
  215.         End If
  216.     Next
  217.     If sDisplayName<>"" Then
  218.         getProgNameAndVersion = sDisplayName
  219.         Exit Function                    
  220.     End If
  221. End Function
  222. Function WriteTable(caption,value)
  223.         '函数,将数据写入HTML单元格
  224. resultFile.Writeline "<tr>"
  225. resultFile.Writeline "<td align=""left"" width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""row"">&nbsp;&nbsp;" & caption & "</td>"
  226. resultFile.Writeline "<td bgcolor=""#ffffff"">&nbsp;&nbsp;" & value & "</td>"
  227. resultFile.Writeline "</tr>"
  228. End Function
  229. Function HtmlWriteHead()
  230.         '函数,写入THML文件头
  231. resultFile.Writeline "<html>"
  232. resultFile.Writeline "<head>"
  233. resultFile.Writeline "<title>软硬件配置清单</title>"
  234. resultFile.Writeline "</head>"
  235. resultFile.Writeline "<body>"
  236. End Function
  237. Function HtmlWriteEnd()
  238.         '函数,写入Html文件尾
  239. resultFile.Writeline "</body>"
  240. resultFile.Writeline "</html>"
  241. End Function
  242. Function TableHead(pcname,str)
  243.         '函数,写入Html表格结尾
  244. resultFile.Writeline "<h3>" & pcname & str & " -- date:"&now()&" </h3>" & VbCrLf
  245. resultFile.Writeline "<table width=""90%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""1"" bgcolor=""#0000ff"">"
  246. resultFile.Writeline "<tr>"
  247. resultFile.Writeline "<th width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""col"">资产类型</th>"
  248. resultFile.Writeline "<th bgcolor=""#ffffff"" scope=""col"">查询结果值</th>"
  249. resultFile.Writeline "</tr>"
  250. strstyle = "<th width=""30%"" height=""25"" bgcolor=""#ffffff"" scope=""row"">"
  251. End Function
  252. Function TableEnd()
  253.         '函数,Html表格结尾
  254. resultFile.Writeline "</table>"
  255. End Function
复制代码
vbs判断操纵系统
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
  3. Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
  4. For Each objItem in colItems
  5. strOSVersion = objItem.Version
  6. Next
  7. wscript.echo strOSversion
  8. select case strOSversion
  9. case "5.2.3790"
  10. wscript.echo "Windows Server 2003"
  11. case "5.0.2195"
  12. wscript.echo "Windows 2000"
  13. case "5.1.2600"
  14. wscript.echo "Windows XP"
  15. case "6.0.6001"
  16. wscript.echo "windows visita"
  17. Case "6.1.7601"
  18. wscript.echo "Windows Server 2008 r2"
  19. case else
  20. wscript.echo "i don't know"
  21. end select
复制代码
到此这篇关于vbs查询局域网内电脑的软件和硬件列表清单的文章就介绍到这了,更多干系查询软件和硬件列表清单内容请搜索草根技能分享以前的文章或继续欣赏下面的干系文章希望各人以后多多支持草根技能分享!

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作