Sign in to follow this  
Followers 0
MrBoo

Confused about IF...

16 posts in this topic

Hi folks,

I'm hoping you might be able to lend a hand again...

I'm trying to script an app at the moment; and I've got a little conundrum...

I'm running a particular process in an application (basically launching a set of tests in a diagnostics tool); when it completes it displays a results dialogue. I want to screen-print and save the results and move on to the next task. With combinations of Run, WinWait, WinActivate, ControlClick and Send I've got this bit figured out no problem.

The issue is that sometimes there's a dialogue box which pops-up during the tests (warning when there's no CD in the drive); and sometimes it isn't present (if there IS a CD in the drive). I'm not too concerned about the overall effect this has on results, so would simply like to hit "Cancel" on the dialogue, IF it appears.

So, after I have used ControlClick to 'launch' the test sequence, I would use

WinWait("WARNING")
WinActivate("WARNING")
ControlClick("WARNING" , "Cancel, 2 , "left" , 1 , 50 , 10)

...to wait for, and cancel the warning - should it appear. The problem that I have of course, is that I can't use this code as if there is a CD in the drive the warning will never be displayed and therefore the script will simply sit waiting for the 'WARNING' window which will never appear.

Does anyone have any suggestions for how I might use an IF to request the script to cancel the warning should it appear, but otherwise continue on to the next 'stage' which begins

WinWait("RESULTS")

Your ideas and suggestions would be greatly appreciated!

Thanks and regards,

Rob.

Share this post


Link to post
Share on other sites



Thanks for your reply :D

If I'm honest it went completely over my head! ...But it gives me a jumping-off point to look at the Help file again...

I've never looked at defining functions and things; my scripts have always been REALLY basic line-by-line logic so far...

I'll see how I get on!

Thanks again,

Rob.

Share this post


Link to post
Share on other sites

just put the conditional action in the loop

like this

while 1
if WinExists ("title","text") then
ControlClick ("title","text", ControlID, button, clicks)
endif
wend

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

Hi,

Without a sample script to work with, maybe you could use something like

AdlibEnable("WarnCheck", 100)

;Do your stuff here

Func WarnCheck()
   If WinExists("WARNING") Then
        WinActivate("WARNING")
        ControlClick("WARNING" , "Cancel, 2 , "left" , 1 , 50 , 10)
        AdlibDisable()
    ElseIf WinExists("Window After CD Warninig") Then
        AdlibDisable()
    EndIf
EndFunc

Cheers

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hey guys,

Again, thanks for all your advice... I'm still struggling to get my head around it though...

I've tried inserting the code that star2 suggested, and the dialogue box was cancelled as I wished, but then the script didn't continue to do the print screen etc. I also tried with smashly's code but I'm pretty certain I put it in the wrong place or something, as it launched the tests and did the print screen simultaneously, rather than waiting for the tests to finish before doing the print screen.

Here's the code I would have if the warning message was ALWAYS shown. I'd be grateful of any pointers on where I should be inserting the new conditional stuff...

Run("C:\Program Files\PerformanceTest\pt.exe")
WinWait("PassMark(TM) PerformanceTest")
WinActivate("PassMark(TM) PerformanceTest")
ControlClick("PassMark(TM) PerformanceTest", "&Continue", 1035)
WinWait("PerformanceTest 6.1 Evaluation Version")
WinActivate("PerformanceTest 6.1 Evaluation Version")
Sleep(2000)
ControlClick("PerformanceTest 6.1 Evaluation Version" , "" , 1 , "left" , 1 , 370 , 20)
WinWait("WARNING")
WinActivate("WARNING")
ControlClick("WARNING" , "Cancel", 2 , "left" , 1 , 50 , 10)
WinWait("PassMark Rating (PerformanceTest 6.1)")
WinActivate("PassMark Rating (PerformanceTest 6.1)")
Send("{PRINTSCREEN}")
ControlClick("PassMark Rating (PerformanceTest 6.1)", "&OK", 1)
Send("!{F4}")
Run("C:\Windows\System32\mspaint.exe")
WinWait("Untitled - Paint")
WinActivate("Untitled - Paint")
Send("^v")
Sleep(1000)
Send("^s")
WinWait("Save As")
WinActivate("Save As")
Edited by MrBoo

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Run("C:\Program Files\PerformanceTest\pt.exe")
While 1
    If WinExists ("WARNING") Then
        WinActivate("WARNING")
        ControlClick("WARNING" , "Cancel", 2 , "left" , 1 , 50 , 10)
    EndIf
    If WinExists("PassMark(TM) PerformanceTest") = 1 Then
            WinActivate("PassMark(TM) PerformanceTest")
            ControlClick("PassMark(TM) PerformanceTest", "&Continue", 1035)
    EndIf
    If WinExists("PerformanceTest 6.1 Evaluation Version") =1 Then
            WinActivate("PerformanceTest 6.1 Evaluation Version")
            Sleep(2000)
            ControlClick("PerformanceTest 6.1 Evaluation Version" , "" , 1 , "left" , 1 , 370 , 20)
    EndIf
    If WinExists("PassMark Rating (PerformanceTest 6.1)")=1 Then
            WinActivate("PassMark Rating (PerformanceTest 6.1)")
            Send("{PRINTSCREEN}")
            ControlClick("PassMark Rating (PerformanceTest 6.1)", "&OK", 1)
            Send("!{F4}")
            Run("C:\Windows\System32\mspaint.exe")
            WinWait("Untitled - Paint")
            WinActivate("Untitled - Paint")
            Send("^v")
            Sleep(1000)
            Send("^s")
            WinWait("Save As")
            WinActivate("Save As")
    EndIf
WEnd

you need to decide when to exit your script cause this way it will continue looping

Edited by star2

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

Awesome! Thanks for your help!

It does seem to behave correctly with the warning box now; but as you say it continues looping. I'm not sure how to decide when to exit the script from this point. I guess once I've put the filename into the "Save As" box for paint, 'hit enter' and then sent Alt+F4 I'm pretty much done. Is it as easy as simply putting 'Exit' at that point? If I wanted to continue with more operations (say launching another application), how would that affect where I need to put the 'Exit'? (Or might it be easier to call a second script to do the next part?).

Once again your help is greatly appreciated. I promise I'm taking it all in too - I'm learning!

Regards,

Rob.

This is where I'm up to now (I changed things around in your code a bit)...

Run("C:\Program Files\PerformanceTest\pt.exe")
WinWait("PassMark(TM) PerformanceTest")
WinActivate("PassMark(TM) PerformanceTest")
ControlClick("PassMark(TM) PerformanceTest", "&Continue", 1035)
WinActivate("PerformanceTest 6.1 Evaluation Version")
Sleep(2000)
ControlClick("PerformanceTest 6.1 Evaluation Version" , "" , 1 , "left" , 1 , 370 , 20)
While 1
    If WinExists ("WARNING") Then
        WinActivate("WARNING")
        ControlClick("WARNING" , "Cancel", 2 , "left" , 1 , 50 , 10)
    EndIf
    If WinExists("PassMark Rating (PerformanceTest 6.1)")=1 Then
        WinActivate("PassMark Rating (PerformanceTest 6.1)")
        Send("{PRINTSCREEN}")
        ControlClick("PassMark Rating (PerformanceTest 6.1)", "&OK", 1)
        Send("!{F4}")
        Run("C:\Windows\System32\mspaint.exe")
        WinWait("Untitled - Paint")
        WinActivate("Untitled - Paint")
        Send("^v")
        Sleep(1000)
        Send("^s")
        WinWait("Save As")
        WinActivate("Save As")
    EndIf
WEnd

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

It does seem to behave correctly with the warning box now; but as you say it continues looping. I'm not sure how to decide when to exit the script from this point. I guess once I've put the filename into the "Save As" box for paint, 'hit enter' and then sent Alt+F4 I'm pretty much done. Is it as easy as simply putting 'Exit' at that point? If I wanted to continue with more operations (say launching another application), how would that affect where I need to put the 'Exit'? (Or might it be easier to call a second script to do the next part?).

as we put the conditional action (for the warning box) in the loop it will continue doing it's job for ever, as for exiting and starting with another operation, you don't have to do that just start the next operation after the last step of the previous is done so let's say you saved your snapshot, this is when you can add the next operation.

by the way there is some useful functions for capturing screen shots

instead of using what you did:

Send("{PRINTSCREEN}")
ControlClick("PassMark Rating (PerformanceTest 6.1)", "&OK", 1)
Send("!{F4}")
Run("C:\Windows\System32\mspaint.exe")
WinWait("Untitled - Paint")
WinActivate("Untitled - Paint")
Send("^v")
Sleep(1000)
Send("^s")
WinWait("Save As")
WinActivate("Save As")oÝ÷ Û*.q©î±ëaȧ²×u«­¢+Ø%¹±Õ±ÐíMɹ
ÁÑÕɹÔÌÐì)}Mɹ
ÁÑÕÉ}
ÁÑÕÉ¡lÀÌØíÍ¥±9µôÅÕ½ÐìÅÕ½Ðíl°ÀÌØí¥1ÐôÁl°ÀÌØí¥Q½ÀôÁl°ÀÌØí¥I¥¡Ðô´Ål°ÀÌØí¥ ½Ñѽ´ô´Ål°ÀÌØí
ÕÉͽÈôQÉÕuuuuutoÝ÷ ÙìZ^&¶¡zZ_WºÚ"µÍÚ[ÛYH ÔØÜY[ØK]LÉÝÂÈØH[ØÜY[ÔØÜY[ØWÐØJ^QØÝ[Y[Ñ  [È ][ÝÉÌLÑÑT×Ò[XYÙLKÉ][ÝÊBÈØHYÚ[ÛÔØÜY[ØWÐØJ^QØÝ[Y[Ñ    [È ][ÝÉÌLÑÑT×Ò[XYÙLÉ][ÝË
ÎM
NM

Just search the help file for:

_ScreenCapture_Capture

Good luck

Edited by star2

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi,

Thanks for your time (again!)...

After the last activity on this thread yesterday I tried fumbling around on my own a little and put this 'ExitLoop' in - I had a feeling it wouldn't work as it was likely to break the loop before the warning box appeared - I'm still pretty sure it _shouldn't_ work; but it seems to?

Send("!{F4}")
        Sleep(2000)
        ExitLoop
    EndIf
WEnd
MsgBox (1,"Finished","If you see this the script continued out of the loop")

I'm going to continue putting the next operations in and do some more testing to see how it all works. Thanks very much indeed for showing me the better way to do screen-grabs! That's much tidier!

The next challenge I have is 3DMark06... Vista UAC pops-up when I try to run it using "Run" - I'm going to see if ShellExecute is any help - failing that I'll see if launching 3DMark06 with an argument to stop it probing for system info prevents UAC from stepping-in...

Thanks again and best regards,

Rob.

----

Update... Starting with ShellExecute still resulted in UAC (never mind - more learning!). I'll ty with no system information probe now...

Regards,

Rob.

----

Update 2... Starting with -nosysteminfo still makes Vista panic and think I'm trying to destroy the world with 3DMark06.exe and so the UAC warning still pops-up to pass any potential blame on to me (you'll notice I'm not impressed with UAC).

I'm running out of ideas on that one now... I think maybe a new thread is in order so it's easier to search for in future...

Thanks again,

Rob.

----

I'm struggling to start a new thread now? Every PC I use the browser just hangs on the form before it's fully displayed - so any workarounds ideas for starting applications which cause UAC intervention would be great here!

Thanks again,

Rob.

----

Edited by MrBoo

Share this post


Link to post
Share on other sites

well I wouldn't post a lot of replies like what you're doing here !!

that will not make the Mods happy !

u can edit your last reply if u want to !!


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Fixed :D

It did occur to me that my numerous updates might be a little cheeky (especially given as I'm a mod on some forums myself)... But it was either that ot post 'BTT' :P

So... Does anyone have any ideas about how to get around starting an application from inside my script which requires elevated privilleges? Can I make my AutoIt script prompt the user for escalated privilleges when they launch it from the compiled "tests.exe" - that way any app that the script launches would inherit the privilleges, right? Could that be as easy as telling the user to run the tests.exe as Administrator?

...Or do I just write a bit for the beginning of the script that goes to Control Panel and turns off UAC!

Any help would be fantastic...

Regards,

Rob.

Edited by MrBoo

Share this post


Link to post
Share on other sites

Check this out !

my advice search the forum before asking !!


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

Hi star2,

I did run a search on the forum before I started asking questions - I promise!

I didn't find the post that you linked though - but to be completely honest I'm not sure I would've highlighted it as something that will help - purely because most of that goes WAAAAY over my head! I've copied the script into SciTE and I've read through it twice now, but as I'm a long way from being an AutoIt Jedi I can't see where I would actually put the command to run "C:\Program Files\Futuremark\3DMark06\3DMark06.exe"

I'll keep looking at the script and hope I get the idea! ...Either that or I'm just going to disable/request users disable UAC - I'm better with a screwdriver than I am with a script-editor :D

Thanks again, and regards,

Rob.

Share this post


Link to post
Share on other sites

purely because most of that goes WAAAAY over my head! I've copied the script into SciTE and I've read through it twice now, but as I'm a long way from being an AutoIt Jedi I can't see where I would actually put the command to

don't worry, you'll manage to understand how the various of scripts work !!

it will take time (I'm still learning and I'm loving it)

as for the topic I linked to you try to read the topic itself cause the author of the script did explain about it and you can read the other replies and try to ask questions even there about how to use the script !!

:D


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Thanks again... I couldn't see in the post/thread about where I put the command. I tried messing around with it but I didn't get it right.

I've since used RegWrite to disable UAC via the registry and I'm calling 3DMark06.exe with ShellExecute and it's all good (so long as my script is run as Administrator)...

The problem I have now though is that when I couldn't get ControlClick to work on one of the 3DMark dialogues, I thought I'd try MouseClick...

The mouse doesn't click, or even move - and the script doesn't report any errors.

I thought I'd try MouseMove just to see if it would even move this way, but still nothing...

Is there any known issue with MouseClick and MouseMove in certain hardware/software configurations? I've used these two commands the last time I made this script (when it was for XP), and they worked fine?...

Thanks!

Rob.

EDIT: This part's interesting (well, to me at least!) - I just got rid of the call to start 3DMark so my script was just a 'Sleep' and then a 'MouseMove' - the mouse then moved... Does ShellExecute cause me problems in using MouseMove / MouseClick / ControlClick ? Or is there something stranger going on?

This doesn't work...

ShellExecute ("C:\Program Files\Futuremark\3DMark06\3DMark06.exe", "", "C:\Program Files\Futuremark\3DMark06\")
Sleep(20000)
MouseMove(750, 655)

but this does...

Sleep(20000)
MouseMove(750, 655)

Any ideas folks?

Regards,

Rob.

Edited by MrBoo

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