Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Hta code with dropdown menu's for software installation.

Hi,

Hta code with dropdown menu's for software installation.
The below code is from Rob.
It works perfect. But for a specific senario i dont want the "Offices" drop down.
and
When a software is selected i want a small description given to the right of the in some free space describing of the application and if its a silent installor not.

Regards
Sharath

'=============
<head>
<title>Choose Software To Install</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Choose Software To Install"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>
 
<script language="VBScript">
 
Dim arrSoftware
 
Sub Window_onLoad
      intWidth = 800
      intHeight = 600
      Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
      arrSoftware = Array(_
           "Chennai;Office Products;Office 2003;\\in\FS\Office_Products\Office_2003\SETUP.EXE", _
           "Chennai;Office Products;Office Xp;\\dev\Office XP\SETUPPRO.EXE", _
            "Chennai;Utilities;WinZip;\\dev\WinZip\SETUP.EXE", _
            "Chennai;Utilities;Adobe Reader 7;\\ntfp\software\Adobe Reader\AdobeRdr709_Extracted\Adobe Reader 7.0.9.msi", _
            "Chennai;Utilities;Windows Installer 3;\\ntfp\software\Windows Installer 3.1\WindowsInstaller-KB893803-v2-x86.exe", _
            "Hyderabad;Messengers;Windows Messenger;\\server\share\WinMessenger\setup.exe", _
            "Hyderabad;Utilities;Security Test;\\server\share\temp\PS4LICENSE\setup.exe", _
            "Hyderabad;Databases;SQL Server Tools;\\server\share\SQL Server\Tools\setup.exe")
    Populate_Office
End Sub
 
Sub Populate_Office
 
      strHTML = "<select size='1' name='cbo_office' onchange='vbs:Populate_SoftwareType'>" & VbCrLf
      strHTML = strHTML & "<option selected value='cbo_office'> --- Select Office --- </option>" & vbCrLf
      
      strOffices = ";"
      For Each strProduct In arrSoftware
            strOffice = Split(strProduct, ";")(0)
            If InStr(LCase(strOffices), LCase(";" & strOffice & ";")) = 0 Then
                  strOffices = strOffices & strOffice & ";"
                  strHTML = strHTML & "<option value='" & strOffice & "'>" & strOffice & "</option>" & VbCrLf
            End If
      Next
      
      strHTML = strHTML & "</select>"
 
      span_office.InnerHTML = strHTML
 
End Sub
 
Sub Populate_SoftwareType
 
      strHTML = "<select size='1' name='cbo_softwaretype' onchange='vbs:Populate_Application'>" & VbCrLf
      strHTML = strHTML & "<option selected value='cbo_softwaretype'> --- Select Software Type --- </option>" & VbCrLf
      
      strTypes = ";"
      For Each strProduct In arrSoftware
            If LCase(Split(strProduct, ";")(0)) = LCase(cbo_office.Value) Then
                  strType = Split(strProduct, ";")(1)
                  If InStr(LCase(strTypes), LCase(";" & strType & ";")) = 0 Then
                        strTypes = strTypes & strType & ";"
                        strHTML = strHTML & "<option value='" & strType & "'>" & strType & "</option>" & VbCrLf
                  End If
            End If
      Next
      
      strHTML = strHTML & "</select>"
 
      span_softwaretype.InnerHTML = strHTML
 
End Sub
 
Sub Populate_Application
 
      strHTML = "<select size='1' name='cbo_application'>" & VbCrLf
      strHTML = strHTML & "<option selected value='cbo_application'> --- Select Application --- </option>" & VbCrLf
      
      For Each strProduct In arrSoftware
            If LCase(Split(strProduct, ";")(0)) = LCase(cbo_office.Value) And LCase(Split(strProduct, ";")(1)) = LCase(cbo_softwaretype.Value) Then
                  strApplication = Split(strProduct, ";")(2)
                  strFilePath = Split(strProduct, ";")(3)
                  strHTML = strHTML & "<option value='" & strApplication & ";" & strFilePath & "'>" & strApplication & "</option>" & VbCrLf
            End If
      Next
      
      strHTML = strHTML & "</select>"
 
      span_application.InnerHTML = strHTML
 
End Sub
 
Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_install.Click
      End If
End Sub
 
Sub Install_Software
      strLogFile = "\\indiasophos\Ps\HTA_Install_Log.csv"
      Const intForAppending = 8
      If cbo_office.Value = "cbo_office" Then
            MsgBox "Please select an office."
            cbo_office.Focus
      ElseIf cbo_softwaretype.Value = "cbo_softwaretype" Then
            MsgBox "Please select a software type."
            cbo_softwaretype.Focus
      ElseIf cbo_application.Value = "cbo_application" Then
            MsgBox "Please select an application."
            cbo_application.Focus
      Else
            strProduct = Split(cbo_application.Value, ";")(0)
            strExecutable = Split(cbo_application.Value, ";")(1)
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objShell = CreateObject("WScript.Shell")
            Set objNetwork = CreateObject("WScript.Network")
            'Software file,Machinename,Username,Date and time
            strDetails = strExecutable & "," & objNetwork.ComputerName & "," & objNetwork.UserName & "," & Now
            If objFSO.FileExists(strExecutable) = True Then
                  'objShell.Run strExecutable
                  If LCase(Right(strExecutable, 4)) = LCase(".msi") Then
                        strCommand = "msiexec /i " & objFSO.GetFile(strExecutable).ShortPath & " /qf /norestart"
                  Else
                        strCommand = "cmd /c """ & objFSO.GetFile(strExecutable).ShortPath & """"
                  End If
                  'MsgBox "Installing: " & strProduct & VbCrLf & "From:" & VbCrLf & strExecutable & VbCrLf & "With: " & strCommand
 
                  strExitCode = objShell.Run(strCommand, 1, True)
 
 
                
                  If Left(strCommand, 7) = "msiexec" And strExitCode = 1619 Then
                        MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
                  ElseIf Left(strCommand, 6) = "cmd /c" And strExitCode = 1 Then
                        MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
                  End If
                  Set objOutputFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
                  objOutputFile.WriteLine strDetails
                  objOutputFile.Close
                  Set objOutputFile = Nothing
            Else
                  MsgBox "The file does not exist, or you do not have permission to access it." & VbCrLf & "Please contact the Help Desk."
            End If
            Set objShell = Nothing
            Set objFSO = Nothing
            Set objNetwork = Nothing
      End If
End Sub
 
</script>
 
<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
      <table width='90%' height = '100%' align='center' border='0'>
            <tr>
                  <td align="center" colspan="2">
                        <h2>Choose Software To Install</h2>
                  </td>
            </tr>
            <tr>
                  <td align='center'>
                        Choose from the options in each list:
                  </td>
            </tr>
            <tr>
                  <td>
                        Office:
                        <span id="span_office">
                              <select size="1" name="cbo_office">
                                    <option selected value="cbo_office"> --- Select Office --- </option> 
                              </select>
                        </span>
                  </td>
            </tr
            <tr>
                  <td>
                        Software Type:
                        <span id="span_softwaretype">
                              <select size="1" name="cbo_softwaretype">
                                    <option selected value="cbo_softwaretype"> --- Select Software Type --- </option> 
                              </select>
                        </span>
                  </td>
            </tr
            <tr>
                  <td>
                        Application:
                        <span id="span_application">
                              <select size="1" name="cbo_application">
                                    <option selected value="cbo_application"> --- Select Application --- </option> 
                              </select>
                        </span>
                  </td>
            </tr
            <tr>
                  <td align='center' colspan="2">
                        <input type="button" value="Install" name="btn_install"  onClick="vbs:Install_Software"><br><br>
                  </td>
            </tr>
            <tr height='20%'>
                  <td>
                  </td>
            </tr>
      </table>
 
</body>
'=============

Open in new window

Avatar of jostrander
jostrander
Flag of United States of America image

See if this works for you:
<head>
<title>Choose Software To Install</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Choose Software To Install"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
     CONTEXTMENU="NO"
     MINIMIZEBUTTON="NO"
     MAXIMIZEBUTTON="NO"
>
</head>
 
<script language="VBScript">

intWidth = 800
intHeight = 600
Me.ResizeTo intWidth, intHeight
Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2)) 

Dim arrSoftware
 
Sub Window_onLoad

      arrSoftware = Array(_
           "Office Products;Office 2003;\\in\FS\Office_Products\Office_2003\SETUP.EXE;Add a description for Office 2003", _
           "Office Products;Office Xp;\\dev\Office XP\SETUPPRO.EXE;Add a description for Office XP", _
            "Utilities;WinZip;\\dev\WinZip\SETUP.EXE;Add a description for WinZip", _
            "Utilities;Adobe Reader 7;\\ntfp\software\Adobe Reader\AdobeRdr709_Extracted\Adobe Reader 7.0.9.msi;Add a description for Adobe Reader", _
            "Utilities;Windows Installer 3;\\ntfp\software\Windows Installer 3.1\WindowsInstaller-KB893803-v2-x86.exe;Add a description for Windows Installer 3.1", _
            "Messengers;Windows Messenger;\\server\share\WinMessenger\setup.exe;Add a description for Windows Messenger", _
            "Utilities;Security Test;\\server\share\temp\PS4LICENSE\setup.exe;Add a description for Security Test", _
            "Databases;SQL Server Tools;\\server\share\SQL Server\Tools\setup.exe;Add a description for SQL Server Tools.  Here is a sample description that is very long.  It is for example only to show what it will look like... blah blah blah...")
            
	Populate_SoftwareType
    
End Sub
 

 
Sub Populate_SoftwareType
	span_desc.innerText=""
      strTypes = ";"
      For Each strProduct In arrSoftware
		  strType = Split(strProduct, ";")(0)
		  If InStr(LCase(strTypes), LCase(";" & strType & ";")) = 0 Then
				strTypes = strTypes & strType & ";"
				AddOption "select_type",strType,strType
		  End If
      Next
      
End Sub
 
Sub Populate_Application
	span_desc.innerText=""
	ClearOptions "select_application"
 
      For Each strProduct In arrSoftware
            If LCase(Split(strProduct, ";")(0)) = LCase(cbo_softwaretype.Value) Then
                  strApplication = Split(strProduct, ";")(1)
                  strFilePath = Split(strProduct, ";")(2)
                  strDescription = Split(strProduct, ";")(3)
				strText = strApplication
				strValue = strApplication & ";" & strFilePath & ";" & strDescription
				AddOption "select_application",strText,strValue
            End If
      Next
      
 
End Sub

Sub AddOption(elem_id,myText,myValue)
	Set elem=document.getElementById(elem_id)
	Set objNewOption = document.createElement("OPTION")
	objNewOption.Text = myText
	objNewOption.value = myValue
	elem.options.Add(objNewOption)
End Sub

Sub ClearOptions(elem_id)
	Set elem=document.getElementById(elem_id)
	elem.options.length=1

End Sub
 
Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_install.Click
      End If
End Sub
 
Sub Install_Software
      ON ERROR RESUME NEXT
      
      strLogFile = "\\indiasophos\Ps\HTA_Install_Log.csv"
      Const intForAppending = 8
      If cbo_softwaretype.Value = "cbo_softwaretype" Then
            MsgBox "Please select a software type."
            cbo_softwaretype.Focus
      ElseIf cbo_application.Value = "cbo_application" Then
            MsgBox "Please select an application."
            cbo_application.Focus
      Else
            strProduct = Split(cbo_application.Value, ";")(0)
            strExecutable = Split(cbo_application.Value, ";")(1)

            Set objFSO = CreateObject("Scripting.FileSystemObject")
            Set objShell = CreateObject("WScript.Shell")
            Set objNetwork = CreateObject("WScript.Network")
            'Software file,Machinename,Username,Date and time
            strDetails = strExecutable & "," & objNetwork.ComputerName & "," & objNetwork.UserName & "," & Now
            If objFSO.FileExists(strExecutable) = True Then
                  'objShell.Run strExecutable
                  If LCase(Right(strExecutable, 4)) = LCase(".msi") Then
                        strCommand = "msiexec /i " & objFSO.GetFile(strExecutable).ShortPath & " /qf /norestart"
                  Else
                        strCommand = "cmd /c """ & objFSO.GetFile(strExecutable).ShortPath & """"
                  End If
                  'MsgBox "Installing: " & strProduct & VbCrLf & "From:" & VbCrLf & strExecutable & VbCrLf & "With: " & strCommand
 
                  strExitCode = objShell.Run(strCommand, 1, True)
				If strExitCode="" then Exit Sub
                
                  If Left(strCommand, 7) = "msiexec" And strExitCode = 1619 Then
                        MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
                  ElseIf Left(strCommand, 6) = "cmd /c" And strExitCode = 1 Then
                        MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
                  End If
                  Set objOutputFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
                  objOutputFile.WriteLine strDetails
                  objOutputFile.Close
                  Set objOutputFile = Nothing
            Else
                  MsgBox "The file does not exist, or you do not have permission to access it." & VbCrLf & "Please contact the Help Desk."
            End If
            Set objShell = Nothing
            Set objFSO = Nothing
            Set objNetwork = Nothing
      End If
End Sub

Sub Set_Description
	strSelectValue=select_application.value
	span_desc.innerText=split(strSelectValue,";")(2)
End Sub

Sub HighLight
	If btn_install.className="on" then
		btn_install.className="off"
	Else
		btn_install.className="on"
	End If
End Sub 
</script>

<STYLE>
body {
	font:12 pt arial;
	color:white;
	filter:progid:DXImageTransform.Microsoft.Gradient
		(GradientType=1, StartColorStr='black', EndColorStr='gray');
}


td {
	vertical-align: top;
	font: 10pt arial;
}

.td_lbl {
	width: 100px;
}

#td_desc {
	width: 60%;
	background: gray;
	color: black;
	border: 2px solid gray;
	height: 200px;
}

.on {
	border: 2px solid white;
	color: white;
	background-color: black;
}

.off {
	border: 2px solid gray;
	color: black;
	background-color: buttonface;
}

select {
	width: 190px;
	color: white;
	background-color: black;
	
}
</STYLE>
 
<body onkeypress='Default_Buttons'>
<h2>Choose Software To Install</h2>
<br>
Choose from the options in each list:<br><br>
<table>
	<tr>
		<td>
			<table>
			<tr>
				<td class="td_lbl">Software Type:</td>
				<td>
					<span id="span_softwaretype">
						<select size="1" name="cbo_softwaretype" id="select_type" onchange="Populate_Application" >
							<option selected value="cbo_softwaretype"> --- Select Software Type --- </option> 
						</select>
					</span>
				</td>
			</tr>
			<tr>	
				<td class="td_lbl">Application:</td>
				<td>
					<span id="span_application">
						<select size="1" name="cbo_application" id="select_application" onchange="Set_Description">
							<option selected value="cbo_application" > --- Select Application --- </option> 
						</select>
					</span>
				</td>
			</tr>
			<tr>
				<td><br><button id="btn_install" class="off" onClick="Install_Software" onmouseover="HighLight" onmouseout="HighLight">Install</button></td>
				<td></td>
			</tr>	
			</table>
		</td>
		<td id="td_desc"><span id="span_desc"></span></td>
	</tr>
</table>


 
</body>

Open in new window

Avatar of bsharath

ASKER

Thanks Joe
All fine
 I guess an additional option not to right click on the Hta
Can You please set the log to capture the Open time of Hta Installed application,Machine name,username and close time of Hta
so instead of this:
zzzz.exe,Computer123,User123,<app install start time>
yyyy.exe,Computer123,User123,<app install start time>

you want this?
<hta open time>,Computer123,User123,<hta close time>

OR this?

zzzz.exe,Computer123,User123,<app install start time>
yyyy.exe,Computer123,User123,<app install start time>
<hta open time>,Computer123,User123,<hta close time>
I want this
zzzz.exe,Computer123,User123,<app install start time>,Hta close time,Date,timeofinstallation

ASKER CERTIFIED SOLUTION
Avatar of jostrander
jostrander
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
What if you open it in notepad?
Got it time works fine.
can you give me the exact change i need to do from the other post into this
It's already done ;)
Thanks a lot Joe.
have postes a related Q please have a look...
https://www.experts-exchange.com/questions/26244944/HTA-script-need-help-with-an-addition.html