Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

Combining 2 htas to make one hta

Hi nice people.
Guys,
I have 2 hta scripts that I would like to combine into one hta.
I have attached in the code snippet both hta scripts, and have simply called them hta1 (architecture) and hta2 (service pack).
The objective is to:
Be able to select to return just the service pack, or just the architecture, or both service pack and architecture, and output the results in tables.
More explanation is attached in an image i have uploaded.
Any help would be greatly appreciated. Thanks everyone.
'======================================================== hta1 (architecture):
 
<head>
<title>Enumerate System Information on Remote Computers</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Enumerate 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; }
 
 
</style>
 
 
</head>
<script language="vbscript">
Sub Window_onLoad
	intWidth = 600
	intHeight = 480
	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
        Set objFSO = CreateObject("Scripting.FileSystemObject")
 
        If ComputerListFile.Value <> "" Then
                If objFSO.FileExists(ComputerListFile.Value) = True Then
                        Set List = objFSO.OpenTextFile(ComputerListFile.Value, ForReading)
                        
                        strHTML = "<table width='40%' border=1 bgcolor='white'>" &_
                        "<th style='background:c0c0c0'><b>System</b></th><th style='background:c0c0c0'><b>Processor Type</b>"
                        Results.InnerHTML = strHTML
 			strHTML2 = "<table width='40%' border=1>" &_
                        "<th colspan='2' style='background:c0c0c0'><b>Number of Servers with:</b>"
			Totals.InnerHTML = strHTML2
 
			iArch1 = 0
			iArch2 = 0
			iArch3 = 0
			iArch4 = 0
			iArch5 = 0
			iArchU = 0
			iUnreach = 0
                        Do Until List.AtEndOfStream
                                strComputer = List.ReadLine
                                If Ping(strComputer) Then
                                        Set objWMIService = GetObject("winmgmts:" _
                                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                				    Set colProcessors = objWMIService.ExecQuery _
                				    ("Select * From Win32_Processor")
                                        For Each objProcessor in colProcessors
							strArch = "Arch Unknown"
							If objProcessor.Architecture = 0 Then strArch = "x86"
							If objProcessor.Architecture = 1 Then strArch = "MIPS"
							If objProcessor.Architecture = 2 Then strArch = "Alpha"
							If objProcessor.Architecture = 3 Then strArch = "PowerPC"
							If objProcessor.Architecture = 9 Then strArch = "x64"
                                        Next
                                        strHTML =  strHTML &"<tr><td width='40%' border=1>" & strComputer &_
                                        	"</td><td bgcolor='green'><font color='white'>" &strArch & "</font><br>"
					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
                                Else
					iUnreach = iUnreach + 1
                                        strHTML =  strHTML &"<tr><td width='40%'>"& strComputer & "</td><td bgcolor='red'><font color='white'>Unreachable</font></td></tr><br>"
                                End If
                        Loop
			strHTML2 =  strHTML2 &"<tr><td width='80%' border=1>x86"&_
                         	"</td><td>" &iArch1 & "<br>"&_
				"<tr><td width='80%' border=1>MIPS"&_
                         	"</td><td>" &iArch2 & "<br>"&_
				"<tr><td width='80%' border=1>Alpha"&_
                         	"</td><td>" &iArch3 & "<br>"&_
				"<tr><td width='80%' border=1>PowerPC"&_
                         	"</td><td>" &iArch4 & "<br>"&_
				"<tr><td width='80%' border=1>x64"&_
                         	"</td><td>" &iArch5 & "<br>"&_
				"<tr><td width='80%' border=1>Unknown"&_
                         	"</td><td>" &iArchU & "<br>"&_
				"<tr><td width='80%' border=1>Unreachable"&_
                         	"</td><td>" &iUnreach & "<br>"&_
                        List.Close      
                        Totals.InnerHTML = strHTML2 &"</table>"
                        Results.InnerHTML =  strHTML &"</table>"
                Else
                        MsgBox "File does not exist: " & ComputerListFile.Value
                End If
        Else
                MsgBox "Please specify a file name."
        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"> <br><br>
<span id = "Totals"></span><br><br>
<span id = "Results"></span>
</body>
</html>
 
 
' end of hta 1
 
 
 
 
'============================================================ hta2 (service pack):
 
<head>
<title>Enumerate Service Pack on Remote Computers</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Enumerate Service Pack on Remote Computers"
     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; }
 
 
</style>
 
 
</head>
<script language="vbscript">
Sub Window_onLoad
        intWidth = 600
        intHeight = 480
        Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
End Sub
 
Sub GetServicePack
        run_button.disabled = True
        ComputerListFile.disabled = True
        Const ForReading = 1
        Const ForWriting = 2
        Set objFSO = CreateObject("Scripting.FileSystemObject")
 
        If ComputerListFile.Value <> "" Then
                If objFSO.FileExists(ComputerListFile.Value) = True Then
                        Set List = objFSO.OpenTextFile(ComputerListFile.Value, ForReading)
                        
                        strHTML = "<table width='40%' border=1 bgcolor='white'>" &_
                        "<th style='background:c0c0c0'><b>System</b></th><th style='background:c0c0c0'><b>Service Pack</b>"
                        Results.InnerHTML = strHTML
 			strHTML2 = "<table width='40%' border=1>" &_
                        "<th colspan='2' style='background:c0c0c0'><b>Number of Servers with:</b>"
			Totals.InnerHTML = strHTML2
			iSpack1 = 0
			iSpack2 = 0
			iSpackU = 0
			iUnreach = 0
                        Do Until List.AtEndOfStream
                                strComputer = List.ReadLine
                                If Ping(strComputer) Then
 
                                        Set objWMIService = GetObject("winmgmts:" _
                                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                                        Set colSpack = objWMIService.ExecQuery _
                                        ("Select * from Win32_OperatingSystem")
                                        For Each objSpack in colSpack
                                                strSpack = objSpack.ServicePackMajorVersion
                                        Next
 
                                        strHTML =  strHTML &"<tr><td width='40%' border=1>" & strComputer &_
                                        	"</td><td bgcolor='green'><font color='white'>" &strSpack & "</font><br>"
                                	If strSpack = "1" then
						iSpack1=iSpack1+1
					Elseif strSpack = "2" then
						iSpack2=iSpack2+1
					Else
						iSpackU=iSpackU+1
					End If
                                Else
					iUnreach = iUnreach + 1
                                        strHTML =  strHTML &"<tr><td width='40%'>"& strComputer & "</td><td bgcolor='red'><font color='white'>Unreachable</font></td></tr><br>"
                                End If
                        Loop
			strHTML2 =  strHTML2 &"<tr><td width='80%' border=1>Service Pack 1"&_
                         	"</td><td>" &iSpack1 & "<br>"&_
				"<tr><td width='80%' border=1>Service Pack 2"&_
                         	"</td><td>" &iSpack2 & "<br>"&_
				"<tr><td width='80%' border=1>Unknown"&_
                         	"</td><td>" &iSpackU & "<br>"&_
				"<tr><td width='80%' border=1>Unreachable"&_
                         	"</td><td>" &iUnreach & "<br>"&_
                        List.Close      
                        Totals.InnerHTML = strHTML2 &"</table>"
                        Results.InnerHTML =  strHTML &"</table>"
                Else
                        MsgBox "File does not exist: " & ComputerListFile.Value
                End If
        Else
                MsgBox "Please specify a file name."
        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="Get Service Pack" name="run_button" onClick="GetServicePack">
<input type="file" name="ComputerListFile"> <br><br>
<span id = "Totals"></span><br><br>
<span id = "Results"></span>
</body>
</html>

Open in new window

request.jpg
Avatar of TakedaT
TakedaT
Flag of United States of America image

Here you go.
<head>
<title>Enumerate System Information on Remote Computers</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Enumerate 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; }
 
 
</style>
 
 
</head>
<script language="vbscript">
Sub Window_onLoad
	intWidth = 600
	intHeight = 480
	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
SPacks.InnerHTML = "" : Archs.InnerHTML = "" : Totals.InnerHTML = ""
iArch1 = 0 : iArch2 = 0 : iArch3 = 0 : iArch4 = 0 : iArch5 = 0 : iArchU = 0
iSpack1 = 0 : iSpack2 = 0 : iSpackU = 0 : iUnreach = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
If ServicePack.Checked=True or Architecture.Checked=True then 
        If ComputerListFile.Value <> "" Then
                If objFSO.FileExists(ComputerListFile.Value) = True Then
                        Set List = objFSO.OpenTextFile(ComputerListFile.Value, ForReading)
             
  			strTotalHTML = "<table width='40%' border=1 bgcolor='white'>" &_
                        "<th style='background:c0c0c0'><b>System</b></th>"
 
                        If ServicePack.Checked=True then
				strSPHTML = "<table width='40%' border=1>" &_
				"<th colspan='2' style='background:c0c0c0'><b>Number of Servers with:</b>"
				SPacks.InnerHTML = strSPHTML
				strTotalHTML = strTotalHTML&"<th style='background:c0c0c0'><b>Service Pack</b>"
			End If
                        If Architecture.Checked=True then
				strArchHTML = "<table width='40%' border=1>" &_
				"<th colspan='2' style='background:c0c0c0'><b>Number of Servers with:</b>"
				Archs.InnerHTML = strArchHTML
				strTotalHTML = strTotalHTML&"<th style='background:c0c0c0'><b>Processor Type</b>"
			End If
			Totals.InnerHTML = strTotalHTML&"</tr>"
                        Do Until List.AtEndOfStream
				strComputer = List.ReadLine
				strTotalHTML = strTotalHTML &"<tr><td width='40%' border=1>" & strComputer &"</td>"
                                If Ping(strComputer) Then
					Set objWMIService = GetObject("winmgmts:" _
	                                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
                                        If ServicePack.Checked = True then
	                                        Set colSpack = objWMIService.ExecQuery _
	                                        ("Select * from Win32_OperatingSystem")
	                                        For Each objSpack in colSpack
	                                                strSpack = objSpack.ServicePackMajorVersion
	                                        Next
	                                	If strSpack = "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
					If Architecture.Checked=True then
	                			Set colProcessors = objWMIService.ExecQuery _
	                			("Select * From Win32_Processor")
	                                        For Each objProcessor in colProcessors
							If objProcessor.Architecture = 0 Then
								iArch1=iArch1+1
								strArch = "x86"
							Elseif objProcessor.Architecture = 1 Then
								iArch2=iArch2+1
								strArch = "MIPS"
							Elseif objProcessor.Architecture = 2 Then
								iArch3=iArch3+1
								strArch = "Alpha"
							Elseif objProcessor.Architecture = 3 Then
								iArch4=iArch4+1
								strArch = "PowerPC"
							Elseif objProcessor.Architecture = 9 Then
								iArch5=iArch5+1
								strArch = "x64"
							Else
								iArchU=iArchU+1
								strArch = "Arch Unknown"
							End If
	                                        Next
 						strTotalHTML =  strTotalHTML &"<td bgcolor='green'><font color='white'>" &strArch & "</font><br>"
					End If
                                Else
					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
				End If
 
 
                        Loop
 
			If ServicePack.Checked = True then
				strSPHTML =  strSPHTML &"<tr><td width='80%' border=1>Service Pack 1"&_
	                 	"</td><td>" &iSpack1 & "<br>"&_
				"<tr><td width='80%' border=1>Service Pack 2"&_
	                 	"</td><td>" &iSpack2 & "<br>"&_
				"<tr><td width='80%' border=1>Unknown"&_
	                 	"</td><td>" &iSpackU & "<br>"&_
				"<tr><td width='80%' border=1>Unreachable"&_
	                 	"</td><td>" &iUnreach & "<br></table>"
				SPacks.InnerHTML = strSPHTML
			End If
			If Architecture.Checked=True then
				strArchHTML =  strArchHTML &"<tr><td width='80%' border=1>x86"&_
				"</td><td>" &iArch1 & "<br>"&_
				"<tr><td width='80%' border=1>MIPS"&_
				"</td><td>" &iArch2 & "<br>"&_
				"<tr><td width='80%' border=1>Alpha"&_
				"</td><td>" &iArch3 & "<br>"&_
				"<tr><td width='80%' border=1>PowerPC"&_
				"</td><td>" &iArch4 & "<br>"&_
				"<tr><td width='80%' border=1>x64"&_
				"</td><td>" &iArch5 & "<br>"&_
				"<tr><td width='80%' border=1>Unknown"&_
				"</td><td>" &iArchU & "<br>"&_
				"<tr><td width='80%' border=1>Unreachable"&_
				"</td><td>" &iUnreach & "<br></table>"
				Archs.InnerHTML = strArchHTML
			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"><br><br>
Inventory this information:<br><br>
<input type="checkbox" name="ServicePack">Service Pack<br><br>
<input type="checkbox" name="Architecture">Architecture<br><br>
<span id = "Spacks"></span><br>
<span id = "Archs"></span><br>
<span id = "Totals"></span><br><br>
</body>
</html>
 
 

Open in new window

Avatar of Simon336697

ASKER

TakedaT,
Youve done it yet again.
Im going to really understand what you have done, and hopefully learn a great deal from a guru in you :>)
Thanks so much mate.
Tak,
Just one thing if that is ok mate.
It doesnt look like your great script is summing the totals correctly for the architecture?
Eg. for whether the system is an x86, x64 etc.
Could you show me a screen shot as an example?  I dont have the environment to test properly.
Hi Tak,
Here is a screenshot mate. Thanks so much again for your great help :>)
requests.jpg
ASKER CERTIFIED SOLUTION
Avatar of TakedaT
TakedaT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tak, I cant thank you enough. You fixed it :>)
That is awesome Tak.
Take care.
Simon
Brilliant Tak :>)