dcistech Posted May 22, 2012 Posted May 22, 2012 First off: I'm a bit of a novice. I know enough to make sense of most simple written code (most of the time), but I'm not all that experienced. So, this issue is likely very silly, but I've searched for a solution for a few hours now and can't find one.Anyway, I'm working on modifying an HTA to show a second HTA (with an animation) while the main HTA doing whatever it's doing at the time. However, I'm having trouble getting the new animation HTA to close when the main HTA completes its task. Since the main HTA locks up until it finishes its task, I've tried simply adding an objShell.run before the task and an ObjShell.terminate after the task. However, since it's running from an HTA, the terminate command doesn't seem to want to work, and always throws up an error. I've also attempted switching to a simple animated .gif and using window.open("animated.gif") and window.close("animated.gif"). While that works, the inability to completely remove the border etc is really annoying and not ideal. I have an HTA already made to the specifications I want, I just can't get it to close once its opened.Any ideas?
Tripredacus Posted May 22, 2012 Posted May 22, 2012 FYI: This discussion is a more code-oriented split off of the OP trying to adapt the GImageX HTA to show "something" for progress. Here is where that discussion starts:As I mentioned in the other thread, you'll need to have your HTA check for the presence of a process and then execute the window.close once it is determined that said process isn't running anymore. As for how to do this in VBScript, I couldn't tell you. Here is an example of how to use WMI with VBScript to verify if a process is present, however its a one time check.http://www.wisesoft.co.uk/scripts/vbscript_check_if_a_process_is_running.aspxSo let's take a look at the old code that doesn't work. How exactly this translates into the gray box, I'm not sure, but I would imagine parts of this code could be used to show an HTA instead since it already does appear (usually) when the drive is being imaged. So getting this to show an animation would certainly be easier.progress.style.visibility = "visible" progress.innerHTML = "<table border='0'><tr><td>Percents completed: </td><td>Calculating</td></tr><tr><td>Time remaining: </td><td>Calculating</td></tr></table>"Now there are two Progress functions at the bottom of the HTA but they aren't called anywhere in the code.
dcistech Posted May 22, 2012 Author Posted May 22, 2012 Thanks Tripredacus, apparently I didn't see your post before splitting off here. From my research, it looks like the progress bar code will not work in an HTA because IE stops rendering while the HTA does its thing--hence my attempt to create a pop-up status animation that just lets you know something is happening. My reasoning for making it an HTA rather than a plain .gif (other than the annoying IE frame) being that I eventually want it to display different text depending on the operation--text that could be overlayed onto a generic processing gif. Probably via some sort of create-as-you-go secondary HTA that gets supplied certain variables and then opened.Here is the super simple animation HTA I've put together:<html><HEAD><title>Processing</title><HTA:APPLICATION BORDER = none APPLICATION = yes WINDOWSTATE = normal INNERBORDER = no SHOWINTASKBAR = no SCROLL = no APPLICATIONNAME = "Processing" NAVIGABLE = yes></HEAD><script LANGUAGE="VBScript">Sub Window_onLoad strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor") For Each objItem in colItems intHorizontal = objItem.ScreenWidth intVertical = objItem.ScreenHeight Next intLeft = (intHorizontal - 400) / 2 intTop = (intVertical - 200) / 2 window.resizeTo 400,200 window.moveTo intLeft, intTopEnd Sub</SCRIPT><body background = "pics\processing.gif"></BODY></HTML>As you can see, it's nothing at all complicated.In replacing the original status bar bits that aren't working I've done something simple like this: Start_Processing objWIM.ApplyImage End_ProcessingStart_Processing and End_Processing are both subs I created. My most recent attempt looked like this:Sub Start_Processing Dim processing_hta Set processing_hta = objShell.run("processing.hta")End SubSub End_Processing If processing_hta.status = 0 Then processing_hta.Terminate() Set processing_hta = NothingEnd SubThe HTA opened, but got somewhat angry when it was then instructed to close.The original progress subs trip mentioned are here: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 IfEnd SubSub ProgressHelper(pr,tr)On Error Resume NextintFMin = (tr MOD 3600) \ 60intFSec = (tr MOD 3600) MOD 60progress.style.visibility = "visible"progress.innerHTML = "<table border='0'><tr><td>Percents completed: </td><td>" & pr & "%" & "</td></tr><tr><td>Time remaining: </td><td>" & intFMin & " min " & intFSec & " sec</td></tr></table>"If pr = 100 Thenwindow.clearInterval(iTimerID)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>"ElseExit SubEnd IfEnd SubAnd the same bit of code I posted that attempts to open and close the progress HTA looks like this in the original: progress.style.visibility = "visible" progress.innerHTML = "<table border='0'><tr><td>Percents completed: </td><td>Calculating</td></tr><tr><td>Time remaining: </td><td>Calculating</td></tr></table>" objWIM.ApplyImageSo ya, that's just about everything, aside from looking at the original HTA itself. I can't make heads or tails of the original status bar stuff, and on my end, the gray window trip mentioned is just the after-affect of an earlier HTA being opened and then closed right as the main HTA stops rendering (leaving behind a "shadow" box"). Which make sense if the info I've found is correct and HTA windows stop rendering during tasks.
Tripredacus Posted May 23, 2012 Posted May 23, 2012 I think you need to get the function of closing the progress HTA out of the main HTA and into the progress HTA. That should have no problem closing itself. Like I said, I don't use VBScript much at all, however here is a general method of what I am thinking:1. Wait for imagex.exe process to exist.2. Wait until imagex.exe exits.3. Sleep 1-5 seconds.4. invoke window.close()Now the only app I currently have that waits for a process to close concerns MSIEXEC and it behave differently than imagex does. Another possibility is to move the actuall imaging commands into the progress HTA, so it would be easier (I hope) for that to know when the imaging is done. This was what I did when I created a custom recovery partition that included a main HTA that launched a "progress" HTA. Here is it (with commands changed to xxx)<Title>full</Title> <HTA:APPLICATION ID="FsSplashScreen" SCROLL="No" SCROLLFLAT ="No" SingleInstance="Yes" ShowInTaskbar="No" SysMenu="No" MaximizeButton="No" MinimizeButton="No" Border="none" BORDERSTYLE ="complex" INNERBORDER ="No" Caption="no" WindowState="Normal" APPLICATIONNAME="FsCommandHta" CONTEXTMENU="no" Icon="%SystemRoot%\explorer.exe"><STYLE type="text/css"> BODY { Font:9.25pt; Font-weight:bold; Font-family:helvetica,verdana,arial; Color:#000080; Text-Align:Center; Vertical-Align:Middle; Padding-Top:3; Padding-Bottom:2; Padding-Left:10; Padding-Right:10; background-image:url('resources\animation.gif') }</STYLE><script Language='VBSCRIPT'>'-> Resize And Move Window Dim Wth :Wth = int(250) Dim Hht :Hht = int(50) window.ResizeTo Wth, Hht MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2)) Dim Tmr Sub confirmation2 Dim A1 :A1 = MsgBox("Recovery Complete, Click the Restart button to continue.") If A1 = True Then CreateObject("WScript.Shell").run "fscommand\restart.exe",0,TrueEnd Sub'-> Start The First Timer OnLoad, Three Second Wait Befor It Goes'-> To The ClearTimer Function Function Window_OnLoad() document.focus() Txt1.innerHTML= "Processing The Script Function Please Wait" Tmr=setTimeout("ClearTimer()",3000) Exit Function End Function'-> Process The First Command Function ClearTimer() '-> Object To Run The First Command Hidden, Uncooment To Make Active Set objShell = CreateObject("WScript.Shell") ObjShell.run "xxx",0,True ObjShell.run "xxx",0,True ObjShell.run "xxx",0,True ObjShell.run "xxx",0,True Tmr=clearTimeout("") '-> Place Your Code For confirmation2 Here Start Call confirmation2() '-> Place Your Code For confirmation2 Here End Txt1.innerHTML= "Prepaparing To Close" Tmr=setTimeout("ClearTimer2()",3000) Exit Function End Function'-> Close The Hta Function Function ClearTimer2() Tmr=clearTimeout("") window.close() Exit Function End Function</SCRIPT><BODY Scroll='No'><TABLE><SPAN ID='Txt1'> </SPAN></TABLE></BODY>You'll hate me for now remembering what all this code means. I built it, and then the entire concept failed regression testing and the concept was scrapped. So for example, you'll see there is a mention of a restart.exe in there. I do not know how that is called in this.The main HTA launches this progress HTA using the following function:Sub RunFull Set objShell = CreateObject("WScript.Shell") ObjShell.Run "mshta x:\windows\system32\full.hta",1,True On Error Resume Next Set objShell = NothingEnd Sub
dcistech Posted May 25, 2012 Author Posted May 25, 2012 Thanks for the tips. The processing HTA is now set up to check whether a particular process is running, and close if it isn't. I've been testing it with notepad since I wasn't wanting to deal with the main HTA until I knew my processing HTA was working. From what I can tell, the processing HTA works flawlessly. Here it is looking for notepad.exe:<html><HEAD><title>Processing</title><HTA:APPLICATION BORDER = none APPLICATION = yes WINDOWSTATE = normal INNERBORDER = no SHOWINTASKBAR = no SCROLL = no APPLICATIONNAME = "Processing" NAVIGABLE = yes></HEAD><script LANGUAGE="VBScript">'--------------------------------------------------------------'Globals'--------------------------------------------------------------Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")'--------------------------------------------------------------'Window_onLoad (Resize and center window)'--------------------------------------------------------------Sub Window_onLoad strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor") For Each objItem in colItems intHorizontal = objItem.ScreenWidth intVertical = objItem.ScreenHeight Next intLeft = (intHorizontal - 400) / 2 intTop = (intVertical - 200) / 2 window.resizeTo 400,200 window.moveTo intLeft, intTopEnd Sub'--------------------------------------------------------------'Waiting for GImageX_COM to start the process'--------------------------------------------------------------idTimer = window.setTimeout("Status_Check", 10000, "VBScript")'--------------------------------------------------------------'Check status of operation'--------------------------------------------------------------Sub Status_Check window.clearTimeout(idTimer) GImageXStatus = Not Running strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process") For Each objProcess in colProcessList If objProcess.Name = "notepad.exe" Then GImageXStatus = Running End If Next If GImageXStatus = Running Then idTimer = window.setTimeout("Status_Check", 5000, "VBScript") Else Window.Close End IfEnd Sub</SCRIPT><body background = "pics\processing.gif"></BODY></HTML>Basically, I open it, have it wait ten seconds (waiting in an HTA is annoying because wscript.sleep doesn't work), and then have it look for notepad.exe. If it finds it running, it sets an already defined variable to say "running" (it defaults to "not running") and then waits another five seconds before checking again. Once it does not find notepad.exe running, it closes. It's all pretty awesome.One problem: GImageX_COM does not create a separate process for its tasks. They all run under the original mshta.exe. So... ya.
dcistech Posted May 29, 2012 Author Posted May 29, 2012 (edited) Ok, so I've made a temporary fix barring someone with a more legit idea coming around and sharing it with us. Since the processing HTA can't simply check for the GImageX process, I've "beefed up" the processing subs in the main HTA to create and delete a processing.txt file. The processing HTA then checks for this file--if it exists, it waits five seconds and runs the check again. If the file does not exist, the processing HTA closes. It's roughly equivalent to looking for an elephant by checking for piles of crap, but whatever. It works.If anyone cares, this is what the processing subs look like right at this minute:Sub Start_Processing Set SysFolder = Objfso.GetSpecialFolder(1) objFSO.CreateTextFile(SysFolder & "\processing.txt") objShell.run("processing.hta")End SubSub Stop_Processing Set SysFolder = Objfso.GetSpecialFolder(1) objFSO.DeleteFile(SysFolder & "\processing.txt")End SubObviously, both subs have to be run for the whole thing to work--the start sub before a given process, the stop sub after a given process.And here's the simple processing HTA:<html><HEAD><title>Processing</title><HTA:APPLICATION BORDER = none APPLICATION = yes WINDOWSTATE = normal INNERBORDER = no SHOWINTASKBAR = no SCROLL = no APPLICATIONNAME = "Processing" NAVIGABLE = yes></HEAD><script LANGUAGE="VBScript">'--------------------------------------------------------------'Globals'--------------------------------------------------------------Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")Set objFso = CreateObject("Scripting.FileSystemObject")'--------------------------------------------------------------'Window_onLoad (Resize and center window)'--------------------------------------------------------------Sub Window_onLoad strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor") For Each objItem in colItems intHorizontal = objItem.ScreenWidth intVertical = objItem.ScreenHeight Next intLeft = (intHorizontal - 400) / 2 intTop = (intVertical - 200) / 2 window.resizeTo 400,200 window.moveTo intLeft, intTopEnd Sub'--------------------------------------------------------------'Waiting for GImageX_COM to start the process'--------------------------------------------------------------idTimer = window.setTimeout("Status_Check", 10000, "VBScript")'--------------------------------------------------------------'Check status of operation'--------------------------------------------------------------Sub Status_Check window.clearTimeout(idTimer) Set objFso = CreateObject("Scripting.FileSystemObject") Set SysFolder = Objfso.GetSpecialFolder(1) If objFso.FileExists(SysFolder & "\processing.txt") Then idTimer = window.setTimeout("Status_Check", 5000, "VBScript") Else Window.Close End IfEnd Sub</SCRIPT><body background = "pics\processing.gif"></BODY></HTML>I'm still planning on having the main HTA create the processing HTA with custom text each time it runs, but for now, I'm leaving it as is, and adding the sub calls before/after all the major processes in the main HTA. Edited May 29, 2012 by dcistech
Tripredacus Posted May 29, 2012 Posted May 29, 2012 Hmmm if it helps any, here is some AutoIT code that mentions the Progress tracking ability of the GImagex_COM.dll.Set objWIM = WScript.CreateObject("GImageX.GImageXCtrl", "objWIM_")objWIM.Source = "test.wim"objWIM.Destination = "c:\test"objWIM.ImageIndex = 1objWIM.Check = TRUEobjWIM.Verify = TRUEobjWIM.ApplyImageWScript.DisconnectObject objWIMSet objWIM = NothingSub objWIM_Progress(Percent, TimeRemaining) WScript.Echo Percent & "% - " & TimeRemaining & " sec(s)" ' Abort the operation by using the line below 'objWim.Abort = TRUEEnd SubSub objWIM_ProgressInfo(Info) WScript.Echo InfoEnd SubThis should look familiar as it looks like Geezery adapted the DLL functions (including example names) to VBScript for this HTA. A user on AutoIT forums have reported his VBScript example works, but the AutoIT one does not. Take a look (although the VBScript example is further up)http://www.autoitscript.com/forum/topic/111922-gimagex-comdll-how-to-manage-events-with-objevent/page__view__findpost__p__784958
allanf Posted June 8, 2012 Posted June 8, 2012 The problem with HTAs is that they become unresponsive when performing certain tasks. An HTA can open a reliable Modeless Dialogue Window to show activity.See how the script and style for the Modeless Dialogue Window can be written on-the-fly by the HTA, such that there is no need for more than one file - the main HTA. objProgressWindow.document.write ProgressHTML.innerHTMLwhere "ProgressHTML" is enclosed in XML tags within the body of the HTA.<html> <head> <meta http-equiv="x-ua-compatible" content="ie=9"> <script type="text/vbscript"> HTAResize '********************************************************************************' '*Before HTA starts, resize screen. *' '********************************************************************************' Sub HTAResize window.resizeTo 800,640 intHorizontal = Document.ParentWindow.Screen.AvailWidth intVertical = Document.ParentWindow.Screen.AvailHeight intLeft = (intHorizontal - 800) / 2 intTop = (intVertical - 640) / 2 'move to centerscreen window.moveTo intLeft, intTop End Sub </script> <hta:application id="htaHTA" applicationname="WinRE-O-Matic" border="dialog" maximizebutton="no" minimizebutton="no" scroll="auto" </hta:application> <script type="text/vbscript"> Sub window_onLoad window.setTimeout "OpenProgressWindow", 0, "VBScript" End Sub '********************************************************************************' '*Progress bar. *' '********************************************************************************' Dim objProgressWindow Sub OpenProgressWindow intProgBarWidth = CInt(document.documentElement.clientWidth) intProgBarHeight = 18 intLeft = window.screenLeft intTop = window.screenTop + document.documentElement.clientHeight _ - intProgBarHeight strOptions = "dialogWidth:" & intProgBarWidth _ & "px; dialogHeight:" & intProgBarHeight & "px; dialogLeft: " _ & intLeft & "; dialogTop: " & intTop & "; unadorned: yes; scroll: no;" Set objProgressWindow = _ window.showModelessDialog("about:blank", self, strOptions) objProgressWindow.document.write ProgressHTML.innerHTML strTimedIterations = "TimedIterations" _ & "(" & Chr(34) & intProgBarWidth & Chr(34) & ")" objProgressWindow.setTimeout strTimedIterations, 10, "VBScript" End Sub Sub CloseProgressWindow objProgressWindow.close End Sub </script> </head> <body> <xml id="ProgressHTML"> <html> <head> <script language="vbscript"> intCounter = 0 window.returnValue = self Sub TimedIterations(fullWidth) intFullWidth = CInt(fullWidth) intBarBlockWidth = 150 If intCounter < intBarBlockWidth Then spnBar1.style.width = intCounter Else spnBar2.style.width = intCounter - intBarBlockWidth If intCounter > intFullWidth Then spnBar1.style.width = intBarBlockWidth - (intCounter - intFullWidth) If intCounter = intFullWidth + intBarBlockWidth Then spnBar2.style.width = 0 intCounter = 0 End If End If End If intCounter = intCounter + 1 strTimedIterations = "TimedIterations" _ & "(" & Chr(34) & intFullWidth & Chr(34) & ")" window.setTimeout strTimedIterations, 1, "VBScript" End Sub </script> </head> <body style="background-color: #FFC106; cursor: wait; border: none;"> <span id="spnBar2" style="background-color: #FFC106;"> </span> <span id="spnBar1" style="background-color: green;"> </span> </body> </html> </xml> </body></html>BTW, as a demonstration, there is nothing in this code to cause the Modeless Dialogue Window (the Indeterminate Progress Bar) to close.
gunsmokingman Posted June 8, 2012 Posted June 8, 2012 This is just a simple Demo of a self closing Menu with a 5 second count downYou could have your progress bar where the count down is appearing.Save As DemoPopupMenu.hta<!-- Hta And Script By Gunsmokingman Aka Jake1Eye This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use. This is only posted as example code and meant only to used as such.--><HTA:APPLICATION ID="DemoMenuTimer"SCROLL="No"SCROLLFLAT ="No"SingleInstance="Yes"ShowInTaskbar="Yes"SysMenu="Yes"MaximizeButton="No"MinimizeButton="No"Border="Thin"BORDERSTYLE ="complex"INNERBORDER ="No"Caption="Yes"WindowState="Normal"APPLICATIONNAME="MainApp"Icon="%SystemRoot%\explorer.exe"><TITLE>Demo Popup Menu Self Close</TITLE><!-- For Menu BackGround Dark To Light#D2B48C = Tan#FAF0E6 = Linen#FFFFF0 = Ivory--><STYLE type="text/css">Body{Font-Size:9.25pt;Font-Weight:Bold;Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;Color:Black;BackGround-Color:#EFE9E3;Margin-Top:21;Margin-Bottom:1;Margin-Left:4;Margin-Right:4;Padding-Top:1;Padding-Bottom:1;Padding-Left:4;Padding-Right:4;Text-Align:Center;Vertical-Align:Top;Border-Top:0px Transparent;Border-Bottom:0px Transparent;Border-Left:0px Transparent;Border-Right:0px Transparent;}Div.Menu1{Font-Size:8.05pt;Font-Weight:Bold;Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;Color:Black;BackGround-Color:Transparent;Filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#FFFFF0',EndColorStr='#D2B48C');Border-Left: 1px Dot;Border-Right: 2px Sunken;Border-Top: 1px Dot;Border-Bottom: 2px Sunken;Text-Align:Center;Margin:1;Padding:2;}TD{Font-Size:8.05pt;Font-Weight:Bold;Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;Color:Black;}BUTTON{Height:18pt;width:61pt;Cursor:Hand;Font:8.05pt;Font-weight:bold;Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;Color:#404040;Text-Align:Center;Vertical-Align:Middle;filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E5E5E5',EndColorStr='#7D7D7D');Margin:1;Padding:2;Border-Left: 1px Transparent;Border-Right: 2px Transparent;Border-Top: 1px Transparent;Border-Bottom: 2px Transparent;}</STYLE><script Language='VBSCRIPT'>'-> Varibles For Run TimeDim C1,Tm1'-> Count Up UnComment This Comment Out Count Down' C1=0'-> Count Down Default Fot HtaC1=5'-> Resize And Center WindowDim Wth :Wth = int(425)Dim Hht :Hht = int(175)window.ResizeTo Wth, HhtMoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))'-> Button 01 ClickFunction Button01()If Menu01.style.visibility = "hidden" ThenBtn01.disabled=TrueMenu01.style.visibility = ""' Text1.innerHTML="Processing Please Wait"MyTimer1()ElseMenu01.style.visibility = "hidden"End IfEnd Function'-> Timer FunctionFunction MyTimer1()Select Case C1'-> Uncomment Case 5 For Count Up And Commnet Case 0 To Stop Count Down' Case 5Case 0Btn01.disabled=FalseMenu01.style.visibility = "hidden"'-> Count Up UnComment This Comment Out Count Down' C1=0'-> Count Down Default Fot HtaC1=5Case Else'-> Count Up UnComment This Comment Out Count Down' C1=C1+1Text1.innerHTML="Count At : " & C1'-> Count Down Default Fot HtaC1=C1-1Tm1=window.setTimeout("MyTimer1()",1000,"VBScript")End SelectEnd Function</SCRIPT><BODY><!-- Button To Show Menu 01 And Start Timer --><TABLE Style=''><TD><BUTTON ID='Btn01' OnClick='Button01()'> Show Menu </BUTTON></TD></TABLE><!-- Only Seen When Button 01 Click --><DIV ID='Menu01' Class='Menu1'Style='visibility:hidden;position:absolute;Top:40pt;Left:89;Width:225;Height:48;'><TABLE Border=1><TD>Some Text Here For Details</TD></TABLE><FONT ID='Text1' Style='Font-Size:9.05pt;Width:125;Height:16;Matgin-Top:3pt;' > </FONT></DIV></BODY>
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now