Sign in to follow this  
Followers 0
anandnz

(Solved)Winwait(timer passed as parameter)& window activate

43 posts in this topic

#1 ·  Posted (edited)

Hi Experts,

Firstly thank you every one here Especially all those who replied. I am almost near to the first draft of the application(my first with AutoIT). I could not proceed a step without your help.

I have two issues bothering me.

1. I am trying to pass the variable defined in array as parameter for WinWaitActive(), doesn't work Need Help.

2. When logged back in as the screen locked up idle for a while, i see that 3rd party dialog box is minimized down and program worked when i have activated the window.

Please need help in handling this as this runs over night for 100 times and screen locks or Network administrators, message may kill my application.

#include <File.au3>
#include <Array.au3>
Local $passlog = "C:\AutoIT_Script_documents\Publishlogs\passlog\Passlog.txt"
Local $faillog = "C:\AutoIT_Script_documents\Publishlogs\faillog\faillog.txt"
Local $common = "P:\technology\Requirements\AutoIT_Script_documents\Scripts\Common\"
Local $killall = "P:\technology\Requirements\AutoIT_Script_documents\Scripts\Common\kill_all.bat"

Local $Scripts[3][4] = [["DesignMech",$common & "Overview_Rename.bat", 5000, True], _
                ["DesignElec",$common & "Elec_Rename.bat", 5000, False], _
                ["DesignProd",$common & "Prod_Features_Rename.bat", 200000, False] ]

;_ArrayDisplay($Scripts)
For $cnt = 0 To UBound($Scripts) - 1
    If $Scripts[$cnt][3] == "True" Then
        ConsoleWrite("The file publishing is " & $Scripts[$cnt][0] & @CRLF)
        ;ConsoleWrite("The batch file is " & $Scripts[$cnt][1] & @CRLF)
        ;ConsoleWrite("The Maximum Time out is " & $Scripts[$cnt][2] & @CRLF)
        $command = "C:\Program Files\OpenFile\bin\exe\win32pc\" & "openfile.exe -file " & $Scripts[$cnt][0] & ""
        ;Local $batchfile =  $Scripts[$cnt][1] This works
        Run($command) ; working hurray !
        ;WinWaitActive("Information","","& $Scripts[$cnt][2]") Timer is not working HELP HERE ..
        WinWaitActive("Information","",""$Scripts[$cnt][2]") ; The timer is not working  as well
        if WinExists("Information") Then ; When screen is locked and when i log in, i notice that this window is down minimized and not activated. HELP Here
        WinActivate("Information") ;  I want this to work even if the system is in standby or other windows pop up.
        Send("{ENTER}")
        _FileWriteLog($passlog, "File " & $Scripts[$cnt][0] & "success")
        sleep(4000)
           Run($Scripts[$cnt][1])
           sleep(4000)
        Else
        _FileWriteLog($faillog, "File " & $Scripts[$cnt][0] & "Failed")
        Run($killall)
        EndIf
    Else
        ConsoleWrite("This file is not selected ... " & $Scripts[$cnt][0] & @CRLF)

    EndIf
Next

Thanks a lot in advance.

-- Anand

Edited by anandnz

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

anandnz,

the 3RD parm of the winwaitactive is a number, you have some unbalanced quotes. Also, the $command variable looks like it is receiving element n,0 "DesignMech, etc...should'nt that be element n,1?

kylomas

edit: also, not sure what you are getting testing for ubound on a multi-dimensional array and not specifying the dimension...see dockylomas

never mind, default is 1

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

You must be able to see, in scite that this - WinWaitActive("Information","",""$Scripts[$cnt][2]") - is incorrect

Cause it will throw an error at you.

Thank you Johnone,

was in a hurry to copy. Yes i corrected the error. My issue is It does not take the parameter from the array i am passing. Is there a way to do it.

Share this post


Link to post
Share on other sites

Hi Kylomas,

Thank you .. corrected the syntax, apologies, It however doesn't put the variable i wanted it from the array.

Please could you also advice me to ensure that only WinActivate("Information")gets all the focus and will not react to any other window. Even though my system goes into idle.

Thank you

--Anand

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This should take away syntax errors, but not sure if it achieves your goal

#include <File.au3>
#include <Array.au3>
Local $Passlog = "C:\AutoIT_Script_Documents\Publishlogs\passlog\Passlog.txt"
Local $Faillog = "C:\AutoIT_Script_documents\Publishlogs\faillog\faillog.txt"
Local $Common = "P:\technology\Requirements\AutoIT_Script_documents\Scripts\Common\"
Local $Killall = "P:\technology\Requirements\AutoIT_Script_documents\Scripts\Common\kill_All.bat"

Local $Scripts[3][4] = [["DesignMech", $Common & "Overview_Rename.bat", 5000, True], _
        ["DesignElec", $Common & "Elec_Rename.bat", 5000, False], _
        ["DesignProd", $Common & "Prod_Features_Rename.bat", 200000, False]]

;_ArrayDisplay($Scripts)
For $Cnt = 0 To UBound($Scripts) - 1
    If $Scripts[$Cnt][3] == "True" Then
        ConsoleWrite("The file publishing is " & $Scripts[$Cnt][0] & @CRLF)
        ;ConsoleWrite("The batch file is " & $Scripts[$cnt][1] & @CRLF)
        ;ConsoleWrite("The Maximum Time out is " & $Scripts[$cnt][2] & @CRLF)
        $command = 'C:\Program Files\OpenFile\bin\exe\win32pc\openfile.exe -file "' & $Scripts[$Cnt][0] & '"'
        ;Local $Batchfile =  $Scripts[$cnt][1] This works
        Run($command) ; working hurray !
        ;WinWaitActive("Information","","& $Scripts[$cnt][2]") Timer is not working HELP HERE ..
        WinWaitActive("Information", "", $Scripts[$Cnt][2]) ; The timer is not working  as well
        If WinExists("Information") Then ; When screen is locked and when i log in, i notice that this window is down minimized and not activated. HELP Here
            Do
                WinActivate("Information") ;  I want this to work even if the system is in standby or other windows pop up.
            Until WinActive("Information")
            Send("{ENTER}")
            _FileWriteLog($Passlog, "File " & $Scripts[$Cnt][0] & "success")
            Sleep(4000)
            Run($Scripts[$Cnt][1])
            Sleep(4000)
        Else
            _FileWriteLog($Faillog, "File " & $Scripts[$Cnt][0] & "Failed")
            Run($Killall)
        EndIf
    Else
        ConsoleWrite("This file is not selected ... " & $Scripts[$Cnt][0] & @CRLF)

    EndIf
Next

EDIT:You can replace Send() with ControlSend() if you know the Control to which you want the string sent or the control to which you want the string sent is in focus by default. Like so:

Run('notepad.exe')
Winwait('[CLASS:Notepad]')
ControlSend('[CLASS:Notepad]', '', '', 'Sent to Notepad with no control specified')
Edited by Varian

Share this post


Link to post
Share on other sites

Thank you Varian,

Unfortunately it did not work for me. when i lock the system. the script doesn't work. When i log back in and click on the dialog box from the third party, the script starts to work again.

Any ideas.

Regards

--Anand

Share this post


Link to post
Share on other sites

Hi Varian,

I will try this control send and get back thank you.

Share this post


Link to post
Share on other sites

Hi Johnone,

Thank you, good idea, probably turn idle off from windows ? However i have to make this run on the virtual server and have no control over it .

Any ideas welcome.

Regards

--Anand

The simple way would be to stop your system going idle.

You could do this by your pc configuration or just throw a mousemove() in every so many minutes.

Share this post


Link to post
Share on other sites

The Basic Control Info Class and Instance are blank from AutoIT window Info

Call item below Title shows "#32770.

The Summary window has this Information.

Title: Information

Class: #32770

Position: 737, 476

Size: 212, 126

Style: 0x94C801C5

ExStyle: 0x00010101

Handle: 0x00C51A98

>>>> Control <<<<

Class:

Instance:

ClassnameNN:

Name:

Advanced (Class):

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Handle:

>>>> Mouse <<<<

Position: 841, 497

Cursor ID: 0

Color: 0x81A7E8

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

OK

Finished Output Generation.

[

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

The Basic Control Info Class and Instance are blank from AutoIT window Info

Call item below Title shows "#32770.

I was not certain that the pc being locked was the issue, but now I see.

There is an FAQ about scripts & locked stations that you need to read.

After that, you will see that ControlSend() is the only possible solution that you have.

With that, if the Control is not focused already, you can try ControlFocus(), but it may not worked when the machine is locked.

Edited by Varian

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thank you Varian,

I tried with out success the following script.

Control Focus and Control send were used. Please advise.

Note: I also tried auto record function, but the FAQ link from you is clear that will not work.

Run($command) ; working hurray !
        ;WinWaitActive("Information","","& $Scripts[$cnt][2]") Timer is not working
        WinWaitActive("Information","",$Scripts[$Cnt][2])
        ControlFocus ( "Information", "text", "OK" )

        If WinExists("Information") Then ;
            Do
                WinActivate("Information") ;
            Until WinActive("Information")
            _WinWaitActivate("Information","Finished Output Gene")
            MouseClick("left",118,16,1)
            MouseClick("left",96,97,1)
        ;Send("{ENTER}")
            ControlSend ( "title", "text", "", "{ENTER}")
            _FileWriteLog($passlog, "File " & $Scripts[$cnt][0] & "success")
        sleep(4000)
        ;ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $commonPRS = ' & $commonPRS & "\" & $file & "_Rename.bat" & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ;
           ;ConsoleWrite("The BATCH FILE IS ......" & $batchfile & @CRLF) ; This works
        ;Run($batchfile) ; working
           Run($Scripts[$cnt][1])
           sleep(4000)
        Else
        _FileWriteLog($faillog, "File " & $Scripts[$cnt][0] & "Failed")
        Run($killall)
        EndIf
    Else
        ConsoleWrite("This file is not selected ... " & $Scripts[$cnt][0] & @CRLF)

    EndIf
Next

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

Thanks

-- Anand

Edited by anandnz

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Replace:

ControlSend ( "title", "text", "", "{ENTER}")

with this:

ControlSend ("[TITLE:Information; CLASS:#32770]", "", "", "{ENTER}")

EDIT: Also, remove the ControlFicus() line as that "OK" is not a proper Control or Control Handle

EDIT EDIT:You can also remove all references to WinActivate() and WinWaitActive() since this you are using ControlSend() and they are useless if the machine is locked

Edited by Varian

Share this post


Link to post
Share on other sites

Hi Varian,

Thank you very much. It works even after locking. I think most of my issues are resolved. Thank you and every one a lot.

Please can i ask a few questions.

1. ControlSend ( "title", "text", controlID, "string" [, flag] ) ; but can we use this input

[TITLE:Information; CLASS:#32770] for title ? I thought it was only "information"

2. I have used ControlFocus("Information", "text", "OK" )based on the following help message.

  • TEXT - The text on a control, for example "&Next" on a button does this. When you asked me not to is it because "OK" is not the button? as it has no "&" in it.
3. What's the equivalent of continue with ability to print some debug message.

I have code like this, I want to ensure i am not breaking anything. Help says if blah blah then continue loop. I am using continue at the end. is that fine.

I

f $Scripts[$cnt][3] == "True" Then
        if WinExists("Cannot Open PDB File") Then
            blah blah
            _FileWriteLog($faillog, "File " & $Scripts[$cnt][0] & "Cannot OpenPDB file ..to debug")
            ContinueLoop; no point in this loop .. go to NEXT...
        EndIf
        ControlFocus("Information", "text", "" )
        If WinExists("Information") Then ;
        blab blah
        Else
        _FileWriteLog($faillog, "File " & $Scripts[$cnt][0] & "Failed")
        Run($killall)
        EndIf
    Else
        ConsoleWrite("This file is not selected ... " & $Scripts[$cnt][0] & @CRLF)
    EndIf
Next

Thanks a ton and Regards

-- Anand

Share this post


Link to post
Share on other sites

Hi Varian,

Thank you very much. It works even after locking. I think most of my issues are resolved. Thank you and every one a lot.

Please can i ask a few questions.

1. ControlSend ( "title", "text", controlID, "string" [, flag] ) ; but can we use this input

[TITLE:Information; CLASS:#32770] for title ? I thought it was only "information"

2. I have used ControlFocus("Information", "text", "OK" )based on the following help message.

  • TEXT - The text on a control, for example "&Next" on a button does this. When you asked me not to is it because "OK" is not the button? as it has no "&" in it.
3. What's the equivalent of continue with ability to print some debug message.

I have code like this, I want to ensure i am not breaking anything. Help says if blah blah then continue loop. I am using continue at the end. is that fine.

Thanks a ton and Regards

-- Anand

ControlSend ( "title", "text", controlID, "string" [, flag] )

You did not fill in the Title & Text properly...unless the title of the window is "title" and text of the window is "text", you need t fill in the appropriate values, i.e.

ControlSend("Information", "some text that is in window", "", "string")
I used the TITLE & CLASS to make sure that we are choosing the appropriate window..there could be another window with "Information" as its' title, but there may only be one (the one we want) that has "Information" as its' title and its' Class is #32270. Look in the Help for "Window Titles and Text (Advanced)" for a further description.

ControlFocus("Information", "text", "OK")

If you want to search by the text of the button, you need to format it like this:

ControlFocus("Information", "text", "[TEXT:OK]")
Look in the Help file for "Controls"

ContinueLoop

Your syntax is correct in you script. ContinueLoop was inside an If...EndIf loop and it needed to be closed with EndIf. If you wanted to add a MsgBox() or ConsoleWrite() after the ContinueLoop, you would do it like this:

if WinExists("Cannot Open PDB File") Then
    ContinueLoop MsgBox(262208, "Error", '"Cannot Open PDB File" Window Exists')
EndIf

One other note that I made but did not stress...in your Array you are using Logical Operators (True, False) yet you are comparing strings when you do this:

If $Scripts[$cnt][3] == "True" Then
Now this is fine for such a small script, but it would be better practice if you used:
If $Scripts[$cnt][3] = True Then
or
If $Scripts[$cnt][3] Then
The issue is that
If $Scripts[$cnt][3] == "True"
will fail if $Scripts[$cnt][3] is "true", not "True".. == is a case-sensitive comparison. The reason I bring this up is that if you use the Logical comparison, $Scripts[$cnt][3] could be True or 1 and the comparison would be true in both cases.

Good luck and glad to help.

Share this post


Link to post
Share on other sites

Thank you a lot Varian.

If not for you and others, i would have taken ages to proceed. I started to like autoit and hopefully get lot of opportunity to use it.

Thanks a ton

Regards

-- Anand

Share this post


Link to post
Share on other sites

ContinueLoop

Your syntax is correct in you script. ContinueLoop was inside an If...EndIf loop and it needed to be closed with EndIf. If you wanted to add a MsgBox() or ConsoleWrite() after the ContinueLoop, you would do it like this:

if WinExists("Cannot Open PDB File") Then
    ContinueLoop MsgBox(262208, "Error", '"Cannot Open PDB File" Window Exists')
EndIf

Do you really want to set the level of the loop like that? Looks kinda funky.

Share this post


Link to post
Share on other sites

Do you really want to set the level of the loop like that? Looks kinda funky.

This was just an example...although it may not very efficient (MsgBox instead of ConsoleWrite or _FileWriteLog or some other "silent" debug) it is programmatically correct.

Share this post


Link to post
Share on other sites

This was just an example...although it may not very efficient (MsgBox instead of ConsoleWrite or _FileWriteLog or some other "silent" debug) it is programmatically correct.

What? How is that correct? Both MsgBox() and ConsoleWrite() would break it horribly unless you add some math, but why bother when you could just out the "whatever" above the ContinueLoop?

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