Windows Computer Inventory HTML Application (HTA)
Windows Computer Inventory HTML Application (HTA)
<head>
<title>Inventory Computers</title>
<HTA:APPLICATION
ID="objHTAInventory"
APPLICATIONNAME="HTA_Inventory"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<SCRIPT Language="VBScript">
'*******************************************************************************
'Script to accept a text file as source of machine names, then create a new
' Excel workbook for each computer in the file and save the workbook as the
' computer name. Each workbook will contain a sheet for hardware, software,
' printers, services, and general information.
'Created by Brian Bohanon
'Created: 7/7/2008
'*******************************************************************************
Option Explicit
'Global Variables
Dim arrFileLines() 'array to hold computer names
Dim tst 'variable for file
Dim i, j, k, l 'global counters
'Objects
Dim objFSO, objFile, objDialog, objExcel, objWMIService, objWorkbook
Dim objPrintItem, objDiskDrive, objExplorer, objLocalWMIService, objLocalItem
Dim objOSItem, objBIOS, objSetting, objQuickFix, objSoftware, objService
Dim objDrive, objNet, objProcItem, objSCSIItem, objVideo, objDisk
'Collections
Dim colOSItems, colBIOS, colSettings, colQuickFixes, colSoftware, colServices
Dim colPrintItems, colDisks, colDiskDrives, colDrives, colNet, colProcItems
Dim colSCSIItems, colVideo, colLocalItems
Dim WshShell 'Provides access to WScript.Shell
Dim srcFileName 'source file
Dim intResult 'used to test open file dialog
Dim strComputer 'active computer to inventory
Dim strDirectory 'Local directory
Dim strLocalComputer 'Local computer script is running on
Dim intHorizontal, intVertical, intLeft, intTop
'Constants
Const xlLeft = -4131
Const xlHorizontal = -4128
'*******************************************************************************
'Sub routines
'*******************************************************************************
Sub Window_onLoad
Set WshShell = CreateObject("WScript.Shell")
strLocalComputer = "."
'Set current directory to Desktop & display on page
strDirectory = WshShell.SpecialFolders("Desktop") & "\"
DirectorySpan.innerhtml = "The files will be saved to " & strDirectory
End Sub
'*******************************************************************************
Sub CreateLog()
Dim objFile
Dim strFile, strText
'*******************************************************************************
'Used to append the log for each computer the script is run against
Sub WriteLog(strErrorNumber)
strFile = "InventoryLog_" & Month(Date()) & "_" & Day(Date()) & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
End Sub
'*******************************************************************************
'Cretes the window to tell the user the script is running
Sub ProgressBar()
'Window title
objExplorer.Document.Title = "Inventory script in progress"
'Message for status, including the current computer
objExplorer.Document.Body.InnerHTML = "The inventory script is being
processed " &_
" for computer " & strComputer &_
". This might take several minutes to complete."
End Sub
'*******************************************************************************
Dim n, a
n = 3
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
Application.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.Add()
objExcel.Worksheets("Sheet2").Delete
objExcel.Worksheets("Sheet3").Delete
If n <> 1 Then
a = n - 1
objExcel.Worksheets(strComputerName).Move objExcel.Worksheets(1)
End If
objExcel.Worksheets(strComputerName).Activate
'Save the workbook to the desktop
objWorkbook.SaveAs(strDirectory & strComputerName & "_Inventory_" &_
Month(Date()) & "_" & Day(Date()) & "_" & Year(Date()) & ".xls")
'Close Excel
objExcel.Quit
End Sub
'*******************************************************************************
Dim s, t 'counters
Set colBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")
Set colOSItems = objWMIService.ExecQuery("Select * from
Win32_OperatingSystem")
Set colSettings = objWMIService.ExecQuery("Select * from
Win32_ComputerSystem")
'Get OS information
s = s + 2
t = 1
s = s + 1
'Section header
objExcel.Cells(s, t).Value = "Physical Machine Information"
objExcel.Cells(s, t).Font.Bold = True
s = s + 1
s = s + 1
t = 1
s = s + 1
t = 1
objExcel.Cells(s, t).Value = "Model:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t).Value = objSetting.Model
s = s + 1
t = t - 1
objExcel.Cells(s, t).Value = "System Type:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t).Value = objSetting.SystemType
Next
End Sub
'*******************************************************************************
Dim s, t 'counters
s = 1
t = 1
Set colQuickFixes = objWMIService.ExecQuery("Select * from " &_
"Win32_QuickFixEngineering")
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")
objExcel.Cells(s, t) = "Software"
objExcel.Cells(s, t).Font.Bold = True
s = s + 1
objExcel.Cells(s, t) = "Caption:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Version:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Description:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Vendor:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Identiying Number:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Install Date:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Install Location:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Package Cache:"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
s = s + 1
t = 1
'Section header
objExcel.Cells(s, t) = "Installed Hotfixes"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
'Column headers
objExcel.Cells(s, t) = "Hot Fix ID:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Description:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Installed By:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Install Date:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Service Pack Level:"
objExcel.Cells(s, t).Font.Bold = TRUE
'Hotfix data
For Each objQuickFix in colQuickFixes
s = s + 1
t = 1
End Sub
'*******************************************************************************
Sub GetServicesInfo()
Dim s, t
s = 1
t = 1
'Column headers
objExcel.Cells(s, t).Value = "Service"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t).Value = "Status"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t).Value = "StartMode"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t).Value = "StartName"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t).Value = "PathName"
objExcel.Cells(s, t).Font.Bold = TRUE
'Services data
For Each objService in colServices
s = s + 1
objExcel.Cells(s, 1) = objService.Name
objExcel.Cells(s, 2) = objService.State
objExcel.Cells(s, 3) = objService.StartMode
objExcel.Cells(s, 4) = objService.StartName
objExcel.Cells(s, 5) = objService.PathName
if objService.State = "Stopped" then
objExcel.Cells(s, 2).Font.ColorIndex = 3
end if
Next
' Autofit the first column to fit the longest service name
objExcel.Columns("A:Z").EntireColumn.AutoFit
objExcel.Columns("A:Z").HorizontalAlignment = xlLeft
End Sub
'*******************************************************************************
Sub GetHardwareInfo()
Dim s, t
Dim video_ram, disk_size, disk_free, diskDrive_size, phys_ram
s = 1
t = 1
'Section header
objExcel.Cells(s, t) = "Logical Drives"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column headers
objExcel.Cells(s, t) = "Drive letters:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Volume Name:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Description:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "File System:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Total Size (GB):"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Free Space (GB):"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Volume Serial Number:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Compressed:"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
t = 1
s = s + 1
'Section header
objExcel.Cells(s, t) = "Physical Drives"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column headers
objExcel.Cells(s, t) = "Caption:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Device ID:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Index:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Interface Type:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Manufacturer:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Media Loaded:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Media Type:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Model:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Partitions:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "SCSI Bus:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "SCSI Logical Unit:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "SCSI Port:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "SCSI TargetId:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Sectors Per Track:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Signature:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Size (GB):"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Status:"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
objExcel.Cells(s, t) = objDiskDrive.Caption
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.DeviceID
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.Index
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.InterfaceType
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.Manufacturer
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.MediaLoaded
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.MediaType
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.Model
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.Partitions
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.SCSIBus
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.SCSILogicalUnit
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.SCSIPort
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.SCSITargetId
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.SectorsPerTrack
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.Signature
t = t + 1
'convert into GB
diskDrive_size = objDiskDrive.Size / 1073741824
objExcel.Cells(s, t) = int(diskDrive_size)
t = t + 1
objExcel.Cells(s, t) = objDiskDrive.Status
Next
t = 1
s = s + 2
'Section header
objExcel.Cells(s, t) = "SCSI Information"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column headers
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Device ID:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Driver Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "PNP Device ID:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Protocol Supported:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Status Information:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Configuration Manager Error Code:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Configuration Manager User Configuration:"
objExcel.Cells(s, t).Font.Bold = TRUE
objExcel.Cells(s, t) = objSCSIItem.Name
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.DeviceID
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.DriverName
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.PNPDeviceID
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.ProtocolSupported
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.StatusInfo
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.ConfigManagerErrorCode
t = t + 1
objExcel.Cells(s, t) = objSCSIItem.ConfigManagerUserConfig
Next
t = 1
s = s + 2
'Section header
objExcel.Cells(s, t) = "BIOS Information"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column header
objExcel.Cells(s, t) = "Manufacturer:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Release Date:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Version:"
objExcel.Cells(s, t).Font.Bold = TRUE
'BIOS data
For each objBIOS in colBIOS
s = s + 1
t = 1
objExcel.Cells(s, t) = objBIOS.Manufacturer
t = t + 1
objExcel.Cells(s, t) = objBIOS.Name
t = t + 1
objExcel.Cells(s, t) = objBIOS.ReleaseDate
t = t + 1
objExcel.Cells(s, t) = objBIOS.Version
Next
t = 1
s = s + 2
'Section header
objExcel.Cells(s, t) = "Processor Information"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column headers
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Manufacturer:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Current Clock Speed (MHz):"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "L2 Cache Size (MB):"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Architecture:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Address Width (bits):"
objExcel.Cells(s, t).Font.Bold = TRUE
'Processor data
For Each objProcItem in colProcItems
s = s + 1
t = 1
objExcel.Cells(s, t) = objProcItem.Name
t = t + 1
objExcel.Cells(s, t) = objProcItem.Manufacturer
t = t + 1
objExcel.Cells(s, t) = objProcItem.CurrentClockSpeed
t = t + 1
objExcel.Cells(s, t) = objProcItem.L2CacheSize
t = t + 1
objExcel.Cells(s, t) = objProcItem.Architecture
t = t + 1
objExcel.Cells(s, t) = objProcItem.AddressWidth
Next
t = 1
s = s + 2
'Section header
objExcel.Cells(s, t) = "Physical Memory Information"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column header
objExcel.Cells(s, t) = "Total Physical Memory (MB):"
objExcel.Cells(s, t).Font.Bold = TRUE
t = 1
s = s + 2
'Section header
objExcel.Cells(s, t) = "Video Card Information"
objExcel.Cells(s, t).Font.Bold = TRUE
s = s + 1
t = 1
'Column header
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Description:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Driver Version:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Video Memory (MB):"
objExcel.Cells(s, t).Font.Bold = TRUE
t = 1
s = s + 2
'Section header
objExcel.Cells(s, t) = "NIC Information"
objExcel.Cells(s, t).Font.Bold = TRUE
'Column header
s = s + 1
t = 1
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "MAC Address:"
objExcel.Cells(s, t).Font.Bold = True
t = t + 1
objExcel.Cells(s, t) = "Manufacturer:"
objExcel.Cells(s, t).Font.Bold = TRUE
End Sub
'*******************************************************************************
Sub GetPrinterInfo()
Dim s, t
s = 1
t = 1
'Section header
objExcel.Cells(s, t) = "Printer Information"
objExcel.Cells(s, t).Font.Bold = TRUE
'Column Headers
s = s + 1
t = 1
objExcel.Cells(s, t) = "Default:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Server Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Share Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Driver Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
t = t + 1
objExcel.Cells(s, t) = "Port Name:"
objExcel.Cells(s, t).Font.Bold = TRUE
End Sub
'*******************************************************************************
'Button Actions
'*******************************************************************************
'Start Logging
CreateLog()
End If
'***************************************************************************
****
'Loop through the array of computers, create a workbook with the computer
name,
' get the list of services,
' and write out the services to the excel sheet
'***************************************************************************
****
Next
End Sub
'*******************************************************************************
'This sub is used if a single computer name is put into the text box
Sub InventorySingleComputer()
'Start Logging
CreateLog()
strComputer = SingleComputerName.value
End Sub
'*******************************************************************************
'Use a list of computers from AD to get inventory
Sub InventoryDomainComputers()
On Error Resume Next
'Start Logging
CreateLog()
Dim strDomain
Dim objConnection, objCommand, objRecordSet
Const ADS_SCOPE_SUBTREE = 2
strDomain = DomainComputers.value
objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF
Redim Preserve arrFileLines(i)
arrFileLines(i) = objRecordSet.Fields("Name").Value
i = i + 1
'Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
Next
'*******************************************************************************
'Get a list from AD and display in new window for approval
Sub GetComputersFromAD()
objCommand.CommandText = _
"Select Name, Location from 'LDAP://" & strDomain & "' " _
& "Where objectCategory='computer'"
objCommand.Properties("Page Size") = 500
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF
Redim Preserve arrFileLines(i)
arrFileLines(i) = objRecordSet.Fields("Name").Value
i = i + 1
'Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
DisplayDomainComputers(i)
End Sub
'*******************************************************************************
Sub DisplayDomainComputers(iCount)
'Window title
objExplorer.Document.Title = "Approve Computers"
'Message for status, including the current computer
objExplorer.Document.Body.InnerHTML = iCount & " Computers were found in the
query. " '&_
'"<input id=AcceptADbutton class=""button"" type=""button"" " &_
'"value=""Continue with Inventory..."" name=""AcceptAD_button"" " &_
'"onClick=""CloseIE"">"
Set objLocalWMIService = Nothing
Set objLocalItem = Nothing
Set WshShell = Nothing
Set objConnection = Nothing
Set objCommand = Nothing
Set objRecordSet = Nothing
Set objExplorer = Nothing
End Sub
'*******************************************************************************
'Sub used to change the default directory
Sub ChangeDirectory()
End Sub
'*******************************************************************************
Sub CompletedJob()
'*******************************************************************************
'Used to reload the UI
Sub RefreshHTA()
Location.Reload(True)
End Sub
'*******************************************************************************
'Used to close the UI
Sub CloseHTA()
window.close()
End Sub
'*******************************************************************************
</SCRIPT>
<body>
<table width="100%" border=0>
<tr>
<!--Title-->
<td valign="top"><b><u>Computer Inventory<u><b></td>
</tr>
<tr>
<td valign="top"> </td>
</tr>
<!-- Display the current directory -->
<td valign="top"><span id=DirectorySpan></span></td>
</tr>
<tr>
<!-- Button To change the directory -->
<td valign="top"><input id=changedirectorybutton class="button" type="button"