Advertisement
omegastripes

tmp_cimv2_win32_classes_props_quals_insts_htm_release_0.vbs

Feb 1st, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 11.15 KB | None | 0 0
  1. ' WMI Report builder
  2. ' release 0
  3. ' 02 02 2017
  4. ' omegastripes@yandex.ru
  5.  
  6. Const wbemFlagUseAmendedQualifiers = 131072
  7. Set oWnd = CreateOutputWindow("WMI Report", 1200, 800)
  8.  
  9. sDesktopPath = CreateObject("WScript.Shell").SpecialFolders.Item("Desktop")
  10. Set oService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\Root\CIMV2") ' SWbemServicesEx
  11. Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
  12.  
  13. REM ' hardware + software
  14. REM aClsList = Array("Win32_PnPEntity", "Win32_SystemEnclosure", "Win32_BaseBoard", "Win32_MotherboardDevice", "Win32_OnBoardDevice", "Win32_Bus", "Win32_SystemSlot", "Win32_Processor", "Win32_CacheMemory", "Win32_PhysicalMemory", "Win32_MemoryDevice", "Win32_MemoryArray", "Win32_PhysicalMemoryArray", "Win32_DeviceMemoryAddress", "Win32_DMAChannel", "Win32_PortConnector", "Win32_PortResource", "Win32_ParallelPort", "Win32_SerialPort", "Win32_SerialPortConfiguration", "Win32_Keyboard", "Win32_PointingDevice", "Win32_SoundDevice", "Win32_VideoController", "CIM_VideoControllerResolution", "Win32_NetworkAdapter", "Win32_NetworkAdapterConfiguration", "Win32_DesktopMonitor", "Win32_FloppyDrive", "Win32_DiskDrive", "Win32_CDROMDrive", "Win32_OperatingSystem", "Win32_ComputerSystem", "Win32_BIOS", "Win32_StartupCommand", "Win32_Product", "Win32_SoftwareFeature", "Win32_ClassicCOMClassSetting")
  15.  
  16. ' hardware
  17. aClsList = Array("Win32_PnPEntity", "Win32_SystemEnclosure", "Win32_BaseBoard", "Win32_MotherboardDevice", "Win32_OnBoardDevice", "Win32_Bus", "Win32_SystemSlot", "Win32_Processor", "Win32_CacheMemory", "Win32_PhysicalMemory", "Win32_MemoryDevice", "Win32_MemoryArray", "Win32_PhysicalMemoryArray", "Win32_DeviceMemoryAddress", "Win32_DMAChannel", "Win32_PortConnector", "Win32_PortResource", "Win32_ParallelPort", "Win32_SerialPort", "Win32_SerialPortConfiguration", "Win32_Keyboard", "Win32_PointingDevice", "Win32_SoundDevice", "Win32_VideoController", "CIM_VideoControllerResolution", "Win32_NetworkAdapter", "Win32_NetworkAdapterConfiguration", "Win32_DesktopMonitor", "Win32_FloppyDrive", "Win32_DiskDrive", "Win32_CDROMDrive")
  18.  
  19. REM ' software
  20. REM aClsList = Array("Win32_OperatingSystem", "Win32_ComputerSystem", "Win32_BIOS", "Win32_StartupCommand", "Win32_Product", "Win32_SoftwareFeature", "Win32_ClassicCOMClassSetting")
  21.  
  22. sUserPc = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%username%@%computername%")
  23. sReportPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, ".") - 1) & "_" & sUserPc & ".htm"
  24. oWnd.write "<p>Report started: " & Now & "</p>"
  25. oWnd.write "<p>" & sUserPc & "</p>"
  26. oWnd.write "<h1>WMI Classes</h1><p>" & A2HT(aClsList) & "</p>"
  27. j = 1
  28. For Each sClass In aClsList
  29.     Set oClass = oService.Get(sClass, wbemFlagUseAmendedQualifiers) ' SWbemObjectEx
  30.     ' class qualifiers
  31.     s = "<h1>" & sClass & "</h1><p>Qualifiers</p><p><table><tr><th>Qualifier</th><th>Value</th></tr>"
  32.     For Each oQualifier In oClass.Qualifiers_
  33.         s = s & "<tr><td>" & oQualifier.Name & "</td>"
  34.         If IsArray(oQualifier.Value) Then
  35.             s = s & "<td>" & A2HT(oQualifier.Value) & "</td></tr>"
  36.         Else
  37.             s = s & "<td>" & SafeHtml(oQualifier.Value) & "</td></tr>" ' \n\r\t
  38.         End If
  39.     Next
  40.     s = s & "</table></p>"
  41.     oWnd.write s
  42.     ' properties
  43.     k = 1
  44.     s = "<p>Properties</p><p><table><tr><th>Property</th><th>Qualifier</th><th>Value</th>"
  45.     Set oProperties = CreateObject("Scripting.Dictionary")
  46.     For Each oProperty In oClass.Properties_
  47.         Set oQuals = CreateObject("Scripting.Dictionary")
  48.         For Each oQualifier In oProperty.Qualifiers_
  49.             oQuals(oQualifier.Name) = oQualifier.Value
  50.         Next
  51.         CreateMap oQuals, "Values", "ValueMap", oValueMap, bValuesExists, bValueMapExists
  52.         CreateMap oQuals, "BitValues", "BitMap", oBitMap, bBitValuesExists, bBitMapExists
  53.         lQualCount = oQuals.Count
  54.         If bValueMapExists Or bBitMapExists Then lQualCount = lQualCount - 1
  55.         sprp = "<td rowspan=""" & lQualCount & """>" & oProperty.Name & "</td>"
  56.         bPropRow = True
  57.         For Each sQual In oQuals
  58.             Select Case sQual
  59.                 Case "ValueMap", "BitMap"
  60.                 Case Else
  61.                     s = s & "<tr>"
  62.                     If bPropRow Then
  63.                         s = s & sprp
  64.                         bPropRow = False
  65.                     End If
  66.                     Select Case sQual
  67.                         Case "Values"
  68.                             If bValueMapExists Then s = s & "<td>Values, ValueMap</td>" Else s = s & "<td>Values</td>"
  69.                             s = s & "<td>" & D2HT(oValueMap) & "</td>"
  70.                         Case "BitValues"
  71.                             If bBitMapExists Then s = s & "<td>BitValues, BitMap</td>" Else s = s & "<td>BitValues</td>"
  72.                             s = s & "<td>" & D2HT(oBitMap) & "</td>"
  73.                         Case Else
  74.                             s = s & "<td>" & sQual & "</td>"
  75.                             If IsArray(oQuals(sQual)) Then
  76.                                 s = s & "<td>" & A2HT(oQuals(sQual)) & "</td>"
  77.                             Else
  78.                                 s = s & "<td>" & SafeHtml(oQuals(sQual)) & "</td>" ' \n\r\t
  79.                             End If
  80.                     End Select
  81.                     s = s & "</tr>"
  82.             End Select
  83.         Next
  84.         If oQuals.Exists("Units") Then
  85.             sUnits = " " & oQuals("Units")
  86.         Else
  87.             sUnits = ""
  88.         End If
  89.         bCimDateTime = oQuals("CIMTYPE") = "datetime"
  90.         oProperties(oProperty.Name) = Array(oQuals, bValuesExists, oValueMap, bBitValuesExists, oBitMap, sUnits, bCimDateTime)
  91.         oWnd.document.title = "WMI Report: Class " & sClass & " (" & j & " of " & (UBound(aClsList) + 1) & "), Property " & k
  92.         k = k + 1
  93.     Next
  94.     s = s & "</table></p>"
  95.     oWnd.write s
  96.     ' instances
  97.     k = 1
  98.     s = "<p>Instances</p><p><table><tr>"
  99.     For Each sProperty In oProperties
  100.         s = s & "<th>" & sProperty & "</th>"
  101.     Next
  102.     s = s & "</tr>"
  103.     For Each oInstance In oService.InstancesOf(sClass)
  104.         s = s & "<tr>"
  105.         For Each sProperty In oProperties
  106.             v = oInstance.Properties_.Item(sProperty).Value
  107.             Select Case True
  108.                 Case IsNull(v) v = "N/A"
  109.                 Case IsArray(v) v = A2HT(v)
  110.                 Case v = "" v = "-"
  111.                 Case Else
  112.                     Select Case True
  113.                         Case oProperties(sProperty)(1) ' bValuesExists
  114.                             If oProperties(sProperty)(2).Exists(CStr(v)) Then
  115.                                 v = oProperties(sProperty)(2)(CStr(v))
  116.                             Else
  117.                                 v = "(" & v & ")"
  118.                             End If
  119.                             v = SafeHtml(v) & oProperties(sProperty)(5)
  120.                         Case oProperties(sProperty)(3) ' bBitValuesExists
  121.                             v = A2HT(GetMapBits(v, oProperties(sProperty)(4)))
  122.                         Case oProperties(sProperty)(6) ' cim_datetime
  123.                             oSWbemDateTime.Value = v
  124.                             v = CStr(oSWbemDateTime.GetVarDate(True))
  125.                         Case Else
  126.                             v = SafeHtml(v) & oProperties(sProperty)(5)
  127.                     End Select
  128.             End Select
  129.             s = s & "<td>" & v & "</td>"
  130.         Next
  131.         s = s & "</tr>"
  132.         oWnd.document.title = "WMI Report: Class " & sClass & " (" & j & " of " & (UBound(aClsList) + 1) & "), Instance " & k
  133.         k = k + 1
  134.     Next
  135.     s = s & "</table></p>"
  136.     oWnd.write s
  137.     j = j + 1
  138. Next
  139. oWnd.write "<p>Report completed: " & Now & "</p>"
  140.  
  141. s0 = oWnd.document.getElementsByTagName("style")(0).outerHTML
  142. s1 = oWnd.document.getElementById("output").innerHTML
  143. s = "<html><head>" & s0 & "</head><body>" & s1 & "</body></html>"
  144. WriteTextFile s, sReportPath, -1
  145. oWnd.document.title = "WMI Report"
  146. CreateObject("WScript.Shell").Run sReportPath
  147.  
  148.  
  149.  
  150. Function GetMapBits(ByVal v, oBitMap)
  151.     Dim i
  152.     With CreateObject("Scripting.Dictionary")
  153.         For i = 31 To 0 Step -1
  154.             If v >= 2 ^ i Then
  155.                 If oBitMap.Exists(CStr(i)) Then .Item(.Count) = oBitMap(CStr(i))
  156.                 v = v - 2 ^ i
  157.             End If
  158.         Next
  159.         GetMapBits = .Items()
  160.     End With
  161. End Function
  162.  
  163. Function SafeHtml(ByVal s)
  164.     s = Replace(s, "&", "&amp;", 1, -1, 0)
  165.     s = Replace(s, "<", "&lt;", 1, -1, 0)
  166.     s = Replace(s, ">", "&gt;", 1, -1, 0)
  167.     s = Replace(s, vbCrLf, "<br>", 1, -1, 0)
  168.     s = Replace(s, vbCr, "<br>", 1, -1, 0)
  169.     s = Replace(s, vbLf, "<br>", 1, -1, 0)
  170.     s = Replace(s, chr(9), "&nbsp;&nbsp;&nbsp;&nbsp;", 1, -1, 0)
  171.     s = Replace(s, "  ", " &nbsp;", 1, -1, 0)
  172.     SafeHtml = Replace(s, "&nbsp; ", "&nbsp;&nbsp;", 1, -1, 0)
  173. End Function
  174.  
  175. Sub CreateMap(oQuals, Items, ItemMap, oMap, bItemsExists, bItemMapExists)
  176.     Dim aItems, aItemMap, i
  177.     bItemsExists = oQuals.Exists(Items)
  178.     If bItemsExists Then
  179.         Set oMap = CreateObject("Scripting.Dictionary")
  180.         aItems = oQuals(Items)
  181.         bItemMapExists = oQuals.Exists(ItemMap)
  182.         If bItemMapExists Then
  183.             aItemMap = oQuals(ItemMap)
  184.             For i = 0 To UBound(aItems)
  185.                 If oMap.Exists(aItemMap(i)) Then
  186.                     oMap(aItemMap(i)) = oMap(aItemMap(i)) & "|" & aItems(i) ' inexplicable duplicates
  187.                 Else
  188.                     oMap(aItemMap(i)) = aItems(i)
  189.                 End If
  190.             Next
  191.         Else
  192.             For i = 0 To UBound(aItems)
  193.                 oMap(CStr(i)) = aItems(i)
  194.             Next
  195.         End If
  196.     Else
  197.         bItemMapExists = False
  198.         Set oMap = Nothing
  199.     End If
  200. End Sub
  201.  
  202. Function D2HT(oDict)
  203.     Dim sKey
  204.     D2HT = "<table>"
  205.     For Each sKey In oDict
  206.         D2HT = D2HT & "<tr><td>" & sKey & "</td><td>" & SafeHtml(oDict(sKey)) & "</td></tr>"
  207.     Next
  208.     D2HT = D2HT & "</table>"
  209. End Function
  210.  
  211. Function A2HT(aList)
  212.     Dim sItem
  213.     A2HT = A2HT & "<table>"
  214.     For Each sItem In aList
  215.         A2HT = A2HT & "<tr><td>" & SafeHtml(sItem) & "</td></tr>"
  216.     Next
  217.     A2HT = A2HT & "</table>"
  218. End Function
  219.  
  220. Sub WriteTextFile(sContent, sPath, lFormat) ' 27 01 2015
  221.     ' lFormat -2 - System default, -1 - Unicode, 0 - ASCII
  222.     With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 2, True, lFormat)
  223.         .Write sContent
  224.         .Close
  225.     End With
  226. End Sub
  227.  
  228. Function CreateOutputWindow(sTitle, lWidth, lHeight)
  229.     ' source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
  230.     Dim sSignature, oShellWnd, oProc
  231.     On Error Resume Next
  232.     sSignature = Left(CreateObject("Scriptlet.TypeLib").Guid, 38)
  233.     Do
  234.         Set oProc = CreateObject("WScript.Shell").Exec("mshta ""about:<head><script>moveTo(-32000,-32000);document.title=' '</script><hta:application id=app border=thick minimizebutton=yes maximizebutton=yes scroll=no showintaskbar=yes contextmenu=yes selection=yes innerborder=no icon=""""/><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""")
  235.         Do
  236.             If oProc.Status > 0 Then Exit Do
  237.             For Each oShellWnd In CreateObject("Shell.Application").Windows
  238.                 Set CreateOutputWindow = oShellWnd.GetProperty(sSignature)
  239.                 If Err Then
  240.                     Err.Clear
  241.                     WScript.Sleep 1
  242.                 Else
  243.                     With CreateOutputWindow
  244.                         With .document
  245.                             .title = sTitle
  246.                             .getElementsByTagName("head")(0).appendChild(.createElement("style"))
  247.                             .styleSheets(0).cssText = "* {font-family: consolas, courier new; font-size: 10pt;} h1 {font-size: 14pt;} table {border-collapse: collapse; background: transparent;} td, th {border: black 1px solid; vertical-align: top; padding: 2px 5px;} #output {width: 100%; height: 100%; padding: 3px; overflow-x: auto; overflow-y: scroll;}"
  248.                             .body.style.background = "buttonface"
  249.                             .body.innerHTML = "<div id='output'></div>"
  250.                         End With
  251.                         .resizeTo .screen.availWidth, .screen.availHeight
  252.                         .resizeTo lWidth + .screen.availWidth - .document.body.offsetWidth, lHeight + .screen.availHeight - .document.body.offsetHeight
  253.                         .moveTo (.screen.availWidth - lWidth) \ 2, (.screen.availHeight - lHeight) \ 2
  254.                         .execScript "var hostWScript, hostQuit = function() {hostWScript.Timeout = 1; hostWScript.Quit();};"
  255.                         Set .hostWScript = WScript
  256.                         Set .document.body.onunload = .hostQuit
  257.                         .execScript "var write = function(s) {output.appendChild(document.createElement('div')).innerHTML = s};"
  258.                     End With
  259.                     Exit Function
  260.                 End If
  261.             Next
  262.         Loop
  263.     Loop
  264. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement