MSFN Forum: progress bar for application install - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

progress bar for application install Rate Topic: -----

#1 User is offline   wmlau 

  • Group: Members
  • Posts: 5
  • Joined: 05-November 12
  • OS:none specified
  • Country: Country Flag

Posted 05 November 2012 - 05:24 PM

hi,
I am new at scripting in HTA. I've created this hta to give user an interface and show the progress of an application during its installation from start to finish. We typically deploy application silently, lately our management wants to show the installation in a single interface. My script is to deploy the applicaion with this hta front end to display the progress while monitor a specified process is running "setup.exe" and show each step of the way.
The progress bar is working, however, it does not know when to stop. I tried both clearinterval and cleartimeout window.clearInterval(iTimerID2) window.clearTimeout(iTimerID2)
It is not working. Any help or suggestion is appreciated.
What I would like the script to do is to stop the progress bar when the maxprogress is reach or when the setup.exe is finished.
here is the code:
<html>
	<head> 
	<HTA:APPLICATION ID="porgbar"
	APPLICATIONNAME="MyApp Installation"
	BORDER="thin"
	BORDERSTYLE="normal"
	CAPTION="yes"
	MAXIMIZEBUTTON="no"
	MINIMIZEBUTTON="no"
	SHOWINTASKBAR="yes"
	SINGLEINSTANCE="yes"
	SYSMENU="yes"
	VERSION="1.0"
	/>
	<style type="text/css">
<!--
#barreprog {
	position:absolute;
	left: 50%;
	right: 25%;
	width:700px;
	margin-left: -350px;
	height: 1em;
	bottom: 15%;
	padding:2px;
	background-color:white;
	border:1px solid black;
	}
#indicator{
	width:0px;
	height: 1em;
	background-color:C06A45;
	}
//-->
<title>MyApp Installation</title>
	BODY {font-family: Trebuchet MS, Helvetica, Arial; font-size: 14pt; color: black }
</style>
</head>
	<body>
	<h2 style="text-align:center;">MyApp installation process has started</h2> 
	<hr style="width:75%; color: navy;"/>
	<DIV ALIGN=CENTER>

	<p><font size="5">Please save your work and close all applications before clicking <b>“Install Now.”</b></font></p>

	<p><font size="5"><i>This process should take approximately 40 minutes to complete. Please do not attempt to launch any applications during this time.</i></font></p>
	</DIV>

	<div id="DynamicText" style="text-align: center; color:red; font-weight: bold; font-size:25px">
	<p>&nbsp;</p>
	</div>

	<div id="InstallButton" style="visibility: hidden;">
	<p style="text-align: center;"><input type="button" id="InstallNow" value="Install Now"></p>
	</div>

<script language="VBScript">
' Count Down Code
' Declare global variable outside of the Subs
Option Explicit
Dim strComputer, strProcess
Dim iRefreshRt, maxprogress, actualprogress
Dim text1, text2, text3, text4
Dim intMinutes, intSeconds
Dim iTimerID
Dim iTimerID1
Dim iTimerID2
iRefreshRt = 15000
maxprogress = 500
actualprogress = 0
strComputer = "." 
strProcess = "setup.exe"
text1 = "Now processing you request..."
text2 = "Now remove previous version..."
text3 = "Now removing and installing..."
text4 = "Installation complete..."
intMinutes = 1
intSeconds = 01

Sub Window_onLoad
	window.ResizeTo 900, 450
	window.MoveTo ((Screen.Width / 2) - (900 / 2)),((Screen.Height / 2) - (450 / 2))
	' Set the minutes and seconds
	iTimerID1 = window.setInterval("Countdown", 1000, "VBScript")
	DynamicText.innerHTML = intMinutes & "min:" & Right("00" & intSeconds, 2) & "s"
	InstallButton.Style.Visibility = "visible"
	document.body.bgColor="E9F1EA"
End Sub

Sub Countdown
	DynamicText.innerHTML = intMinutes & "min:" & Right("00" & intSeconds, 2) & "s"
		If intSeconds = 0 Then
			' Install auotmatically after time expires
			If intMinutes = 0 Then
				InstallNow.Click
			Else
				intMinutes = intMinutes - 1
				intSeconds = 59
				DynamicText.innerHTML = intMinutes & "min:" & Right("00" & intSeconds, 2) & "s"
			End If
		Else
			intSeconds = intSeconds - 1
			DynamicText.innerHTML = intMinutes & "min:" & Right("00" & intSeconds, 2) & "s"
		End If

End Sub

' On Click the install button
Sub InstallNow_onClick()
	dim oShell, objFSo
	set oShell = CreateObject("WScript.Shell")
		oShell.RegWrite "HKCU\Software\MyApp\Time", "now" , "REG_SZ"
		oShell.RegWrite "HKCU\Software\MyApp\Date", cstr(date) , "REG_SZ" 
	Set oShell = nothing
	set objFSo = CreateObject("Scripting.FileSystemObject")
		If objFSo.fileExists("C:\MsgFlag.txt") then
			objFSo.DeleteFile("C:\MsgFlag.txt")
		End If
	Set objFSo = nothing
	If InstallNow.Value = "Install Now" Then
		Window.clearTimeout(iTimerID1)
		InstallNow.disabled = True
		Document.getElementById("DynamicText").innerHTML = text1
		' DynamicText.innerHTML = "Now processing you request..."
		InstallNow.Value = "In Progress"
		Call ProcessStatus
		iTimerID = window.setInterval("UpdateStatus", iRefreshRt) 'Set timer ONCE
		document.body.bgColor="C9DECB"
	End If
End Sub

Sub UpdateStatus
	Dim ProcessStat
		ProcessStat = ProcessStatus
End Sub

Function ProcessStatus
Dim objWMIService, colProcesses, objProcess, objProgram
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colProcesses = objWMIService.ExecQuery _
	("Select * from Win32_Process Where Name = '" & strProcess & "'")
	If colProcesses.Count > 0 Then
		ProcessStatus = "Running"
		document.body.bgColor="B4D1B6"
		Do Until colProcesses.Count = 0
		' MsgBox strProcess & " is running."
		Document.getElementById("DynamicText").innerHTML = text3
		' DynamicText.innerHTML = "Now removing and installing..."
		Call StartProg
		Exit Do
		Loop
	Else
		window.clearInterval(iTimerID2)
		InstallNow.Value = "In Progress"
		document.body.bgColor="C9DECB"
		' Document.getElementById("DynamicText").innerHTML = text4
	End IF
End Function

Function iTimer (TimeCheck)
	iTimer = 60000 * TimeCheck 'Ensure numeric
End Function

sub StartProg()
	iTimerID2 = setInterval("prog", 10000, "vbscript")
end sub 

sub prog()
Dim objWMIService, objFSO, objShell, colFileList
dim indic
	Set indic = document.getElementById("indicator")
		actualprogress = actualprogress + 1     
		indic.style.width = actualprogress
	if actualprogress > maxprogress then
		window.clearInterval(iTimerID2)
		Document.getElementById("DynamicText").innerHTML = text4
		document.body.bgColor="6CA870"
	End if
End sub

</script>
<div id="barreprog">
	<div id="indicator"> </div>
</div>
</head>
<div id="Progress"> </div>
</body>
</html>

This post has been edited by Tripredacus: 06 November 2012 - 09:23 AM



#2 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,723
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 05 November 2012 - 06:55 PM

With my deployment app, I simply show an HTA during the install process to alert users that the installer is running. That way you don't have to worry about calculating times, etc. Also you need to watch out for installers that spawn msiexec.exe, since that can stay open in the background for 10 minutes.

#3 User is offline   wmlau 

  • Group: Members
  • Posts: 5
  • Joined: 05-November 12
  • OS:none specified
  • Country: Country Flag

Posted 05 November 2012 - 09:29 PM

Thank you for the quick reply. We do have something in that nature, however, they want something with a button to click on and inform every step of the way and also a count down clock to give them time to save any works before we force close the dependence applications in a single GUI. I can't think of any better than HTA, this will have message, button, progress bar and using the innerHTML to show the steps take place.

#4 User is offline   Tripredacus 

  • K-Mart-ian Legend
  • Group: Super Moderator
  • Posts: 8,723
  • Joined: 28-April 06
  • OS:Server 2012
  • Country: Country Flag

Posted 06 November 2012 - 09:38 AM

I am looking at my HTA (see signature) which does not have a working progress bar... BUT it does go away after its work is done. I'm no master of VBScript, but I notice a difference between it and yours. Your progress routine doesn't have any exit command. For example:

Sub objWIM_Progress(Percent,TimeRemaining)
On Error Resume Next
objShell.Popup Percent, 1, "Title", -1
If Percent = 100 Then
progress.innerHTML = "<table border='0'><tr><td>Percents completed: </td><td>100 % </tr><tr><td>Time remaining: </td><td>0 min 0 sec</td></tr></table>"
Exit Sub
Else
Call ProgressHelper(Percent,TimeRemaining)
End If


See that Exit Sub part in there. :unsure:

#5 User is offline   wmlau 

  • Group: Members
  • Posts: 5
  • Joined: 05-November 12
  • OS:none specified
  • Country: Country Flag

Posted 06 November 2012 - 12:24 PM

Thanks Tripredacus.

I'll give that shot.

#6 User is offline   wmlau 

  • Group: Members
  • Posts: 5
  • Joined: 05-November 12
  • OS:none specified
  • Country: Country Flag

Posted 06 November 2012 - 03:32 PM

I've tried with the Exit Sub. That don't work. Also tried with a sub funtion to stop the timer. All with the same result, the progress bar would not stop at the end of timer or at max count.
sub StopTimer
window.clearInterval(iTimerID2)
end sub

#7 User is offline   wmlau 

  • Group: Members
  • Posts: 5
  • Joined: 05-November 12
  • OS:none specified
  • Country: Country Flag

Posted 07 November 2012 - 08:52 AM

Thanks Tripredacus. I got it working now, just switch the order of progrress.

sub prog()
Dim objWMIService, objFSO, objShell, colFileList
dim indic
Set indic = document.getElementById("indicator")
if actualprogress > maxprogress then
window.clearInterval(iTimerID2)
exit sub
else
actualprogress = actualprogress + 1
indic.style.width = actualprogress
Document.getElementById("DynamicText").innerHTML = text4
document.body.bgColor="6CA870"
End if
End sub

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy