Write HTML for Browser
'=========================================================
' Name: WriteHTMLBrowser.vbs
' Author: Neal Walters
' http://VBScript-Training.com
'=========================================================
'
' Show two ways to Read a file
' 1) use the ReadAll method to read all text in one "big gulp"
' 2) use the ReadLine method in a loop
' and loop until AtEndOfStream is true
'
' This program also shows how to "filter" and only show lines
' in the source file that match a keyword (see "searchstring").
'
'
'==========================================================================
option explicit
dim myfilename, fso, oshell, forReading, forWriting
dim path, program, fullProgName, myTextStream, ynCreate
dim obj
set fso = CreateObject("Scripting.FileSystemObject")
set oshell = CreateObject("Wscript.Shell")
myfilename = "c:\myhtml.html"
forReading = 1: forWriting = 2: ynCreate = 1
set myTextStream = fso.OpenTextFile(myfilename,forWriting,ynCreate)
myTextStream.Write "<h1>Processes</H1>"
myTextStream.Write "<h2>From WMI - Windows Management Instrumentation</h2>"
myTextStream.Write "<table border=1 cellspacing=2 cellpadding=3>" & vbcrlf
myTextStream.Write "<tr>" & vbcrlf
myTextStream.Write "<th>Process Name</td>" & vbcrlf
myTextStream.Write "<th>PeakWorkingSetSize</td>" & vbcrlf
myTextStream.Write "<th>Priority</td>" & vbcrlf
myTextStream.Write "</tr>" & vbcrlf
for each obj in GetObject("WinMgmts:").instancesOf("Win32_Process")
myTextStream.Write "<tr>" & vbcrlf
myTextStream.Write "<td>" & obj.Caption & "</td>" & vbcrlf
myTextStream.Write "<td>" & obj.PeakWorkingSetSize & "</td>" & vbcrlf
myTextStream.Write "<td>" & obj.Priority & "</td>" & vbcrlf
myTextStream.Write "</tr>" & vbcrlf
next
myTextStream.Write "</table>" & vbcrlf
myTextStream.Close
'path = "C:\Program Files\Internet Explorer"
program = "IEXPLORE"
'FullProgname = path & "\" & program
'WScript.Echo FullProgname
'OShell.Run (program)
OShell.Run (program & " " & myfilename)
'=========================================================
' Name: WriteHTMLBrowserFSO.vbs
'
' Author: Neal Walters
' http://VBScript-Training.com
'=========================================================
' Show two ways to Read a file
' 1) use the ReadAll method to read all text in one "big gulp"
' 2) use the ReadLine method in a loop
' and loop until AtEndOfStream is true
'
' This program also shows how to "filter" and only show lines
' in the source file that match a keyword (see "searchstring").
'=========================================================
option explicit
dim myfilename, myfoldername, fso, oshell, forReading, forWriting
dim path, program, fullProgName, myTextStream, ynCreate
dim file, mycolor
Set fso = CreateObject("Scripting.FileSystemObject")
Set oshell = CreateObject("Wscript.Shell")
myfilename = "ReportFiles.html"
myfoldername = "c:\Camtasia Studio\VBScript-Training2"
If Not fso.FolderExists(myfoldername) Then
WScript.Echo "Folder does not exist: " & myfoldername
WScript.quit
End If
forReading = 1: forWriting = 2: ynCreate = 1
Set myTextStream = fso.OpenTextFile(myfilename,forWriting,ynCreate)
myTextStream.Write "<H1>Files In <font color='red'>" & myfoldername & "</font></H1>"
myTextStream.Write "<table border=1 cellspacing=2 cellpadding=3>" & vbcrlf
myTextStream.Write "<tr>" & vbcrlf
myTextStream.Write "<th>Filename</th>" & vbcrlf
myTextStream.Write "<th>Filesize</th>" & vbcrlf
myTextStream.Write "<th>DateCreated</th>" & vbcrlf
myTextStream.Write "<th>DateModified</th>" & vbcrlf
myTextStream.Write "</tr>" & VbCrLf
for each file In fso.GetFolder(myfoldername).Files
myTextStream.Write "<tr>" & VbCrLf
myTextStream.Write "<td>" & file.Name & "</td>" & VbCrLf
'build syntax: <font color='red'> or <font color='green'>
If file.size > 500 Then
mycolor = "red"
Else
mycolor = "green"
End If
myTextStream.Write "<td><font color='" & mycolor & "'>" & file.size & "<font></td>" & vbcrlf
myTextStream.Write "<td>" & file.DateCreated & "</td>" & vbcrlf
myTextStream.Write "<td>" & file.DateLastModified & "</td>" & vbcrlf
myTextStream.Write "</tr>" & VbCrLf
Next
myTextStream.Write "</table>" & VbCrLf
myTextStream.Close
Dim fqfilename
fqfilename = fso.GetFile(myfilename).path
WScript.Echo "fqfilename=" & fqfilename
'WScript.Quit
'path = "C:\Program Files\Internet Explorer"
program = "IEXPLORE"
'FullProgname = path & "\" & program
'WScript.Echo FullProgname
'OShell.Run (program)
oshell.Run (program & " " & fqfilename)
'============================================================
' Name: WriteHTMLBrowserWMI.vbs
' Author: Neal Walters
' http://VBScript-Training.com
'============================================================
'============================================================
option explicit
dim myfilename, myfoldername, fso, oshell, forReading, forWriting
dim path, program, fullProgName, myTextStream, ynCreate
dim obj
set fso = CreateObject("Scripting.FileSystemObject")
set oshell = CreateObject("Wscript.Shell")
myfilename = "ReportFiles.html"
myfoldername = "C:\FSODEMO"
forReading = 1: forWriting = 2: ynCreate = 1
set myTextStream = fso.OpenTextFile(myfilename,forWriting,ynCreate)
myTextStream.Write "<h1>Files in" & myfoldername & "</H1>"
myTextStream.Write "<table border=1 cellspacing=2 cellpadding=3>" & vbcrlf
myTextStream.Write "<tr>" & vbcrlf
myTextStream.Write "<th>Process Name</td>" & vbcrlf
myTextStream.Write "<th>PeakWorkingSetSize</td>" & vbcrlf
myTextStream.Write "<th>Priority</td>" & vbcrlf
myTextStream.Write "</tr>" & vbcrlf
for each obj in GetObject("WinMgmts:").instancesOf("Win32_Process")
myTextStream.Write "<tr>" & vbcrlf
myTextStream.Write "<td>" & obj.Caption & "</td>" & vbcrlf
myTextStream.Write "<td>" & obj.PeakWorkingSetSize & "</td>" & vbcrlf
myTextStream.Write "<td>" & obj.Priority & "</td>" & vbcrlf
myTextStream.Write "</tr>" & vbcrlf
next
myTextStream.Write "</table>" & vbcrlf
myTextStream.Close
'path = "C:\Program Files\Internet Explorer"
program = "IEXPLORE"
'FullProgname = path & "\" & program
'WScript.Echo FullProgname
'OShell.Run (program)
OShell.Run (program & " " & myfilename)
|