wmlau Posted November 5, 2012 Share Posted November 5, 2012 (edited) 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> </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 SubsOption ExplicitDim strComputer, strProcessDim iRefreshRt, maxprogress, actualprogressDim text1, text2, text3, text4Dim intMinutes, intSecondsDim iTimerIDDim iTimerID1Dim iTimerID2iRefreshRt = 15000maxprogress = 500actualprogress = 0strComputer = "." strProcess = "setup.exe"text1 = "Now processing you request..."text2 = "Now remove previous version..."text3 = "Now removing and installing..."text4 = "Installation complete..."intMinutes = 1intSeconds = 01Sub 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 SubSub 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 IfEnd Sub' On Click the install buttonSub 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 IfEnd SubSub UpdateStatus Dim ProcessStat ProcessStat = ProcessStatusEnd SubFunction ProcessStatusDim 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 IFEnd FunctionFunction iTimer (TimeCheck) iTimer = 60000 * TimeCheck 'Ensure numericEnd Functionsub StartProg() iTimerID2 = setInterval("prog", 10000, "vbscript")end sub sub prog()Dim objWMIService, objFSO, objShell, colFileListdim 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 ifEnd sub</script><div id="barreprog"> <div id="indicator"> </div></div></head><div id="Progress"> </div></body></html> Edited November 6, 2012 by Tripredacus Link to comment Share on other sites More sharing options...
Tripredacus Posted November 6, 2012 Share Posted November 6, 2012 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. Link to comment Share on other sites More sharing options...
wmlau Posted November 6, 2012 Author Share Posted November 6, 2012 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. Link to comment Share on other sites More sharing options...
Tripredacus Posted November 6, 2012 Share Posted November 6, 2012 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 NextobjShell.Popup Percent, 1, "Title", -1If Percent = 100 Thenprogress.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 SubElseCall ProgressHelper(Percent,TimeRemaining)End IfSee that Exit Sub part in there. Link to comment Share on other sites More sharing options...
wmlau Posted November 6, 2012 Author Share Posted November 6, 2012 Thanks Tripredacus. I'll give that shot. Link to comment Share on other sites More sharing options...
wmlau Posted November 6, 2012 Author Share Posted November 6, 2012 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 Link to comment Share on other sites More sharing options...
wmlau Posted November 7, 2012 Author Share Posted November 7, 2012 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 Link to comment Share on other sites More sharing options...
vtlepshev Posted July 31, 2013 Share Posted July 31, 2013 Hey wmlau,I was looking for an application like yours for a quite some time. this is a very helpful and usefull application.One thing I cannot understand, what in the script I need change to let the script know that I am installing oovoo, basically, how the script knows about ooVooSetup.msi?Thanks, Link to comment Share on other sites More sharing options...
Tripredacus Posted August 1, 2013 Share Posted August 1, 2013 That's a totally different thing than tracking Imagex. For installing an MSI file you need to look at msiexec.exe but you'll notice that process stays active for up to 10 minutes after completing the installation of the MSI file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now