Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using InnnerHTML problem

Posted on 2009-05-03
7
Medium Priority
?
300 Views
Last Modified: 2012-08-30
Guys, im stumped on this.
Im trying to use InnertHTML but im sure there is a problem:

Line 53:
Unknown runtime error.

Any help greatly appreciated.
<html>
<!-------------------------------------------------------------------------
  Get the Service Pack of a list of systems from servfers.txt
---------------------------------------------------------------------------->
 
<head>
<title>Service Pack Information</title>
<HTA:APPLICATION ID="oHTA"
    APPLICATIONNAME="Service Pack Information"
    SINGLEINSTANCE="yes"
    NAVIGABLE="yes"
   >
 
<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 {
border:solid 1px black;
}
 
</style>
 
 
</head>
 
<body>
 
<p><h2 align=center><font color=red>Service Pack Information</font></h2>
<div align=right>S Harding  04/05/2009</div><hr size=1>
This hta application uses VBScript and WMI to enumerate the service pack for systems in a text file.<p>
 
<script language="VBScript">
 
Sub GetServicePack
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strComputersFile = "servers.txt"
Set objComputers = objFSO.OpenTextFile(strComputersFile, intForReading, False)
 
DataArea.InnerHTML = "<center><table width='40%' border=1 bgcolor='white'><tr><td style='background:c0c0c0'>" & "<b>System</b>" & "</td><td style='background:c0c0c0'>" & 
 
"<b>Service Pack</b>" & "</td></tr>"
 
While Not objComputers.AtEndOfStream
	strComputer =   objComputers.ReadLine
 
        'If you can connect to the machine, then get the Service pack:
        If Ping(strComputer) = True Then
 
        On Error Resume Next
                Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
                If Err.Number = 0 Then On Error GoTo 0
 
                'Get Service Pack:
                '-----------------------------------------------------
                Set colSpack = objWMIService.ExecQuery _
                ("Select * from Win32_OperatingSystem")
 
                For Each objSpack in colSpack
                        strSpack = objSpack.ServicePackMajorVersion
                Next
 
 		DataArea.InnerHTML =  "<tr><td>" & strComputer & "</td><td>" & strSpack & "</td></tr>"
	Else
 
		DataArea.InnerHTML =  "<tr><td>" & strComputer & "</td><td style='background:black;'>" & "<font color='red'>Unreachable</font>" & "</td></tr>"
 
        End If
 
  
Wend
 
objComputers.Close
DataArea.InnerHTML =  "</table></center>"
 
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>
<span id=DataArea>This is a span area named DataArea</span>
<input id=getsp  class="button" type="button" value="Get Service Pack" name="getsp_button"  onClick="GetServicePack">
</body>
</html>

Open in new window

0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 16

Assisted Solution

by:Peter Kwan
Peter Kwan earned 440 total points
ID: 24293438
I found that in Line 53, the line ends with a character & and the remaining of the line starts at line 55, which is not allowed. In case you have multiple lines, you need to
add an underscore character "_" (without quotes) afterwards like this:
<html>
<!-------------------------------------------------------------------------
  Get the Service Pack of a list of systems from servfers.txt
---------------------------------------------------------------------------->
 
<head>
<title>Service Pack Information</title>
<HTA:APPLICATION ID="oHTA"
    APPLICATIONNAME="Service Pack Information"
    SINGLEINSTANCE="yes"
    NAVIGABLE="yes"
   >
 
<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 {
border:solid 1px black;
}
 
</style>
 
 
</head>
 
<body>
 
<p><h2 align=center><font color=red>Service Pack Information</font></h2>
<div align=right>S Harding  04/05/2009</div><hr size=1>
This hta application uses VBScript and WMI to enumerate the service pack for systems in a text file.<p>
 
<script language="VBScript">
 
Sub GetServicePack
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strComputersFile = "servers.txt"
Set objComputers = objFSO.OpenTextFile(strComputersFile, intForReading, False)
 
DataArea.InnerHTML = "<center><table width='40%' border=1 bgcolor='white'><tr><td style='background:c0c0c0'>" & "<b>System</b>" & "</td><td style='background:c0c0c0'>" & _
"<b>Service Pack</b>" & "</td></tr>"
 
While Not objComputers.AtEndOfStream
        strComputer =   objComputers.ReadLine
 
        'If you can connect to the machine, then get the Service pack:
        If Ping(strComputer) = True Then
 
        On Error Resume Next
                Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
                If Err.Number = 0 Then On Error GoTo 0
 
                'Get Service Pack:
                '-----------------------------------------------------
                Set colSpack = objWMIService.ExecQuery _
                ("Select * from Win32_OperatingSystem")
 
                For Each objSpack in colSpack
                        strSpack = objSpack.ServicePackMajorVersion
                Next
 
                DataArea.InnerHTML =  "<tr><td>" & strComputer & "</td><td>" & strSpack & "</td></tr>"
        Else
 
                DataArea.InnerHTML =  "<tr><td>" & strComputer & "</td><td style='background:black;'>" & "<font color='red'>Unreachable</font>" & "</td></tr>"
 
        End If
 
  
Wend
 
objComputers.Close
DataArea.InnerHTML =  "</table></center>"
 
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>
<span id=DataArea>This is a span area named DataArea</span>
<input id=getsp  class="button" type="button" value="Get Service Pack" name="getsp_button"  onClick="GetServicePack">
</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24299666
Hi pkwan, thanks so much for your help.
pk, im still getting a runtime error on line 53.
It looks like the DataArea.InnerHTML might be the problem? Just cant figure it out <:(
0
 
LVL 10

Accepted Solution

by:
TakedaT earned 1560 total points
ID: 24300070
I got it to work.  I rearranged it a lot.  It didnt seem to like the <center> tag where it was.  I also had it write everything to a string first, then when its done, it displays the string in the innerhtml part (may take some time depending on how long your list of computers is).  I dont have too much experience with hta's (my html skill is weak), but from what I know, its better to make a string then do the string in one shot.
<!-------------------------------------------------------------------------
Get the Service Pack of a list of systems from servfers.txt
---------------------------------------------------------------------------->
 
<head>
<title>Service Pack Information</title>
<HTA:APPLICATION ID="oHTA"
	APPLICATIONNAME="Service Pack Information"
	SINGLEINSTANCE="yes"
	NAVIGABLE="yes"
>
 
 
 
 
</head>
<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 {
border:solid 1px black;
}
 
</style>
 
 
 
<script language="VBScript">
 
Sub GetServicePack
 
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Const intForReading = 1
	strComputersFile = "servers.txt"
	Set objComputers = objFSO.OpenTextFile(strComputersFile, intForReading, False)
	strHTML = "<table width='40%' border=1 bgcolor='white'><th style='background:c0c0c0'>" & "<b>System</b>" & "</th><th style='background:c0c0c0'>" & _
	"<b>Service Pack</b>"
	DataArea.InnerHTML = strHTML
	
	While Not objComputers.AtEndOfStream
		strComputer =   objComputers.ReadLine
		
		'If you can connect to the machine, then get the Service pack:
		If Ping(strComputer) = True Then
			
			'On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" _
			& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
			
			'If Err.Number = 0 Then On Error GoTo 0
			
			'Get Service Pack:
			'-----------------------------------------------------
			Set colSpack = objWMIService.ExecQuery _
			("Select * from Win32_OperatingSystem")
			
			For Each objSpack in colSpack
				strSpack = objSpack.ServicePackMajorVersion
			Next
			
			strHTML =  strHTML&"<tr><td><center>" & strComputer & "</td><td><center>" & strSpack
		Else
			
			strHTML =  strHTML&"<tr><td><center>" & strComputer & "</td><td style='background:black;'><center>" & "<font color='red'>Unreachable</font>"
			
		End If
	Wend
	
	objComputers.Close
	DataArea.InnerHTML =  strHTML&"</table>"
 
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>
 
<p><h2 align=center><font color=red>Service Pack Information</font></h2>
<div align=right>S Harding  04/05/2009</div><hr size=1>
This hta application uses VBScript and WMI to enumerate the service pack for systems in a text file.<p>
<span id=DataArea>This is a span area named DataArea</span><br>
<input id=getsp  class="button" type="button" value="Get Service Pack" name="getsp_button"  onClick="GetServicePack">
</body>

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:Simon336697
ID: 24300376
TakedaT THAT IS BRILLIANT BRILLIANT that works!
Thank you so much mate.
pkwan youre a champion too.
I am in awe of your guy's knowledege and cannot thank you both enough :>)
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24300400
TakedaT i hope you dont mind me asking 1 final question about this.
What you have done is excellent.
Is there a way to slightly modify your code so that:

1) Instead of hardcoding the text file

strComputersFile = "servers.txt"  (line 46)

2) You can create a browse button, and point to a text file of your choice?

So, instead of hardcoding

strComputersFile = "servers.txt"

You would have something like:

Please select a file to process ___________  <Browse>

Then the script would process that chosen file instead?

You are fantastic guys.
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24300589
Here you go.  Now, this will ONLY work in windows XP.  You will get errors on other operating systems if you try to run it.  Even on this pc im on now wont run it (vista).
<!-------------------------------------------------------------------------
Get the Service Pack of a list of systems from servfers.txt
---------------------------------------------------------------------------->
 
<head>
<title>Service Pack Information</title>
<HTA:APPLICATION ID="oHTA"
	APPLICATIONNAME="Service Pack Information"
	SINGLEINSTANCE="yes"
	NAVIGABLE="yes"
>
 
</head>
<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 {
border:solid 1px black;
}
 
</style>
 
<script language="VBScript">
 
Sub GetServicePack
	currentDir = right(location.pathname,instrrev(location.pathname,"\"))
	Set objDialog = CreateObject("UserAccounts.CommonDialog")
	objDialog.Filter = "Text Files|*.txt|All Files|*.*"
	objDialog.FilterIndex = 1
	objDialog.InitialDir = currentDir
	intResult = objDialog.ShowOpen
	If intResult = 0 Then
		MsgBox "Failed to open a file"
		window.close
	End If
	strComputersFile = objDialog.FIlename
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Const intForReading = 1
 
	Set objComputers = objFSO.OpenTextFile(strComputersFile, intForReading, False)
	strHTML = "<table width='40%' border=1 bgcolor='white'><th style='background:c0c0c0'>" & "<b>System</b>" & "</th><th style='background:c0c0c0'>" & _
	"<b>Service Pack</b>"
	DataArea.InnerHTML = strHTML
	
	While Not objComputers.AtEndOfStream
		strComputer =   objComputers.ReadLine
		
		'If you can connect to the machine, then get the Service pack:
		If Ping(strComputer) = True Then
			
			'On Error Resume Next
			Set objWMIService = GetObject("winmgmts:" _
			& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
			
			'If Err.Number = 0 Then On Error GoTo 0
			
			'Get Service Pack:
			'-----------------------------------------------------
			Set colSpack = objWMIService.ExecQuery _
			("Select * from Win32_OperatingSystem")
			
			For Each objSpack in colSpack
				strSpack = objSpack.ServicePackMajorVersion
			Next
			
			strHTML =  strHTML&"<tr><td><center>" & strComputer & "</td><td><center>" & strSpack
		Else
			
			strHTML =  strHTML&"<tr><td><center>" & strComputer & "</td><td style='background:black;'><center>" & "<font color='red'>Unreachable</font>"
			
		End If
	Wend
	
	objComputers.Close
	DataArea.InnerHTML =  strHTML&"</table>"
 
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>
 
<p><h2 align=center><font color=red>Service Pack Information</font></h2>
<div align=right>S Harding  04/05/2009</div><hr size=1>
This hta application uses VBScript and WMI to enumerate the service pack for systems in a text file.<p>
<span id=DataArea>This is a span area named DataArea</span><br>
<input id=getsp  class="button" type="button" value="Get Service Pack" name="getsp_button"  onClick="GetServicePack">
</body>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24300858
Hi TakedaT, youre a genius.

Those new lines you added.....if you wanted to create a new button to click so that this new button would prompt you for a text file, could you do that?
So, you would have:


<Click to point to a filename>
<Click to Get Service Pack>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question