Help - Search - Members - Calendar
Full Version: AutoIt progress bar (steps) from RunOnceEx or batch
MSFN Forums > Unattended Windows Discussion & Support > Application Installs

   
Google Internet Forums Unattended CD/DVD Guide
phaolo
Hello I'd like to enable a progress bar for some silent installs or tweaks.
I don't want to time it, but instead to increase the steps from the code sections (from RunOnceEx or batch files)
I thought at Autoit script, but i have some problems:

1- I don't know how to pass parameters to an active script, so I only managed to run again the same script with new parameters. Last one kills all of them.. not a very good solution.
2- ProgressOn and ProgressSet maintain the process bar window opened only if I add a sleep(ms) line. That wouldn't be a problem if only the batch file that launches the script wouldn't wait too! Where do I do wrong?



Here is the script.
It's a test and I'm not expert, so pardon my programming errors

---------------------------------------------------------------------------------------------------------------------------------

If $CMDLINE[0] = 0 Then
Exit
Else
Dim $Max
Dim $Counter

$Max = $CMDLINE[1]
$Counter = $CMDLINE[2]

ProgressOn("Status","","")

ProgressSet(($Counter/$Max)*100,"","Completed " & ($Counter/$Max)*100 & "%")

; I'd like to avoid this
Sleep(2000)

If $Counter = $Max Then
Sleep(2000)
RunWait(@ComSpec & " /c " & 'taskkill /f /im actbar.exe ', "", @SW_HIDE)
Exit
EndIf
EndIf

----------------------------------------------------------------------------------------------------------------------------------


Example for the file that launches the script (could be in RunOnceEx too):
actbar.exe 10 1
(...some code..)
actbar.exe 10 3
(...some code..)
actbar.exe 10 6
(...some code..)
actbar.exe 10 10
MHz
Hi phaolo,
There is no condition to keep the script running. A loop can be used to keep the script running and that is what I will use below.

Here is some minor modifications to your code that may suit your need. Comments added to explain the steps of operation.
CODE

If $CMDLINE[0] <> 2 Then
; Exit if 2 parameters were not used
Exit 1
Else
; assign parameters to friently variable names
Global $Max = $CMDLINE[1]
Global $Counter = $CMDLINE[2]
; show progress window
ProgressOn("Status", "", "")
; set data to progress window
ProgressSet(($Counter / $Max) * 100, "", "Completed " & ($Counter / $Max) * 100 & "%")
; title to use for the interpreter window title
Global Const $AUTOIT_TITLE = @ScriptName & '_Interpreter'
; close any previous progress windows
If WinExists($AUTOIT_TITLE) Then
WinClose($AUTOIT_TITLE)
WinWaitClose($AUTOIT_TITLE)
EndIf
; set current window as the main interpreter window title
AutoitWinSetTitle($AUTOIT_TITLE)
; if max is reached, then exit
If $Counter = $Max Then
Sleep(2000)
Exit
EndIf
EndIf

; keep the current process running
While 1
Sleep(250)
WEnd

It will overlap the window of the previous execution of progress to prevent a pause between progress window updating and you can change it if it causes issue.

I tested using this script and runs it from the desktop fine.
CODE

Run('"' & @DesktopDir & '\actbar.exe" 10 2')
Sleep(2000)
Run('"' & @DesktopDir & '\actbar.exe" 10 4')
Sleep(2000)
Run('"' & @DesktopDir & '\actbar.exe" 10 6')
Sleep(2000)
Run('"' & @DesktopDir & '\actbar.exe" 10 8')
Sleep(2000)
Run('"' & @DesktopDir & '\actbar.exe" 10 10')


smile.gif
phaolo
Wow the script is perfect that way, thanks! smile.gif
Nice things the "Interpreter" and "infinite while" solutions (I couldn't understand before why that bar disappeared)


I still have the second problem though, because I'm running actbar.exe from a batch file.
I have to use it as I'm doing registry modifications and various operations. Converting all to a script would be long and full of new errors. Putting it in another script would be a poor solution (multiple files).

Anyway, with the batch the execution stops after the first script launch.
I don't know why, dos shouldn't wait for program termination normally! (only with start /wait)

What the.. ??


I'll add a batch example so you can see the problem.
(You won't reach the first pause no.gif )

CODE

actbar.exe 10 1
pause
actbar.exe 10 3
pause
actbar.exe 10 6
pause
actbar.exe 10 10
MHz
QUOTE (phaolo @ Jul 12 2008, 04:46 AM) *
Wow the script is perfect that way, thanks! smile.gif
Nice things the "Interpreter" and "infinite while" solutions (I couldn't understand before why that bar disappeared)

Your welcome smile.gif
QUOTE
I still have the second problem though, because I'm running actbar.exe from a batch file.
I have to use it as I'm doing registry modifications and various operations. Converting all to a script would be long and full of new errors. Putting it in another script would be a poor solution (multiple files).

I am guessing the batch file is a CMD file? That is fine. No matter what type of script that you use, the method of executing Actbar.exe from that script will be basically the same.
QUOTE
Anyway, with the batch the execution stops after the first script launch.
I don't know why, dos shouldn't wait for program termination normally! (only with start /wait)

What the.. ??

Not AFAIK with the NT based interpreter.
  • The CMD interpreter will wait for an execution until processing the next line when a CMD script is used as to invoke the CMD interpreter initially. I notice some particular executions do return immediately as to possibly respawning a new process or some other unknown reason so using Start /wait tends to handle these more reliabily to prevent the immediate return. The default behavior allows the CMD script to complete the command on the line before progressing with the next line.
  • An execution from a CMD prompt will not wait for an execution unless you use Start /wait. The default behavior allows you to do multiple commands without waiting for the CMD prompt.

QUOTE
I'll add a batch example so you can see the problem.
(You won't reach the first pause no.gif )

Try this CMD script
CODE
Start actbar.exe 10 1
pause
Start actbar.exe 10 3
pause
Start actbar.exe 10 6
pause
Start actbar.exe 10 10

While I think of it, a 2nd WinClose maybe needed within the AutoIt script during RunOnceEx period as the 1st seems to get ignored for some reason at that time. Modified the code below to handle the WinClose in a loop.
CODE

If $CMDLINE[0] <> 2 Then
; Exit if 2 parameters were not used
Exit 1
Else
; assign parameters to friently variable names
Global $Max = $CMDLINE[1]
Global $Counter = $CMDLINE[2]
; show progress window
ProgressOn("Status", "", "")
; set data to progress window
ProgressSet(($Counter / $Max) * 100, "", "Completed " & ($Counter / $Max) * 100 & "%")
; title to use for the interpreter window title
Global Const $AUTOIT_TITLE = @ScriptName & '_Interpreter'
; close any previous progress windows
If WinExists($AUTOIT_TITLE) Then
Do
; attempt to close the previous progress window
WinClose($AUTOIT_TITLE)
; perform a sleep if window still exists
If WinExists($AUTOIT_TITLE) Then
Sleep(500)
EndIf
; exit the loop if the window does not exist
Until Not WinExists($AUTOIT_TITLE)
EndIf
; set current window as the main interpreter window title
AutoitWinSetTitle($AUTOIT_TITLE)
; if max is reached, then exit
If $Counter = $Max Then
Sleep(2000)
Exit
EndIf
EndIf

; keep the current process running
While 1
Sleep(250)
WEnd

I expect that you will need to use Start without the wait switch in your CMD file to execute Actbar.exe so the CMD interpreter can progress to the next line of execution which the latter is the one that you want to wait for.
phaolo
No, I'm using a simple BAT. I never encountered a behaviour like that before (usually dos never waits automatically).
Anyway the "start" option works perfectly with the batch. thumbup.gif


Just RunOnceEx problem remains, even if it is secondary now.
It can only run files and not commands directly, so I can't add the "start" option there.
I couldn't test the script from RunOnceEx for that reason.


p.s: err, is "_interpreter" just a string, right?
MHz
QUOTE (phaolo @ Jul 12 2008, 08:27 PM) *
Just RunOnceEx problem remains, even if it is secondary now.
It can only run files and not commands directly, so I can't add the "start" option there.
I couldn't test the script from RunOnceEx for that reason.

Perhaps you can call the Comspec variable. Comspec contains the path to the systems default command interpreter.
CODE
"%COMSPEC%" /c Start actbar.exe 10 2

The above command can be added to registry. You may also try using a bat file from the registry and use it to start actbar.exe.
QUOTE
p.s: err, is "_interpreter" just a string, right?

Correct. Every AutoIt process has a hidden window and the string mentioned is used to set a part of the title for that window. If WinClose is used on that hidden window then the AutoIt process associated with that window closes.
phaolo
You answered all questions in a perfect way!

Wow, I didn't know that I could pass commands to cmd.exe.. that is very useful.
Also %COMSPEC% is new for me.

Now I'll just need to correct minor things (for example a fixed 100 is better than $Max hehe)
You helped me a lot MHz, thank you very much.

welcome.gif


P.S: I found that the Sleep(250) loop causes the program to weight about 3Mb in memory! I've put Sleep(10000) for 300Kb only. I don't think I need small cycles because the script is always killed by the next one.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.