Simon336697
asked on
Saving results from a hta to a html file
Hi guys,
You great people have helped me with the following hta, which works great.
The only thing Id like to do to this hta is the following:
At the moment, when I click on the "Run Script" button, it outputs the results in the hta window.
Which is what i want.
<Run Script>
Results seen here
What I would like is below:
<Run Script>
Results seen here
<Save results as html file>
So, basically,
1) If you have not clicked on the <Run Script> button, there would be no button for saving the results as a html file, because there are no results yet.
2) When you do click on the <Run Script> button, and the results are returned in the hta, I want a button to display after the results (and only displays when the results have finished being returned).
3) When you click on this new button, you have the option of saving the outputted results as a html file.
Any help greatly appreciated.
You great people have helped me with the following hta, which works great.
The only thing Id like to do to this hta is the following:
At the moment, when I click on the "Run Script" button, it outputs the results in the hta window.
Which is what i want.
<Run Script>
Results seen here
What I would like is below:
<Run Script>
Results seen here
<Save results as html file>
So, basically,
1) If you have not clicked on the <Run Script> button, there would be no button for saving the results as a html file, because there are no results yet.
2) When you do click on the <Run Script> button, and the results are returned in the hta, I want a button to display after the results (and only displays when the results have finished being returned).
3) When you click on this new button, you have the option of saving the outputted results as a html file.
Any help greatly appreciated.
<head>
<title>KPMG: Multicomputer System Information</title>
<HTA:APPLICATION
APPLICATIONNAME="KPMG: Multicomputer System Information"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<style type="text/css">
html {
font-family:arial;
font-size:smaller;
}
table {
border-collapse:collapse;
border:solid 1px black;
font-family:arial;
font-size:0.8em;
}
tr, td, th {
border-collapse:collapse;
border-style:solid;
}
td { border-width: 1px; }
.checks { background: #2554C7;
color:white;
border-collapse:collapse;
border:solid 1px black;
cellpadding:1px;
padding:3px;
width:100%;
}
</style>
</head>
<script language="vbscript">
Sub Window_onLoad
intWidth = 800
intHeight = 580
Me.ResizeTo intWidth, intHeight
Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
End Sub
Sub GetInfo
run_button.disabled = True
ComputerListFile.disabled = True
Const ForReading = 1
Const ForWriting = 2
'--------------------------------------------------------
'1) Set the SPAN IDs to nothing:
'--------------------------------------------------------
SPacks.InnerHTML = "" : Archs.InnerHTML = "" : OS.InnerHTML ="" : ModelDetail.InnerHTML ="" : PSPDetail.InnerHTML ="" : Totals.InnerHTML = ""
'--------------------------------------------------------
'2) Initialize variables for each possible value returned:
'--------------------------------------------------------
iArch1 = 0 : iArch2 = 0 : iArch3 = 0 : iArch4 = 0 : iArch5 = 0 : iArchU = 0
iSpack1 = 0 : iSpack2 = 0 : iSpackU = 0 : iUnreach = 0
iOS1 = 0 : iOS2 = 0 : iOS3 = 0 : iOS4 = 0 : iOS5 = 0 : iOSU = 0
iModel1 = 0 : iModel2 = 0 : iModel3 = 0 : iModel4 = 0 : iModel5 = 0 : iModel6 = 0 : iModel6 = 0 : iModel7 = 0 : iModel8 = 0 : iModel9 = 0 : iModel10 = 0 : iModelU = 0
iPSP1 = 0 : iPSP2 = 0 : iPSP3 = 0 : iPSP4 = 0 : iPSP5 = 0 : iPSP6 = 0 : iPSP7 = 0 : iPSP8 = 0 : iPSP9 = 0 : iPSPU = 0
'--------------------------------------------------------
'3) Create an object for the Text File:
'--------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
'--------------------------------------------------------
'4) Determine what checkboxes have been checked:
'--------------------------------------------------------
If ServicePack.Checked=True or Architecture.Checked=True or OperatingSystem.Checked=True or Model.Checked=True or PSP.Checked=True then
'--------------------------------------------------------
'5) If the text file read does have entries, then define a variable "List" to hold its contents:
'--------------------------------------------------------
If ComputerListFile.Value <> "" Then
If objFSO.FileExists(ComputerListFile.Value) = True Then
Set List = objFSO.OpenTextFile(ComputerListFile.Value, ForReading)
'--------------------------------------------------------
'6) Define a variable "strTotalHTML" to build a table:
'--------------------------------------------------------
strTotalHTML = "<table width='100%' border=1 bgcolor='white'>" &_
"<th style='background:black; color:white;'><b>System</b></th>"
'--------------------------------------------------------
'7) If a checkbox is checked, build a table for it:
'--------------------------------------------------------
'Service Pack:
If ServicePack.Checked=True then
strSPHTML = "<table width='100%' border=1>" &_
"<th colspan='2' style='background:black; color:white;'><b>Service Pack Totals:</b>"
SPacks.InnerHTML = strSPHTML
strTotalHTML = strTotalHTML&"<th style='background:black; color:white;'><b>Service Pack</b>"
End If
'Architecture:
If Architecture.Checked=True then
strArchHTML = "<table width='100%' border=1>" &_
"<th colspan='2' style='background:black; color:white;'><b>Architecture Totals:</b>"
Archs.InnerHTML = strArchHTML
strTotalHTML = strTotalHTML&"<th style='background:black; color:white;'><b>Architecture</b>"
End If
'OperatingSystem:
If OperatingSystem.Checked=True then
strOSHTML = "<table width='100%' border=1>" &_
"<th colspan='2' style='background:black; color:white;'><b>Operating System Totals:</b>"
OS.InnerHTML = strOSHTML
strTotalHTML = strTotalHTML&"<th style='background:black; color:white;'><b>Operating System</b>"
End If
'Model:
If Model.Checked=True then
strModelHTML = "<table width='100%' border=1>" &_
"<th colspan='2' style='background:black; color:white;'><b>Model Audit Totals:</b>"
ModelDetail.InnerHTML = strModelHTML
strTotalHTML = strTotalHTML&"<th style='background:black; color:white;'><b>Model</b>"
End If
'PSP:
If PSP.Checked=True then
strPSPHTML = "<table width='100%' border=1>" &_
"<th colspan='2' style='background:black; color:white;'><b>PSP Version Totals:</b>"
PSPDetail.InnerHTML = strPSPHTML
strTotalHTML = strTotalHTML&"<th style='background:black; color:white;'><b>PSP</b>"
End If
Totals.InnerHTML = strTotalHTML&"</tr>"
Do Until List.AtEndOfStream
strComputer = List.ReadLine
strTotalHTML = strTotalHTML &"<tr><td width='15%' border=1>" & strComputer &"</td>"
'The following line will enable the script to continue to run if there is a problem.
On Error Resume Next
If Ping(strComputer) Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'--------------------------------------------------------
'8) If a checkbox is checked, then create a query for that selection:
'--------------------------------------------------------
'Service Pack:
If ServicePack.Checked = True then
Set colSpack = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objSpack in colSpack
strSpack = objSpack.ServicePackMajorVersion
Next
If strSpack = "Service Pack 1" then
iSpack1=iSpack1+1
Elseif strSpack = "2" then
iSpack2=iSpack2+1
Else
iSpackU=iSpackU+1
End If
strTotalHTML = strTotalHTML &"<td bgcolor='green'><font color='white'>" &strSpack & "</font><br>"
End If
'Architecture:
If Architecture.Checked=True then
Set colProcessors = objWMIService.ExecQuery _
("Select * From Win32_Processor")
For Each objProcessor in colProcessors
If objProcessor.Architecture = 0 Then
strArch = "x86"
Elseif objProcessor.Architecture = 1 Then
strArch = "MIPS"
Elseif objProcessor.Architecture = 2 Then
strArch = "Alpha"
Elseif objProcessor.Architecture = 3 Then
strArch = "PowerPC"
Elseif objProcessor.Architecture = 9 Then
strArch = "x64"
Else
strArch = "Arch Unknown"
End If
Next
If strArch = "x86" then
iArch1=iArch1+1
Elseif strArch = "MIPS" then
iArch2=iArch2+1
Elseif strArch = "Alpha" then
iArch3=iArch3+1
Elseif strArch = "PowerPC" then
iArch4=iArch4+1
Elseif strArch = "x64" then
iArch5=iArch5+1
Else
iArchU=iArchU+1
End If
strTotalHTML = strTotalHTML &"<td bgcolor='green'><font color='white'>" &strArch & "</font><br>"
End If
'OperatingSystem:
If OperatingSystem.Checked=True then
Set colOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each objOS in colOS
strOS = objOS.Caption
Next
If strOS = "Microsoft(R) Windows(R) Server 2003, Standard Edition" then
iOS1=iOS1+1
Elseif strOS = "Microsoft(R) Windows(R) Server 2003, Enterprise Edition" then
iOS2=iOS2+1
Elseif strOS = "Microsoft(R) Windows(R) Server 2003 Standard x64 Edition" then
iOS3=iOS3+1
Elseif strOS = "Microsoft Windows 2000 Server" then
iOS4=iOS4+1
Elseif strOS = "Microsoft Windows XP Professional" then
iOS5=iOS5+1
Else
iOSU=iOSU+1
End If
strTotalHTML = strTotalHTML &"<td bgcolor='green'><font color='white'>" &strOS & "</font><br>"
End If
'Model:
If Model.Checked=True then
Set colModels = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each objPlatform in colModels
strModel = objPlatform.Model
Next
If strModel = "VMware Virtual Platform" then
iModel1=iModel1+1
Elseif strModel = "ProLiant ML370" then
iModel2=iModel2+1
Elseif strModel = "ProLiant DL385 G1" then
iModel3=iModel3+1
Elseif strModel = "ProLiant DL380 G2" then
iModel4=iModel4+1
Elseif strModel = "ProLiant DL380 G3" then
iModel5=iModel5+1
Elseif strModel = "ProLiant DL380 G4" then
iModel6=iModel6+1
Elseif strModel = "ProLiant DL380 G5" then
iModel7=iModel7+1
Elseif strModel = "PowerEdge 2650" then
iModel8=iModel8+1
Elseif strModel = "PowerEdge 2850" then
iModel9=iModel9+1
Elseif strModel = "OptiPlex 755" then
iModel10=iModel10+1
Else
iModelU=iModelU+1
End If
strTotalHTML = strTotalHTML &"<td bgcolor='green'><font color='white'>" &strModel & "</font><br>"
End If
'PSP:
If PSP.Checked=True then
Set objectFSO = CreateObject("Scripting.FileSystemObject")
strFileToFind = "C:\Windows\System32\cpqmgmt\agentver.dll"
'If Err.Number = 0 Then On Error GoTo 0
'Get PSP Version (Search for the PSP file, replacing the c:\ with c$):
'-----------------------------------------------------
strUNCFile = "\\" & strComputer & "\" & Replace(strFileToFind, ":", "$")
If objectFSO.FileExists(strUNCFile) = True Then strPSP = objectFSO.GetFileVersion(strUNCFile) Else strPSP = "File Not there"
If strPSP = "6.40.0.0" then
iPSP1=iPSP1+1
Elseif strPSP = "7.30.0.0" then
iPSP2=iPSP2+1
Elseif strPSP = "7.40.0.0" then
iPSP3=iPSP3+1
Elseif strPSP = "7.51.0.0" then
iPSP4=iPSP4+1
Elseif strPSP = "7.70.0.0" then
iPSP5=iPSP5+1
Elseif strPSP = "7.90.0.0" then
iPSP6=iPSP6+1
Elseif strPSP = "7.91.0.0" then
iPSP7=iPSP7+1
Elseif strPSP = "8.0.0.0" then
iPSP8=iPSP8+1
Elseif strPSP = "8.15.0.0" then
iPSP9=iPSP9+1
Else
iPSPU=iPSPU+1
End If
strTotalHTML = strTotalHTML &"<td bgcolor='green'><font color='white'>" &strPSP & "</font><br>"
End If
Else
'--------------------------------------------------------
'9) Factor in unreachable machines:
'--------------------------------------------------------
iUnreach = iUnreach + 1
If ServicePack.Checked = True then
strTotalHTML = strTotalHTML &"<td bgcolor='red'><font color='white'>Unreachable</font></td>"
End If
If Architecture.Checked=True then
strTotalHTML = strTotalHTML &"<td bgcolor='red'><font color='white'>Unreachable</font></td>"
End If
If OperatingSystem.Checked=True then
strTotalHTML = strTotalHTML &"<td bgcolor='red'><font color='white'>Unreachable</font></td>"
End If
If Model.Checked=True then
strTotalHTML = strTotalHTML &"<td bgcolor='red'><font color='white'>Unreachable</font></td>"
End If
If PSP.Checked=True then
strTotalHTML = strTotalHTML &"<td bgcolor='red'><font color='white'>Unreachable</font></td>"
End If
End If
Loop
If ServicePack.Checked = True then
strSPHTML = strSPHTML &"<tr style='background:#A9F5A9;'><td width='80%' border=1>Service Pack 1"&_
"</td><td style='background:#72AB72; color:white;'>" &iSpack1 & "<br>"&_
"<tr style='background:#A9F5A9;'><td width='80%' border=1>Service Pack 2"&_
"</td><td style='background:#72AB72; color:white;'>" &iSpack2 & "<br>"&_
"<tr style='background:#A9F5A9;'><td width='80%' border=1>Unknown"&_
"</td><td style='background:#72AB72; color:white;'>" &iSpackU & "<br>"&_
"<tr style='background:#A9F5A9;'><td width='80%' border=1>Unreachable"&_
"</td><td style='background:#72AB72; color:white;'>" &iUnreach & "<br></table>"
SPacks.InnerHTML = strSPHTML
End If
If Architecture.Checked=True then
strArchHTML = strArchHTML &"<tr style='background:#F2F5A9;'><td width='80%' border=1>x86"&_
"</td><td style='background:#957F53; color:white;'>" &iArch1 & "<br>"&_
"<tr style='background:#F2F5A9;'><td width='80%' border=1>MIPS"&_
"</td><td style='background:#957F53; color:white;'>" &iArch2 & "<br>"&_
"<tr style='background:#F2F5A9;'><td width='80%' border=1>Alpha"&_
"</td><td style='background:#957F53; color:white;'>" &iArch3 & "<br>"&_
"<tr style='background:#F2F5A9;'><td width='80%' border=1>PowerPC"&_
"</td><td style='background:#957F53; color:white;'>" &iArch4 & "<br>"&_
"<tr style='background:#F2F5A9;'><td width='80%' border=1>x64"&_
"</td><td style='background:#957F53; color:white;'>" &iArch5 & "<br>"&_
"<tr style='background:#F2F5A9;'><td width='80%' border=1>Unknown"&_
"</td><td style='background:#957F53; color:white;'>" &iArchU & "<br>"&_
"<tr style='background:#F2F5A9;'><td width='80%' border=1>Unreachable"&_
"</td><td style='background:#957F53; color:white;'>" &iUnreach & "<br></table>"
Archs.InnerHTML = strArchHTML
End If
If OperatingSystem.Checked=True then
strOSHTML = strOSHTML &"<tr style='background:#E7D6BF;'><td width='80%' border=1>Microsoft(R) Windows(R) Server 2003, Standard Edition"&_
"</td><td style='background:#B40404; color:white;'>" &iOS1 & "<br>"&_
"<tr style='background:#E7D6BF;'><td width='80%' border=1>Microsoft(R) Windows(R) Server 2003, Enterprise Edition"&_
"</td><td style='background:#B40404; color:white;'>" &iOS2 & "<br>"&_
"<tr style='background:#E7D6BF;'><td width='80%' border=1>Microsoft(R) Windows(R) Server 2003 Standard x64 Edition"&_
"</td><td style='background:#B40404; color:white;'>" &iOS3 & "<br>"&_
"<tr style='background:#E7D6BF;'><td width='80%' border=1>Microsoft Windows 2000 Server"&_
"</td><td style='background:#B40404; color:white;'>" &iOS4 & "<br>"&_
"<tr style='background:#E7D6BF;'><td width='80%' border=1>Microsoft Windows XP Professional"&_
"</td><td style='background:#B40404; color:white;'>" &iOS5 & "<br>"&_
"<tr style='background:#E7D6BF;'><td width='80%' border=1>Unknown"&_
"</td><td style='background:#B40404; color:white;'>" &iOSU & "<br>"&_
"<tr style='background:#E7D6BF;'><td width='80%' border=1>Unreachable"&_
"</td><td style='background:#B40404; color:white;'>" &iUnreach & "<br></table>"
OS.InnerHTML = strOSHTML
End If
If Model.Checked=True then
strModelHTML = strModelHTML &"<tr style='background:#AFC7C7;'><td width='80%' border=1>VMware Virtual Platform"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel1 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>ProLiant ML370"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel2 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>ProLiant DL385 G1"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel3 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>ProLiant DL380 G2"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel4 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>ProLiant DL380 G3"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel5 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>ProLiant DL380 G4"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel6 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>ProLiant DL380 G5"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel7 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>PowerEdge 2650"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel8 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>PowerEdge 2850"&_
"</td><td style='background:#5E767E; color:white;'>" &iModel9 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>OptiPlex 755 "&_
"</td><td style='background:#5E767E; color:white;'>" &iModel10 & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>Unknown"&_
"</td><td style='background:#5E767E; color:white;'>" &iModelU & "<br>"&_
"<tr style='background:#AFC7C7;'><td width='80%' border=1>Unreachable"&_
"</td><td style='background:#5E767E; color:white;'>" &iUnreach & "<br></table>"
ModelDetail.InnerHTML = strModelHTML
End If
If PSP.Checked=True then
strPSPHTML = strPSPHTML &"<tr style='background:#FDD017;'><td width='80%' border=1>6.40.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP1 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>7.30.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP2 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>7.40.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP3 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>7.51.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP4 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>7.70.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP5 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>7.90.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP6 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>7.91.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP7 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>8.0.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP8 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>8.15.0.0"&_
"</td><td style='background:#C58917; color:white;'>" &iPSP9 & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>Unknown"&_
"</td><td style='background:#C58917; color:white;'>" &iPSPU & "<br>"&_
"<tr style='background:#FDD017;'><td width='80%' border=1>Unreachable"&_
"</td><td style='background:#C58917; color:white;'>" &iUnreach & "<br></table>"
PSPDetail.InnerHTML = strPSPHTML
End If
Totals.InnerHTML = strTotalHTML
List.Close
Else
MsgBox "File does not exist: " & ComputerListFile.Value
End If
run_button.disabled = False
ComputerListFile.disabled = False
Else
MsgBox "Please specify a file name."
End If
run_button.disabled = False
ComputerListFile.disabled = False
Else
MsgBox "You must pick at least 1 option."
End If
run_button.disabled = False
ComputerListFile.disabled = False
End Sub
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
</script>
<body>
<input type="button" value="Run Script" name="run_button" onClick="GetInfo">
<input type="file" name="ComputerListFile" value="servers.txt"> Select a text file that lists computernames ...<br><br>
<u>Inventory this information:</u><br><br>
<div class="checks" style="float:left;">
<input type="checkbox" name="ServicePack">Service Pack
<input type="checkbox" name="Architecture">Architecture
<input type="checkbox" name="OperatingSystem">Operating System
<input type="checkbox" name="Model">Model
<input type="checkbox" name="PSP">PSP</div><br><br><br>
<!-- -------------------------------------------------------- -->
<!-- 7) Create the SPANs to hold the data: -->
<!-- -------------------------------------------------------- -->
<u>Summary Information:</u><br><br>
<span id = "Spacks"></span><br>
<span id = "Archs"></span><br>
<span id = "OS"></span><br>
<span id = "ModelDetail"></span><br>
<span id = "PSPDetail"></span><br>
<u>Systems Information:</u><br><br>
<span id = "Totals"></span><br><br>
</body>
</html>
ASKER
Rob that works flawlessly Rob cannot thank you enough.
Rob, if you want me to post another q on this I dont mind.
But if I wanted to instead, save the results to a csv file, would there be much difference in the sub?
You are brilliant (wont say that again :>))
Rob, if you want me to post another q on this I dont mind.
But if I wanted to instead, save the results to a csv file, would there be much difference in the sub?
You are brilliant (wont say that again :>))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are the best Rob.
Thanks. Thanks for the grade too.
Glad to help.
Rob.
Glad to help.
Rob.
Regards,
Rob.
Open in new window