?
Solved

HTA "save as" box and check box selections

Posted on 2009-04-24
7
Medium Priority
?
1,486 Views
Last Modified: 2012-05-06
I'd like to have the following script save to an XML file that has to be specified in a text box. I've commented out a end sub and a sub beginning because I'm uncertain how to run them properly. I'd like to add other sub's and select them from check boxes. If the check box is not checked, don't run that sub, but default to all checked. Output should always be to a file, and should error if a name isn't given. I don't believe I should use InnerHTML as well, because the output I get currently ignores the xml opening tag.
<head>
<title>Operating System Version</title>
<HTA:APPLICATION
     APPLICATIONNAME="Inventory HTA"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
 
Sub OS_Info
'If OS_Info.Checked Then
	strComputer = BasicTextBox.Value
	Set objWMIService = GetObject("winmgmts:\\" & strComputer &  "\root\cimv2")
	Set colOperatingSystems = objWMIService.ExecQuery  ("Select * from Win32_OperatingSystem",,48)
	For Each objOperatingSystem in colOperatingSystems
		DataArea.InnerHTML = "<os>" & objOperatingSystem.Caption & " " & objOperatingSystem.Version & "</os>"
	Next
'	Else
'End If
'End Sub
'Sub Output
	Set objFSO = CreateObject("Scripting.FileSystemObject")
		objFSO.CreateTextFile("Output.xml")
	Set objFile = objFSO.OpenTextFile("Output.xml", 2)
		objFile.WriteLine DataArea.InnerHTML
		objFile.Close
End Sub
 
'Sub BIOS_Info
' If BasicCheckbox.Checked Then
'		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
'		Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",,48)
'	For Each objItem In colItems
'   	DataArea.InnerHTML = "<serial>" & objItem.SerialNumber & "</serial>"
'	Next
'    Else
'   End If
'End Sub
</script>
 
<body>
<input type="text" name="BasicTextBox" size="50" />
<input type="checkbox"name="OS_Info"value="OS_Info"> OS
<input type="checkbox"name="BIOS_Info"value="BIOS_Info"> BIOS
<input type="button" value="Operating System" name="run_button"  onClick="OS_Info" />
<p><span id=DataArea>Output will be saved to Output.xml</span></p>
 
</body>

Open in new window

0
Comment
Question by:Rich Rumble
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:weellio
ID: 24232588
create a subroutine for your button..

within that sub  add something like
  If BasicCheckbox.Checked Then call <sub x>



as far as saving to an xml, you can do a simple FSO.write to a text file, just format it the way you'd like within a subroutine.
0
 
LVL 38

Author Comment

by:Rich Rumble
ID: 24233599
I've pieced this together with the M$ HTA_Help-o-Matic, I have no programming experience. I wish I could do simple things, but what you see above is all I could muster for a few day. It seems when I make sub's, only the sub I call with the button value gets run, so I think I need a for each or something to look to see if a box is checked, or I need a "case" thingy and the "if checked" and "else end if" will then work?
-rich
0
 
LVL 19

Expert Comment

by:weellio
ID: 24234544
what data do you want pulled?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Author Comment

by:Rich Rumble
ID: 24235658
For now, I'd like the OS version, and Serial # from the code above. The Serial is commented out as are the if/else statements. I think I need a "select case/else" statement in order for all the sub's to run and then the if checked /else should work? Again I'd like all options checked at first, so I should write "checked" inside the input tag. The innerhtml value I'm using above I think needs to be changed to something else, but wscript.echo's don't work in hta's, the innerhtml seems to not like the xml opening tag.
Ultimately I'm trying to convert this script:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23545465.html
to an HTA, I can so some things, so if I can get the basic's going, I should be able to piece it together, but I'm sure I'll open another question before it's done :)

-rich
0
 
LVL 19

Accepted Solution

by:
weellio earned 2000 total points
ID: 24237549
how is this?
<head>
<title>Operating System Version</title>
<HTA:APPLICATION
     APPLICATIONNAME="Inventory HTA"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
sub main
	If strUser.value <> "" And strPassword.value <> "" Then
		boolAlternate = True
		strUser = strUser.value
		strPassword = strPassword.value
		DataArea.InnerHTML = "Using alternate credentials..."
	Else
		boolAlternate = False
		DataArea.InnerHTML = "Using current credentials..."
	End If
	If strcomputers.value = "" Then
		arrComputers = Array(".")
	Else
		arrComputers = Split(strcomputers.value, ",")
	End If
	 
	results =  results & "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbcrlf
	results =  results & "<Inventory>" & vbcrlf
 
	Const WbemAuthenticationLevelPktPrivacy = 6
	On Error Resume Next
	 
	For Each strComputer In arrComputers
		If boolAlternate = True Then
			strNamespace = "root\cimv2"
			Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
			Set objWMIService = objwbemLocator.ConnectServer _
				(strComputer, strNamespace, strUser, strPassword)
			objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
		Else
			Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		End If	
		if HDD_Info.checked then
				results =  results & "<Win32_Drives>" & vbcrlf
				results =  results & "<HardDrive>" & vbcrlf
			Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where Description = 'Local Fixed Disk'")
			For Each objItem in colItems
				results =  results & "<HD_VolumeName>" & objItem.VolumeName & "</HD_VolumeName>" & vbcrlf
				results =  results & "<HD_Description>" & objItem.Description & "</HD_Description>" & vbcrlf
				results =  results & "<HD_name>" & objItem.Name & "</HD_name>" & vbcrlf
				results =  results & "<HD_DeviceID>" & objItem.DeviceID & "</HD_DeviceID>" & vbcrlf
				results =  results & "<HD_Size>" & objItem.Size & "</HD_Size>" & vbcrlf
				results =  results & "<HD_FreeSpace>" & objItem.FreeSpace & "</HD_FreeSpace>" & vbcrlf
				results =  results & "<HD_FileSystem>" & objItem.FileSystem & "</HD_FileSystem>" & vbcrlf
				results =  results & "<HD_SerialNumber>" & objItem.VolumeSerialNumber & "</HD_SerialNumber>" & vbcrlf
				results =  results & "</HardDrive>" & vbcrlf
				
				results2 =  results2 & "HD_VolumeName	:" & objItem.VolumeName & "<BR>"
				results2 =  results2 & "HD_Description	:" & objItem.Description & "<BR>"
				results2 =  results2 & "HD_name			:" & objItem.Name & "<BR>"
				results2 =  results2 & "HD_DeviceID		:" & objItem.DeviceID & "<BR>"
				results2 =  results2 & "HD_Size			:" & objItem.Size & "<BR>"
				results2 =  results2 & "HD_FreeSpace	:" & objItem.FreeSpace & "<BR>"
				results2 =  results2 & "HD_FileSystem	:" & objItem.FileSystem & "<BR>"
				results2 =  results2 & "HD_SerialNumber	:" & objItem.VolumeSerialNumber & "<BR>"
			Next
			results =  results & "</Win32_Drives>" & vbcrlf
		end if
		if OS_Info.checked then
			results =  results & "<PC_info>" & vbcrlf
			'	Get Local Login Information
			Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
			For Each objItem in colItems
				results =  results & "<Caption>" & objItem.Caption & "</Caption>" & vbcrlf
				results =  results & "<CurrentTimeZone>" & objItem.CurrentTimeZone & "</CurrentTimeZone>" & vbcrlf
				results =  results & "<Description>" & objItem.Description & "</Description>" & vbcrlf
				results =  results & "<Domain>" & objItem.Domain & "</Domain>" & vbcrlf
				results =  results & "<Manufacturer>" & objItem.Manufacturer & "</Manufacturer>" & vbcrlf
				results =  results & "<Model>" & objItem.Model & "</Model>" & vbcrlf
				results =  results & "<Machine_Name>" & objItem.Name & "</Machine_Name>" & vbcrlf
				results =  results & "<UserName>" & objItem.UserName & "</UserName>" & vbcrlf
 
				results2 =  results2 & "Caption			:" & objItem.Caption & "<BR>"
				results2 =  results2 & "CurrentTimeZone	:" & objItem.CurrentTimeZone & "<BR>"
				results2 =  results2 & "Description		:" & objItem.Description & "<BR>"
				results2 =  results2 & "Domain			:" & objItem.Domain & "<BR>"
				results2 =  results2 & "Manufacturer	:" & objItem.Manufacturer & "<BR>"
				results2 =  results2 & "Model			:" & objItem.Model & "<BR>"
				results2 =  results2 & "Machine_Name	:" & objItem.Name & "<BR>"
				results2 =  results2 & "UserName		:" & objItem.UserName & "<BR>"
			Next
			results =  results & "</PC_info>" & vbcrlf
		end if
		if BIOS_Info.checked then
			results =  results & "<BIOS_Info>" & vbcrlf
			'	Get Bios info, includng Dell Tag, Bios Revision and Manufacturer
			Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
			For Each objItem in colItems
				results =  results & "<BIOS_Version>" & objItem.BIOSVersion & "</BIOS_Version>" & vbcrlf
				results =  results & "<BIOS_Build_num>" & objItem.BuildNumber & "</BIOS_Build_num>" & vbcrlf
				results =  results & "<BIOS_Description>" & objItem.Description & "</BIOS_Description>" & vbcrlf
				results =  results & "<BIOS_Manufacturer>" & objItem.Manufacturer & "</BIOS_Manufacturer>" & vbcrlf
				results =  results & "<BIOS_Name>" & objItem.Name & "</BIOS_Name>" & vbcrlf
				results =  results & "<Dell_Tag>" & objItem.SerialNumber & "</Dell_Tag>" & vbcrlf
				results =  results & "<BIOS_Status>" & objItem.Status & "</BIOS_Status>" & vbcrlf
				results =  results & "<BIOS_Version>" & objItem.Version & "</BIOS_Version>" & vbcrlf
				
				results2 =  results2 & "BIOS_Version		:" & objItem.BIOSVersion & "<BR>"
				results2 =  results2 & "BIOS_Build_num		:" & objItem.BuildNumber & "<BR>"
				results2 =  results2 & "BIOS_Description	:" & objItem.Description & "<BR>"
				results2 =  results2 & "BIOS_Manufacturer	:" & objItem.Manufacturer & "<BR>"
				results2 =  results2 & "BIOS_Name			:" & objItem.Name & "<BR>"
				results2 =  results2 & "Dell_Tag			:" & objItem.SerialNumber & "<BR>"
				results2 =  results2 & "BIOS_Status			:" & objItem.Status & "<BR>"
				results2 =  results2 & "BIOS_Version		:" & objItem.Version & "<BR>"
			Next
			results =  results & "</BIOS_Info>" & vbcrlf
		end if
		results =  results & "</Inventory>" & vbcrlf
	Next
	DataArea.InnerHTML = results2
	if xml_Info.checked then output(results)
end sub
 
Sub Output(myxml)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.CreateTextFile("Output.xml", true)
		objFile.Write myxml
		objFile.Close
End Sub
</script>
 
<body>
Computername_:<input type="text" name="strcomputers" size="50" /><BR>
User_________:<input type="text" name="strUser" size="50" /><BR>
Password_____:<input type="text" name="strPassword" size="50" /><BR>
 
<input type="checkbox" name="OS_Info" id="OS_Info"> OS
<input type="checkbox" name="BIOS_Info" id="BIOS_Info"> BIOS
<input type="checkbox" name="HDD_Info" id="HDD_Info"> HDD
<input type="checkbox" name="xml_Info" id="xml_Info"> output to xml?
<input type="button" value="Operating System" name="run_button"  onClick="main" />
<p><span id=DataArea>Output will be saved to Output.xml</span></p>
 
</body>

Open in new window

0
 
LVL 38

Author Comment

by:Rich Rumble
ID: 24238630
Pretty good! I think I can take it from here, only error I see is it doesn't accept the user/pass.
Line: 13
Error: Object doesn't support this property or method: 'strUser'
I've made cosmetic changes so far, but I think this will work, I'll make some additions (more subs) and I think that will end this question !-)
-rich
<head>
	<title>Operating System Version</title>
	<HTA:APPLICATION
	APPLICATIONNAME="Inventory HTA"
	SCROLL="yes"
	SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
	sub main
		If strUser.value <> "" And strPassword.value <> "" Then
			boolAlternate = True
			strUser = strUser.value
			strPassword = strPassword.value
			DataArea.InnerHTML = "Using alternate credentials..."
		Else
			boolAlternate = False
			DataArea.InnerHTML = "Using current credentials..."
		End If
		If strcomputers.value = "" Then
			arrComputers = Array(".")
		Else
			arrComputers = Split(strcomputers.value, ",")
		End If
 
		results =  results & "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbcrlf
		results =  results & "<Inventory>" & vbcrlf
 
		Const WbemAuthenticationLevelPktPrivacy = 6
		On Error Resume Next
 
		For Each strComputer In arrComputers
			If boolAlternate = True Then
				strNamespace = "root\cimv2"
				Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
				Set objWMIService = objwbemLocator.ConnectServer _
				(strComputer, strNamespace, strUser, strPassword)
				objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
			Else
			Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
			End If
			If HDD_Info.checked then
				results =  results & "<Win32_Drives>" & vbcrlf
				results =  results & "<HardDrive>" & vbcrlf
				Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where Description = 'Local Fixed Disk'")
				For Each objItem in colItems
					results =  results & "<HD_VolumeName>" & objItem.VolumeName & "</HD_VolumeName>" & vbcrlf
					results =  results & "<HD_Description>" & objItem.Description & "</HD_Description>" & vbcrlf
					results =  results & "<HD_name>" & objItem.Name & "</HD_name>" & vbcrlf
					results =  results & "<HD_DeviceID>" & objItem.DeviceID & "</HD_DeviceID>" & vbcrlf
					results =  results & "<HD_Size>" & objItem.Size & "</HD_Size>" & vbcrlf
					results =  results & "<HD_FreeSpace>" & objItem.FreeSpace & "</HD_FreeSpace>" & vbcrlf
					results =  results & "<HD_FileSystem>" & objItem.FileSystem & "</HD_FileSystem>" & vbcrlf
					results =  results & "<HD_SerialNumber>" & objItem.VolumeSerialNumber & "</HD_SerialNumber>" & vbcrlf
					results =  results & "</HardDrive>" & vbcrlf
 
					results2 =  results2 & "HD_VolumeName   :" & objItem.VolumeName & "<br />"
					results2 =  results2 & "HD_Description  :" & objItem.Description & "<br />"
					results2 =  results2 & "HD_name                 :" & objItem.Name & "<br />"
					results2 =  results2 & "HD_DeviceID             :" & objItem.DeviceID & "<br />"
					results2 =  results2 & "HD_Size                 :" & objItem.Size & "<br />"
					results2 =  results2 & "HD_FreeSpace    :" & objItem.FreeSpace & "<br />"
					results2 =  results2 & "HD_FileSystem   :" & objItem.FileSystem & "<br />"
					results2 =  results2 & "HD_SerialNumber :" & objItem.VolumeSerialNumber & "<br />"
				Next
				results =  results & "</Win32_Drives>" & vbcrlf
			end if
			if OS_Info.checked then
				results =  results & "<PC_info>" & vbcrlf
				'       Get Local Login Information
				Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
				For Each objItem in colItems
					results =  results & "<Caption>" & objItem.Caption & "</Caption>" & vbcrlf
					results =  results & "<CurrentTimeZone>" & objItem.CurrentTimeZone & "</CurrentTimeZone>" & vbcrlf
					results =  results & "<Description>" & objItem.Description & "</Description>" & vbcrlf
					results =  results & "<Domain>" & objItem.Domain & "</Domain>" & vbcrlf
					results =  results & "<Manufacturer>" & objItem.Manufacturer & "</Manufacturer>" & vbcrlf
					results =  results & "<Model>" & objItem.Model & "</Model>" & vbcrlf
					results =  results & "<Machine_Name>" & objItem.Name & "</Machine_Name>" & vbcrlf
					results =  results & "<UserName>" & objItem.UserName & "</UserName>" & vbcrlf
 
					results2 =  results2 & "Caption                 :" & objItem.Caption & "<br />"
					results2 =  results2 & "CurrentTimeZone :" & objItem.CurrentTimeZone & "<br />"
					results2 =  results2 & "Description             :" & objItem.Description & "<br />"
					results2 =  results2 & "Domain                  :" & objItem.Domain & "<br />"
					results2 =  results2 & "Manufacturer    :" & objItem.Manufacturer & "<br />"
					results2 =  results2 & "Model                   :" & objItem.Model & "<br />"
					results2 =  results2 & "Machine_Name    :" & objItem.Name & "<br />"
					results2 =  results2 & "UserName                :" & objItem.UserName & "<br />"
				Next
				results =  results & "</PC_info>" & vbcrlf
				end if
				if BIOS_Info.checked then
				results =  results & "<BIOS_Info>" & vbcrlf
				'       Get Bios info, includng Dell Tag, Bios Revision and Manufacturer
				Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
				For Each objItem in colItems
					results =  results & "<BIOS_Version>" & objItem.BIOSVersion & "</BIOS_Version>" & vbcrlf
					results =  results & "<BIOS_Build_num>" & objItem.BuildNumber & "</BIOS_Build_num>" & vbcrlf
					results =  results & "<BIOS_Description>" & objItem.Description & "</BIOS_Description>" & vbcrlf
					results =  results & "<BIOS_Manufacturer>" & objItem.Manufacturer & "</BIOS_Manufacturer>" & vbcrlf
					results =  results & "<BIOS_Name>" & objItem.Name & "</BIOS_Name>" & vbcrlf
					results =  results & "<Dell_Tag>" & objItem.SerialNumber & "</Dell_Tag>" & vbcrlf
					results =  results & "<BIOS_Status>" & objItem.Status & "</BIOS_Status>" & vbcrlf
					results =  results & "<BIOS_Version>" & objItem.Version & "</BIOS_Version>" & vbcrlf
 
					results2 =  results2 & "BIOS_Version            :" & objItem.BIOSVersion & "<br />"
					results2 =  results2 & "BIOS_Build_num          :" & objItem.BuildNumber & "<br />"
					results2 =  results2 & "BIOS_Description        :" & objItem.Description & "<br />"
					results2 =  results2 & "BIOS_Manufacturer       :" & objItem.Manufacturer & "<br />"
					results2 =  results2 & "BIOS_Name                       :" & objItem.Name & "<br />"
					results2 =  results2 & "Dell_Tag                        :" & objItem.SerialNumber & "<br />"
					results2 =  results2 & "BIOS_Status                     :" & objItem.Status & "<br />"
					results2 =  results2 & "BIOS_Version            :" & objItem.Version & "<br />"
				Next
				results =  results & "</BIOS_Info>" & vbcrlf
			end if
			results =  results & "</Inventory>" & vbcrlf
		Next
		DataArea.InnerHTML = results2
		if xml_Info.checked then output(results)
		end sub
 
		Sub Output(myxml)
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Set objFile = objFSO.CreateTextFile("Output.xml", true)
			objFile.Write myxml
			objFile.Close
	End Sub
</script>
 
<body>
 
	<p style="text-align:right;">Computername: <input type="text" name="strcomputers" size="50" /><br />
		User:
		<input type="text" name="strUser" size="50" /><br />
		Password:
		<input type="password" name="strPassword" size="50" />
	</p>
 
	<input type="checkbox" name="HDD_Info" id="HDD_Info" checked="checked" /> HDD
	<input type="checkbox" name="OS_Info" id="OS_Info" checked="checked" /> OS
	<input type="checkbox" name="BIOS_Info" id="BIOS_Info" checked="checked" /> BIOS
	<input type="checkbox" name="xml_Info" id="xml_Info" checked="checked" /> Output to xml?
	<input type="button" value="Run!" name="run_button"  onClick="main" />
	<p><span id=DataArea>Output will be saved to Output.xml</span></p>
 
</body>

Open in new window

0
 
LVL 38

Author Closing Comment

by:Rich Rumble
ID: 31574289
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 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