'
' Read a CSV file to HTML page.
' From 'Read a CSV file' to console.
' JB 2012
' Updated: 11:16 2012-02-22
'
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
'--
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
'--
Dim fso, f, ts
'--
Dim strHTML, strHTML1
'--
Dim strFile
'--
Dim strHeader
'-- System report first.
strFile = "_system.txt"
'--
strHeader = "This is a system report on this PC."
'--
Set fso = CreateObject("Scripting.FileSystemObject")
'--
Set f = fso.GetFile(strFile)
'
Set ts = f.OpenAsTextStream(ForReading, TristateFalse)
'--
strHTML1 = Replace( ts.ReadAll, vbCR, "
" )
strHTML1 = Replace( strHTML1, " >> ", "" )
strHTML1 = Replace( strHTML1, " << ", "" )
'
ts.Close
'
'-- Software report second.
strFile = "_software.csv"
'--
strPathtoTextFile = "."
'--
strHeader = "This is a report on software installed on this PC."
'--
strOrder = "Caption"
'--
strHTML1 = strHTML1 & WriteHTML( strFile, strPathtoTextFile, strHeader, strOrder )
'--
'-- Services report third.
strFile = "_services.csv"
'--
strPathtoTextFile = "."
'--
strHeader = "This is a report on services running now on this PC."
'--
strOrder = "Process Name"
'--
strHTML = strHTML1 & WriteHTML( strFile, strPathtoTextFile, strHeader, strOrder )
'--
'-- Show it off!
ReadHTMLString strHTML
'--
Wscript.quit 0
'
ErrEx:
Msgbox "Program error! " & Err.Description, 64
'
Wscript.quit 1
Function WriteHTML(strFile, strPathtoTextFile, strHeader, strOrder)
'
'
'
'--
Dim strHTML
'--
Set objConnection = CreateObject("ADODB.Connection")
'--
Set objRecordSet = CreateObject("ADODB.Recordset")
'
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""
'-- This worked! Sorting alphabetically the caption
'
objRecordset.Open "SELECT * FROM " & strFile & " ORDER BY [" & strOrder & "]" , _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
'--
strHTML = "
" & objRecordset.Fields.Item(n).Name & " | " Next '-- Do Until objRecordset.EOF '-- strHTML = strHTML & "
" & objRecordset.Fields.Item(n) & " | " '-- Next '-- strHTML = strHTML & "