Adding dynamic content to an HTA

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
monicafanton
Posts: 7
Last visit: Thu Feb 01, 2024 5:46 am

Adding dynamic content to an HTA

Post by monicafanton »

I am trying to add dynamic content to an HTA, but I'm stuck on how to select a checkbox (dynamically added), click a button, and then perform an action based on whether the checkbox is checked.

Any help would be much appreciated.

Thanks...

The relevant portion of the script is here:

Sub Window_OnLoad
'Prompt the user for the search string strQuery = InputBox("What is the search string?")
' Get the domain name Set objRoot = GetObject("LDAP://rootDSE") strDomain = "LDAP://" & objRoot.Get("defaultNamingContext") ' Create recordset for computer names Set objList = CreateObject("ADOR.RecordSet") Set objList = CreateObject("ADOR.Recordset") objList.Fields.Append "ServerName", adVarChar, MaxCharacters objList.Open ' Create the connection Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" ' Query the directory Set objCommand.ActiveConnection = objConnection objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=computer)" & _ "(Name=*" & strQuery & "*));Name;subtree" ' Set up command properties objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False ' Put computer names into the list Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst 'Create the list While Not objRecordSet.EOF objList.AddNew objList("ServerName") = objRecordset.Fields("Name") objRecordSet.MoveNext Wend 'Alphabetize the list objList.Sort = "ServerName" 'Start at the beginning of the list objList.MoveFirst 'Go through the list and display each server name with a checkbox Do Until objList.EOF strComputer = objList.Fields.Item("ServerName") strHTML = ServerList.InnerHTML strHTML = strHTML & "<table><tr><td> </td><td>" & _ "<input type=""checkbox"" name=" & _ strComputer & ">" & strComputer & "</td></tr>" objList.MoveNext ServerList.InnerHTML = strHTML Loop End Sub

Sub RunScript If strComputer.Checked Then MsgBox ("The checkbox has been checked.") Else MsgBox("The checkbox has not been checked.") End IfEnd Sub

<body>
<BR><table width="100%"><tr><td><b>Server List:</b><td><input id=runbutton class="button" type="button" value="Run Script" name="run_button" onClick="RunScript"></td><td><input id=runbutton class="button" type="button" value="Cancel" name="run_button" onClick="Quit"></td></tr><tr><td>To remove servers from the list, select the checkbox next to the server name.<br></td></tr><td>
</td></td></tr></table> <span id="ServerList"></span>
</body>
User avatar
monicafanton
Posts: 7
Last visit: Thu Feb 01, 2024 5:46 am

Adding dynamic content to an HTA

Post by monicafanton »

I've made some progress, but I'm having a bit of trouble again. I want the user to be able to select a servername and have a script run on each server chosen. I've gotten this to work except for the fact that the script will run only on the first server selected (not all of them). Can someone please help?

Thanks,
Monica

<html><!--*******************************************************************'* Intel EDW Engineering'**********************************************************************'* Title: Local Administrator Password Change'* Author: Monica J. Fanton'* E-mail: mjfantox@intel.com'**********************************************************************'* Description: '*'* This application will query Active Directory for a list of server'* name(s), then display the server name(s) for confirmation. Once'* confirmed, the application will prompt the user for the new'* password and change the local administrator password on each server'* listed.'**********************************************************************'* Version History:'* '* 1.0 Released for test May 22, 2007'* '**********************************************************************'* Dependencies:'* '* 1. The system(s) where this application is run must be a member of'* the same domain as the target system(s).'* 2. The target system(s) must be accessible on the network.'* 3. The individual using this application must have sufficient'* permissions on the target system(s) to perform the operations'* in this application.'* '**********************************************************************'* HTML Application Begins'*******************************************************************-->
<head><title>Password Change Tool</title><HTA:APPLICATION APPLICATIONNAME="Password Change Tool" SCROLL="yes" SINGLEINSTANCE="yes" WINDOWSTATE="normal"></head>
<!--*******************************************************************'* HTML Style Tags'*******************************************************************-->
<style>body{ background-color: buttonface; font-family: arial; font-size: 8pt;}.button{ font-family: arial; font-size: 8pt; width: 100px;}.buttonLong{ font-family: arial; font-size: 10pt; border-style:none; text-align: left; color:#483D8B; text-decoration:underline;}textarea{ font-family:monospace; font-size: 10pt; margin-left: 0px; padding: 0px;}span{ font-family: arial; font-size: 8pt; margin-left: -3px;}select{ font-family: arial; font-size: 10pt; margin-left: 0px;}input{ font-family: arial; font-size: 8pt; margin-left: 0px;}div.code{ font-family: arial; font-size:12pt; margin-left: 2px; position:absolute; color:#483D8B; left:10px; top:77px;}div.attention{ font-family: arial; font-size: 10pt; margin-left: 0px; color: red; font-style: bold; position:absolute; left:230px; top:40px; width:280px;}div.notes{ font-family: arial; font-size: 10pt; margin-left: 0px; color: black; position:absolute; top:95px;}</style>
<!--*******************************************************************'* HTML Application VBScript'*******************************************************************-->
<script language="VBScript">
'**********************************************************************'* HTML Application VBScript Variable Declarations'**********************************************************************
Option Explicit
Dim strQuery, strDomain, strComputer, strHTMLDim strScript, strServerName, strPasswordDim objRoot, objList, objConnection, objCommand, objRecordSetDim objServerList, objPassword, objWMIService, objAccount, objUserDim colAccounts
'**********************************************************************'* HTML Application VBScript Static Variable Assignments'**********************************************************************
Const ADS_SCOPE_SUBTREE = 2Const adVarChar = 200Const MaxCharacters = 255Const DISABLE_NETBIOS = 2
'**********************************************************************'* HTML Application VBScript Subs and Functions'**********************************************************************
On Error Resume Next
Sub Window_OnLoad()
'Prompt the user for the search string strQuery = InputBox("What is the search string?")
If strQuery = "" Then Window.close() Else ' Get the domain name Set objRoot = GetObject("LDAP://rootDSE") strDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
' Create recordset for computer names Set objList = CreateObject("ADOR.RecordSet")
Set objList = CreateObject("ADOR.Recordset") objList.Fields.Append "ServerName", adVarChar, MaxCharacters objList.Open
' Create the connection Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider"
' Query the directory Set objCommand.ActiveConnection = objConnection objCommand.CommandText = "<" & strDomain & ">;(&(objectCategory=computer)" & _ "(Name=*" & strQuery & "*));Name;subtree"
' Set up command properties objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False
' Put computer names into the list Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
'Create the list While Not objRecordSet.EOF objList.AddNew objList("ServerName") = objRecordset.Fields("Name") objRecordSet.MoveNext Wend
'Alphabetize the list objList.Sort = "ServerName"
'Start at the beginning of the list objList.MoveFirst
'Go through the list and display each server name with a checkbox Do Until objList.EOF strComputer = objList.Fields.Item("ServerName") strHTML = ServerList.InnerHTML strHTML = strHTML & "<table><tr><td> </td><td>" & _ "<input type='checkbox' name=" & strComputer & _ " onclick='Selected(""" & strComputer & """)'>" & _ strComputer & "</td></tr>" objList.MoveNext ServerList.InnerHTML = strHTML Loop End IfEnd Sub
Sub Selected(strServerSelected) Dim objServerExists
objServerExists = False
Set objServerList = CreateObject("ADOR.Recordset") objServerList.Fields.Append "ServerName", adVarChar, MaxCharacters objServerList.Open
if (objServerList.RecordCount > 0) Then objServerList.MoveFirst
Do Until objServerList.EOF If objServerList.Fields.Item("ServerName") = strServerSelected Then objServerList.Delete objServerExists = True end If
objServerList.MoveNext Loop end If
if objServerExists = False then objServerList.AddNew objServerList("ServerName") = strServerSelected Else
end IfEnd Sub
Sub RunScript() If (objServerList.RecordCount > 0) Then objServerList.MoveFirst
Do Until objServerList.EOF strServerName = objServerList.Fields.Item("ServerName") strPassword = InputBox("Please enter the new password:")
If strPassword = "" Then Window.close() End If
'Get the local administrator user name Set objWMIService = GetObject("winmgmts:" & strServerName & "rootcimv2")
Set colAccounts = objWMIService.ExecQuery _ ("Select * From Win32_UserAccount Where LocalAccount = TRUE")
For Each objAccount in colAccounts If Left (objAccount.SID, 6) = "S-1-5-" and Right(objAccount.SID, 4) = "-500" Then Set objUser = GetObject("WinNT://" & strServerName & "/" & objAccount.Name)
' Set the password objUser.SetPassword(strPassword) End If strHTML = "The local administrator password " & _ "has been successfully changed on " & strServerName & "." Next objServerList.MoveNext Logging.InnerHTML = strHTML Loop end If
End Sub
Sub Quit Window.close()End Sub
</script>
<body>
<BR><table width="100%"><tr><td><b>Server List:</b><td align="right"><input id=runbutton class="button" type="button" value="Run Script" name="run_button" onClick="RunScript"><input id=runbutton class="button" type="button" value="Cancel" name="run_button" onClick="Quit"></td></tr></table><table><tr><td width = "10%" valign="top"><span id="ServerList"></span></td><td></td><td width = "67%" valign="top"> <span id="Logging"></span></td></tr></table> </body></html>
This topic is 16 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked