Sign in to follow this  
Followers 0
DanDaniels

WinWaitActive and Forced Delays

13 posts in this topic

As one of my first AutoIT projects, I am working on automating burning a DVD with Nero Burning Rom. This is how the script starts:

Opt("WinWaitDelay", 400)
Run ("""C:\Program Files\Ahead\Nero\nero.exe"" /w")
Opt("MouseCoordMode",0)
WinActivate("Nero Express","")
WinWaitActive("Nero Express","")

More times than not, the code hangs on the first window, which never comes into focus. Following a lead elsewhere in this forum, I changed this code to:

Opt("WinWaitDelay", 400)
Run ("""C:\Program Files\Ahead\Nero\nero.exe"" /w")
Opt("MouseCoordMode",0)
EnsureActiveBurn("Nero Express")

Func EnsureActiveBurn($szTitle)
    WinWait($szTitle, "", 90)
    While Not WinActive($szTitle)
         WinActivate($szTitle)
         Sleep(100)
    Wend
    WinWaitActive($szTitle, "", 90)
EndFunc

Which works a litle better but still hangs from time to time. By adding a long Sleep() thus...

Opt("WinWaitDelay", 400)
Run ("""C:\Program Files\Ahead\Nero\nero.exe"" /w")
Opt("MouseCoordMode",0)
Sleep(20000)
EnsureActiveBurn("Nero Express")

Func EnsureActiveBurn($szTitle)
    WinWait($szTitle, "", 90)
    While Not WinActive($szTitle)
         WinActivate($szTitle)
         Sleep(100)
    Wend
    WinWaitActive($szTitle, "", 90)
EndFunc

the code now seems reliable.

Question: Is there a way to wait on a window with certainty and without the use of forced time delays?

Thank you.

Share this post


Link to post
Share on other sites



Question: Is there a way to wait on a window with certainty and without the use of forced time delays?

The timeout is an optional parameter.

Parameters with square brackets surround them, are optional.

Nero also has extensive commandline capability? NeroCMD.exe

CODE
| | [--output_image <filename>]

| |

| | NOTE: At least one audio file or one disk file needs to be

| | specified!

|_______________|

| Write | --write --drivename <name> [--real] [--tao]

| Video CD | --videocd [--speed <speed>] [--speedtest] [--enable_abort]

| | [--close_session] <video files> [--iso <volumename>]

| | [--iso-no-joliet] [--iso-mode2] [--speedtest]

| | [--enable_abort] [--close_session] [--detect_non_empty_disc]

| | [--underrun_prot] [--disable_eject] <disk file>...

| | [--force_erase_disc] [--nero_log_timestamp]

| | [--temp_path <path>] [--output_image <filename>]

|_______________|

| Write Super | --write --drivename <name> [--real] [--tao]

| Video CD | --svideocd [--speed <speed>] [--speedtest] [--enable_abort]

| | [--close_session] <video files> [--iso <volumename>]

| | [--iso-no-joliet] [--iso-mode2] [--speedtest]

| | [--enable_abort] [--close_session] [--detect_non_empty_disc]

| | [--underrun_prot] [--disable_eject] <disk file>...

| | [--force_erase_disc] [--nero_log_timestamp]

| | [--temp_path <path>] [--output_image <filename>]

|_______________|

| Write image | --write --drivename <name> [--real] [--tao] [--dvd]

| | --image <image filename> [--speed <speed>] [--speedtest]

| | [--enable_abort] [--close_session] [--detect_non_empty_disc]

| | [--underrun_prot] [--disable_eject]

| | [--force_erase_disc] [--nero_log_timestamp]

| | [--output_image <filename>]

|_______________|

| Write | --write --drivename <name> [--real] [--tao]

| freestyle disc| [--artist <artist>] [--title <title>] [--speed <speed>]

| | [--cdextra] [--iso <volumename>]

| | [--freestyle_mode1 <filename>]

| | [--freestyle_mode2 <filename>]

| | [--freestyle_audio <filename>]

| | [--iso-no-joliet] [--iso-mode2] [--speedtest]

| | [--enable_abort] [--close_session] [--detect_non_empty_disc]

| | [--cd_text] [--underrun_prot]

| | [--import_udf] [--import_vms_session]

| | [--use_rockridge] [--create_iso_fs] [--create_udf_fs]

| | [--disable_eject] [--verify] [--use_allspace] <disk file>...

| | [--force_erase_disc] [--nero_log_timestamp]

| | [--output_image <filename>]

| |

| | NOTE: Any number of freestyle tracks can be specified up to

| | a maximum of 99 tracks.!

|_______________|

| Estimate | --estimate --drivename <name> [--tao]

| track size | [--iso <volumename>] [--iso-no-joliet] [--iso-mode2]

| | [--close_session] [--import_udf] [--import_vms_session]

| | [--use_rockridge] [--create_iso_fs] [--create_udf_fs]

| | [--disable_eject] [--dvd] [--use_allspace]

| | [--estimate_no_fs_overhead] [--estimate_no_data]

| | [--estimate_no_exact_size] <disk file> ...

|_______________|

| Read audio | --read --drivename <name> [--read_speed <speed>]

| track(s) | --XY <filename> [-XY <filename> ...]

|_______________|

| List audio | --listformats

| formats |

|_______________|

| Erase disc | --erase [--entire] --drivename <name>

|_______________|

| Eject disc | --eject --drivename <name>

|_______________|

| Load disc | --load --drivename <name>

|_______________|

| Obtain image | --imageinfo <filename>

| file disc info|

|_______________|

| Version info | --version

|_______________|

Each command supports the following switches: [--no_error_log],

[--error_log <log filename>], [--no_user_interaction] and [@parameter_file]

_______________

| --write | Burn disc.

|_______________|

| --drivename | <name> is either the "full name" of the drive or the

| <name> | drive letter.

|_______________|

| --real | Forces the disc to be actually burned. If --real is not

| | specified the process is only simulated.

|_______________|

| --tao | Disc is burned in TAO mode (DAO is default).

|_______________|

| --burnproof | Obsolete option, use --underrun_prot instead.

|_______________|

| --artist | <artist> is the artist name as to be written on disc.

| <artist> |

|_______________|

| --title | <title> is the title to be written on disc.

| <title> |

|_______________|

| --read_speed | <speed> is the speed at which the audio tracks will be read

| <speed> | (in x150KB/s).

|_______________|

| --speed | <speed> is the speed at which the disc will be burned

| <speed> | (for CD in x150 KB/s and for DVD in x1,385 KB/s).

|_______________|

| --speed_in_ | <speed> is the speed at which the disc will be burned

| kbps <speed> | (in KB/s).

|_______________|

| --audio | The disc is burned with audio information.

|_______________|

| <audio files> | <audio files> is a list of audio files (wav, mp3, wma, pcm).

|_______________|

| --cdextra | Use the CDExtra feature.

|_______________|

| --iso | <volume name> is the volume name to be stored on the disc.

| <volume name> |

|_______________|

|--iso-no-joliet| Do not use Joliet format.

|_______________|

| --iso-mode2 | Burn the disc using mode 2.

|_______________|

| --speedtest | Perform speed test before burning.

|_______________|

| --enable_abort| Notify which operations can and which cannot be aborted.

|_______________|

|--close_session| Close the session, not the whole disc.

|_______________|

|--detect_non_ | Detect if the disc for burning is a non empty

| empty_disc | RW media and offer to take certain actions.

|_______________|

| --cd_text | Write CD text (if supported by device).

|_______________|

| --videocd | Burn a Video CD.

|_______________|

| --svideocd | Burn a Super Video CD.

|_______________|

| <video files> | <video files> represents a list of video files (mpeg, jpeg).

|_______________|

| --image | <filename> is the filename to the image file.

| <filename> |

|_______________|

| --read | Read audio track(s).

|_______________|

| --XY | XY is the number of the audio track that is to be saved to

| <filename> | <filename>.

|_______________|

| --erase | Erase an RW media.

|_______________|

| --entire | Erase the entire disc (the default is quick erase).

|_______________|

| --eject | Eject disc.

|_______________|

| --load | Load disc.

|_______________|

| --version | Print NeroAPI version information.

|_______________|

| --underrun_ | Protect from underrun condition.

| prot |

|_______________|

| --use_ | Use rockridge format.

| rockridge |

|_______________|

| --create | Create ISO filesystem.

| _iso_fs |

|_______________|

| --create | Create UDF filesystem.

| _udf_fs |

|_______________|

| --dvdvideo | Perform reallocation of files in VIDEO_TS

| _realloc | directory.

|_______________|

| --dvdvideo | Create DVD-Video compatible disc.

| _cmpt | --create_iso_fs --create_udf_fs and

| | --iso_no_joliet also need to be specified.

|_______________|

| --import | Obsolete option; will be ignored.

| rockridge |

|_______________|

| --import_udf | Import UDF format.

|_______________|

| --import_vms | Import Virtual Multisession (VMS) session

| _session | (session number treated as VMS session).

|_______________|

| --import | Obsolete option; will be ignored.

| _iso_only |

|_______________|

| --import | Import session number (if omitted, the last

| <session #> | session is imported).

|_______________|

| --prefer | Obsolete option; will be ignored.

| _rockridge |

|_______________|

| --freestyle_ | Burn the file in mode 1.

| mode1 |

|_______________|

| --freestyle_ | Burn the file in mode 2.

| mode2 |

|_______________|

| --freestyle_ | Burn the file in audio mode.

| audio |

|_______________|

| --disable_ | Disables disc ejection after burn completion.

| eject |

|_______________|

| --verify | Verify ISO filesystem after writing.

|_______________|

| --dvd_high_ | Used for better compatibility of burned DVDs.

| compatibility| At least 1GB will be written.

|_______________|

| --dvd | Select DVD as media type.

|_______________|

| --recursive | Do a recursive file search.

|_______________|

| --force_erase_| Delete disc without user interaction

| disc | (requires --detect_non_empty_disc).

|_______________|

| --nero_log_ | Add a timestamp to the log's file name.

| timestamp |

|_______________|

| --temp_path | Specify a temporary path for Video CD files.

|_______________|

| --media_type | Specify a media type (combine with +)

| <type> | media_cd, media_ddcd, media_dvd_m, media_dvd_p,

| | media_dvd_any, media_dvd_ram, media_ml, media_mrw,

| | media_no_cdr, media_no_cdrw, media_cdrw, media_cdr

| | media_dvd_rom, media_cdrom, media_no_dvd_m_rw,

| | media_no_dvd_m_r, media_no_dvd_p_rw,

| | media_no_dvd_p_r, media_dvd_m_r, media_dvd_m_rw,

| | media_dvd_p_r, media_dvd_p_rw, media_fpacket,

| | media_vpacket, media_packetw, media_hdb or

| | media_dvd_p_r9).

|_______________|

| --no_user_ | Allow the whole process to take place with no user

| interaction | interaction (no questions asked).

|_______________|

| --output_image| Specify output image file name if image recorder is used

| | to avoid prompting for filename.

|_______________|

| --use_allspace| Use all space on the media.

|_______________|

| --relax_joliet| Relax Joliet file name length limitations.

|_______________|

| --japanese_ | CD Text is treated as Japanese CD Text (must include

| cd_text | --cd_text as well).

|_______________|

|--disable_eject| Do not eject the RW media after erasing it.

| _after_erase |

|_______________|

| --force_eject | Force disc ejection after erasing the RW media.

| _after_erase |

|_______________|

| --system_ | <text> is the "system identifier" of an ISO track.

| identifier |

| <text> |

|_______________|

| --volume_set | <text> is the "volume set" of an ISO track.

| <text> |

|_______________|

| --publisher | <text> is the "publisher" of an ISO track.

| <text> |

|_______________|

| --data_ | <text> is the "data preparer" of an ISO track.

|preparer <text>|

|_______________|

| --application | <text> is the "application" of an ISO track.

| <text> |

|_______________|

| --copyright | <text> is the "copyright" of an ISO track.

| <text> |

|_______________|

| --abstract | <text> is the "abstract" of an ISO track.

| <text> |

|_______________|

|--bibliographic| <text> is the "bibliographic" of an ISO track.

| <text> |

|_______________|

| --backup | Replace imported files only if newer are found.

|_______________|

| --booktype | The book type of a burned DVD will be set to

| _dvdrom | DVD-ROM.

|_______________|

| --no_booktype | Do not change the book type of a DVD even if the default

| _change | setting is to change the book type to DVD-ROM.

|_______________|

| --estimate_no | Do not include the file system overhead in calculation.

| fs_overhead |

|_______________|

| --estimate_no | Do not include data in calculation.

| data |

|_______________|

| --estimate_no | Do not calculate the exact size (quicker).

| exact_size |

|_______________|

| --cd_overburn | Specify CD overburn size in blocks.

| <size> |

|_______________|

| --dvd_overburn| Specify DVD overburn size in blocks.

| <size> |

|_______________|

| @param_file | param_file contains the command line arguments.

|_______________|

Share this post


Link to post
Share on other sites

More times than not, the code hangs on the first window, which never comes into focus.

<{POST_SNAPBACK}>

Replace WinWaitActive() to WinWait() .. something like:

Opt("WinWaitDelay", 400)
Run ("""C:\Program Files\Ahead\Nero\nero.exe"" /w")
Opt("MouseCoordMode",0)
WinWait("Nero Express","")
WinActivate("Nero Express","")

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I understand about the optional parameters, but didn't know about the Nero command line options. Thanks.

It's not that the timeout parameter is optional, it's what it's default means. The AutoIT documentation describes it as follows:

[optional] Timeout in seconds

But what happens when the timeout is omitted? There are two choices.

1) There is no timeout, if the window is not there the scripts proceeds immediately.

2) The time out is infinite, the script waits forever for the window.

Question: Does anyone know which it is, 1) or 2) ?

Share this post


Link to post
Share on other sites

Replace WinWaitActive() to WinWait() .. something like:

<{POST_SNAPBACK}>

Ok, but what's the difference? Doesn't a WinWaitActive() also suggest an implied WinWait()? How can a windows come into focus if it does not exist?

Share this post


Link to post
Share on other sites

I understand about the optional parameters, but didn't know about the Nero command line options. Thanks.

It's not that the timeout parameter is optional, it's what it's default means. The AutoIT documentation describes it as follows:

[optional] Timeout in seconds

But what happens when the timeout is omitted? There are two choices.

1) There is no timeout, if the window is not there the scripts proceeds immediately.

2) The time out is infinite, the script waits forever for the window.

Question: Does anyone know which it is, 1) or 2) ?

Timeout:

If you omit the timeout parameter, then your waiting functions will wait forever, until the event happens.

If you use the timeout parameter, then when the timeout reaches zero, then a return value is given (zero), from the function, then the script continues. This allows you do act upon the return value, and take a counter action with the error.

If the timeout does not happen, the script continues successfully.

Ok, but what's the difference? Doesn't a WinWaitActive() also suggest an implied WinWait()? How can a windows come into focus if it does not exist?

If you use Send(), Mouse*() etc., then you will need to use WinWaitActive().

If you use Control*() functions, then the windows do not need to be active. So you could use WinWait(). *

If you windows are considered unreliable to appear, then use timeout, which will give your script a chance to abort. Checking for error, through the script, will achieve this, and to use commands to counter the error.

:)

Share this post


Link to post
Share on other sites

Ok, but what's the difference? Doesn't a WinWaitActive() also suggest an implied WinWait()? How can a windows come into focus if it does not exist?

<{POST_SNAPBACK}>

the sole difference is that WinWait() waits till the windows exists and WinWaitActive() waits till the window exists AND has the Focus (which migth not always happen).

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

If you windows are considered unreliable to appear, then use timeout, which will give your script a chance to abort. Checking for error, through the script, will achieve this, and to use commands to counter the error.

<{POST_SNAPBACK}>

Thanks for the clarification on the timeout parameter and the difference between WinWait() and WinWaitActive(). It's a very sensible implementation.

The "waiting" issue is still not clear to me. If I Run() then immediately WinWait() or WinWaitActive() the script will often hang. Inserting a Sleep() immediately after the Run() fixes this.

Question: Why is the Sleep() necessary?

Share this post


Link to post
Share on other sites

The "waiting" issue is still not clear to me. If I Run() then immediately WinWait() or WinWaitActive() the script will often hang. Inserting a Sleep() immediately after the Run() fixes this.

Question: Why is the Sleep() necessary?

<{POST_SNAPBACK}>

Normally shouldn't be needed..

On which statement is it "Hangng" ?

add Opt("TrayIconDebug", 1) at the top of the script so it will show you the statement...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Normally shouldn't be needed..

On which  statement is it "Hangng" ?

add Opt("TrayIconDebug", 1) at the top of the script so it will show you the statement...

<{POST_SNAPBACK}>

That was a good tip about the TrayIconDebug. Thanks.

Here's the code again:

Opt("TrayIconDebug", 1)
Opt("WinWaitDelay", 500)

Run ("""C:\Program Files\Ahead\Nero\nero.exe"" /w")
; Sleep(20000)

Opt("MouseCoordMode",0)
WinActivate("Nero Express","")
WinWaitActive("Nero Express","")

MouseClick("left", 422, 176, 1)
MouseClick("left", 578, 136, 1)
WinActivate("Select Files and Folders","")
WinWaitActive("Select Files and Folders","")

Without the Sleep(20000) execution skips down to WinActivate("Select Files and Folders","") which hangs because the the first wait, failed which in turn caused the next two mouse clicks to be lost (the application is still opening). With the Sleep() the script works correctly.

All this suggests, to me at least, that you can activate a window before it appears. This then satisfies the following WinWaitActive() and the script proceeds loosing any of the Sends() or MouseClicks() which follow it.

Question: Is this expected behaviour for WinActivate() and WinWaitActivate() ?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Question: Is this expected behaviour for WinActivate() and WinWaitActivate() ?

<{POST_SNAPBACK}>

The WinActivate doesn't do much since the Window isn't available yet and I wouldn't use WinWaitActive() ..

Try and see if this styart works for you ...:

Opt("TrayIconDebug", 1)
Opt("WinWaitDelay", 500)

Run ("""C:\Program Files\Ahead\Nero\nero.exe"" /w")
; Sleep(20000)

Opt("MouseCoordMode",0)
WinWait("Nero Express","What would you like to burn")
WinActivate("Nero Express","")
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Try and see if this works for you ...:

WinWait("Nero Express","What would you like to burn")

WinActivate("Nero Express","")

<{POST_SNAPBACK}>

Yes! Much better! I tried your suggestion on other windows in this application with an equal improvement in reliability.

Can you explain why adding the text parameter works better?

BTW, thank you for going to the trouble of looking up the text on the Nero window for me. That was very generous of you.

Share this post


Link to post
Share on other sites

Yes! Much better! I tried your suggestion on other windows in this application with an equal improvement in reliability.

Can you explain why adding the text parameter works better?

<{POST_SNAPBACK}>

It makes the WinWait() wait until both are true. It looked like "Nero Express" pops up twice and now it waits till the window with this unique text waits.

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0