Jump to content

AutoIt progress bar (steps) from RunOnceEx or batch


Recommended Posts

Posted (edited)

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

Edited by phaolo

Posted

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.


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.


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')

:)

Posted (edited)

Wow the script is perfect that way, thanks! :)

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: )


actbar.exe 10 1
pause
actbar.exe 10 3
pause
actbar.exe 10 6
pause
actbar.exe 10 10

Edited by phaolo
Posted
Wow the script is perfect that way, thanks! :)

Nice things the "Interpreter" and "infinite while" solutions (I couldn't understand before why that bar disappeared)

Your welcome :)

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.

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.

I'll add a batch example so you can see the problem.

(You won't reach the first pause :no: )

Try this CMD script


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.

Posted (edited)

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

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?

Edited by phaolo
Posted
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.

"%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.

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.

Posted (edited)

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.

:hello:

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.

Edited by phaolo

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...