Sign in to follow this  
Followers 0
pr1

Script can't find active window although it is present

4 posts in this topic

Hi,

I have written an AutoIt script which is supposed to run a Macromedia Flash

application, wait until the process exists, and activate the application's

window. Although this script works fine when manually run, it fails to

activate the window 90% of the time when run by Windows's Task Scheduler,

even when the Macromedia Flash window is active (the script writes a list of

the active windows to a text file when it fails to find the Macromedia Flash

window).

Any help with this matter would be much appreciated.

Many thanks.

pr1

----------------- script ------------------------

Dim $flash_process_name = "demo5.exe"

Dim $flash_window_name = "Macromedia Flash Player 7"

....

$list = ProcessList($flash_process_name)

If $list[0][0] == 0 Then

; If it does not exist, run it

Run($flash_process_name, "", @SW_MAXIMIZE)

if @error <> 0 Then

FileWrite($debug_file, "Could not run demo5.exe. Exiting..." & @CRLF)

FileClose($debug_file)

Exit(2)

EndIf

; slow down so that the Macromedia Flash Window has time to active

sleep(2000)

; Wait for process to be up and running

Dim $processwait = ProcessWait($flash_process_name)

If $processwait == 0 Then

FileWrite($debug_file, "ProcessWait timed out. Exiting..." & @CRLF)

FileClose($debug_file)

Exit(3)

EndIf

; Activate window

Dim $winactivate_result = WinActivate("Macromedia")

If $winactivate_result == 0 Then

FileWrite($debug_file, "Activating '" & $flash_window_name & _

"' window was unsuccessful because window could not be found" & @CRLF)

FileWrite($debug_file, "List of active windows:" & @CRLF)

local $winlist = WinList()

Share this post


Link to post
Share on other sites



> ... it fails to activate the window 90% of the time when run by Windows's Task Scheduler ...

I cannot tell from that if you are saying that 10% of the time it works or 10% of the time if fails for some other reason... If it is failing 100% of the time when started by the OS Task Scheduler, then I have to ask - is the computer locked when this script is running? http://www.autoitscript.com/forum/index.ph...st&p=571221

There might be a silent install option or (if the computer is not locked) you might try the pixel functions to detect the window.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

> ... it fails to activate the window 90% of the time when run by Windows's Task Scheduler ...

I cannot tell from that if you are saying that 10% of the time it works or 10% of the time if fails for some other reason... If it is failing 100% of the time when started by the OS Task Scheduler, then I have to ask - is the computer locked when this script is running? http://www.autoitscript.com/forum/index.ph...st&p=571221

There might be a silent install option or (if the computer is not locked) you might try the pixel functions to detect the window.

In fact, it never works when the computer is locked, although the "Macromedia Flash Player 7" is actually there.

Many thanks for mentioning the lock problem and its solutions.

Share this post


Link to post
Share on other sites

... Many thanks for mentioning the lock problem and its solutions.

You are welcome.

There are many ways to code things and I'm not a programmer by training or trade... but you might make this:

$list = ProcessList($flash_process_name)

If $list[0][0] == 0 Then

; If it does not exist, run it

Run($flash_process_name, "", @SW_MAXIMIZE)

into a single line If without an EndIf:

If Not ProcessExists($flash_process_name) Then Run($flash_process_name, "", @SW_MAXIMIZE)

...and this:

; slow down so that the Macromedia Flash Window has time to active

sleep(2000)

; Wait for process to be up and running

Dim $processwait = ProcessWait($flash_process_name)

into a single line:

Dim $processwait = ProcessWait($flash_process_name, 2)

have fun...


[size="1"][font="Arial"].[u].[/u][/font][/size]

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