Use HTA to get WMI


Oh no-z more boring code.

Fun little code to get the WMI info from your or networked machines. WMI is a fun little party tool for devices and such in windows OS. Yes quote me on that.


(Random Gif)

Oh and yes it does export it to excel. Your Welcome.

Option Explicit

dim TargetWmiNs, Excel, Row, tWmiClass, WmiClasses

‘*** Set this variable to the target WMI namespace to document

TargetWmiNs = “\\Localhost\root\sms\site_lab”

**** \\remotecomputer\root\sms\site_lab

‘*** Create Excel object

set Excel = CreateObject(“Excel.Application”)

call Excel.Workbooks.Add()

‘*** Make Excel window visible

Excel.Visible = true

wscript.sleep 500

set WmiClasses = GetObject(“winmgmts:” & TargetWmiNs).Subclassesof

Row = 1

for each tWmiClass in WmiClasses

if Left(GetClassNameFromPath(tWmiClass.Path_), 2) <> “__” then

dim WmiQualifier

Excel.Cells(Row, 1).Value = “Class”

Excel.Cells(Row, 2).Value = GetClassNameFromPath(tWmiClass.Path_)

Excel.Cells(Row, 1).Interior.Color = 5880731

‘*** Write DisplayName WMI qualifier to Excel

for each WmiQualifier in tWmiClass.Qualifiers_

if WmiQualifier.Name = “DisplayName” then Excel.Cells(Row, 2).Value = WmiQualifier.Value


call WritePropertyInfo(tWmiClass)

call WriteMethodInfo(tWmiClass)

Row = Row + 1

end if


‘ Extract a class name from the full WMI path

function GetClassNameFromPath(WMIClassPath)

dim TempPath

TempPath = Split(WMIClassPath, “:”)

GetClassNameFromPath = TempPath(1)

end function

Function WritePropertyInfo(WmiClass)

dim WmiProperty

‘*** Write property information to Excel

for each WmiProperty in WmiClass.Properties_

Row = Row + 1

Excel.Cells(Row, 1).Value = “Property”

Excel.Cells(Row, 1).Interior.Color = 12419407

Excel.Cells(Row, 1).Font.Color = 0

Excel.Cells(Row, 2).Value = WmiProperty.Name

Excel.Cells(Row, 3).Value = WmiProperty.IsArray


End Function

Function WriteMethodInfo(WmiClass)

dim WmiMethod

‘*** Write WMI method information to Excel

for each WmiMethod in WmiClass.Methods_

Row = Row + 1

Excel.Cells(Row, 1).Value = “Method”

Excel.Cells(Row, 1).Interior.Color = 5066944

Excel.Cells(Row, 1).Font.Color = -1

Excel.Cells(Row, 2).Value = WmiMethod.Name


End Function

Copy the code and save it as a .hta. Yes an .Hta Html application.

Once again your welcome.

This entry was posted in Interesting, Windows. Bookmark the permalink.