Jump to content

ControlGetFocus & ControlFocus, Help! Plz!


 Share

Recommended Posts

Hello eveyone,

I really need some help with this script.

I'm trying to automatically install an application with the following window name "Setup - SafeCom Go HP software package". The script navigates through the installation wizard and i need to keep the focus of the script in the wizard window.

Just in case a pop-up appears or there's a click somewhere else in the screen.

I've been trying to achieve this using the ControlGetFocus & ControlFocus functions, but i'm not sure if this is how they work.

Also i'm trying to display the $CurrFocus variable value to see if the function is taking the correct number, but i don't know how to do that either.

;
; AutoIt Version: 3.0
; Language:    English
; Platform:    WS2008/ws2003
; Author:        Antonio Gayo / HP
;
; Script Function:
;   Runs SafeCom Go setup program and pushes correct buttons to run it unattended
;
; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
;$answer = MsgBox(4, "AutoIt - SafeCom Go Unattended Setup", "This script run the unattended SafeCom GO setup script.  Run?")
 
; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
;If $answer = 7 Then
;   MsgBox(0, "Unattend install cancled", "OK.  Bye!")
;   Exit
;EndIf
; specify the directory location for the SafeCom Go install file. It must be in the same folder as the Auto install file
$d = @WorkingDir & "\" & "safecom_go_hp_04005.exe"
;MsgBox(0, "file", $d)
Run($d)
; Wait for the SafeCom Go setup program to become active - it is titled "Setup - SafeCom Go HP software package" on English systems
WinWaitActive("Setup - SafeCom Go HP software package")
; Now that the window is active step through the screens
; Use AutoItSetOption to slow down the typing speed so we can see it :)
AutoItSetOption("SendKeyDelay", 400)
; Retrieve current focus ID
$CurrFocus = ControlGetFocus("Setup - SafeCom Go HP software package")
; MessageBox to check the Focus ID
MsgBox(0, "Current Focus", StringFormat("%CurrFocus",$CurrFocus), 5)
Sleep(5000)
; Set Focus on SafeCom Go installation
ControlFocus("Setup - SafeCom Go HP software package", "", $CurrFocus)
; ControlClick("Setup - SafeCom Go HP software package", "", "[CLASS:Button; TEXT:&Next; INSTANCE:2]")
; Initial screen click Next and wait 3 seconds to copy files
Send("!n")
Sleep(3000)
; Enter installation path and click Next - Default
; IMPORTANT: INSTALL SAFECOM G3 FIRST TO MAKE SURE THE PATH IS CORRECT
ControlFocus("Setup - SafeCom Go HP software package", "", $CurrFocus)
Send("!n")
; Start Installation
ControlFocus("Setup - SafeCom Go HP software package", "", $CurrFocus)
Send("!I")
; Wait 30 seconds to install files
Sleep(30000)
; Finish Installation
ControlFocus("Setup - SafeCom Go HP software package", "", $CurrFocus)
Send("!F")
; Wait 6 seconds to finish the process
Sleep(6000)
; Close SafeCom Administrator
ProcessClose("scAdministrator.exe")
; Finish!

Please if someone can give me a hand i would really appreciate it. :graduated:

Edit1: I think i could do it also like this:

$d = @WorkingDir & "\" & "safecom_go_hp_04005.exe"
Run($d)
WinWaitActive("Setup - SafeCom Go HP software package")
AutoItSetOption("SendKeyDelay", 400)
ControlClick("Setup - SafeCom Go HP software package", "", "[CLASS:TNewButton; TEXT:&Next >; INSTANCE:1]")
Sleep(3000)
ControlClick("Setup - SafeCom Go HP software package", "", "[CLASS:TNewButton; TEXT:&Next >; INSTANCE:3]")
ControlClick("Setup - SafeCom Go HP software package", "", "[CLASS:TNewButton; TEXT:&Install; INSTANCE:3]")
Sleep(30000)
ControlClick("Setup - SafeCom Go HP software package", "", "[CLASS:TNewButton; TEXT:&Finish; INSTANCE:3]")
Sleep(6000)
ProcessClose("scAdministrator.exe")
; Finish!

But for some reason the second click is not being applied, the first one works.

Edit2: I think i made it work fine, i need to test with some popups and screens to throw in the middle of the installation process.

;
; AutoIt Version: 3.0
; Language:    English
; Platform:    WS2008/ws2003
; Author:        Antonio Gayo / HP
;
; Script Function:
;   Runs SafeCom Go setup program and pushes correct buttons to run it unattended
;
; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
;$answer = MsgBox(4, "AutoIt - SafeCom Go Unattended Setup", "This script run the unattended SafeCom GO setup script.  Run?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
;If $answer = 7 Then
;    MsgBox(0, "Unattend install cancled", "OK.  Bye!")
;    Exit
;EndIf
; specify the directory location for the SafeCom Go install file. It must be in the same folder as the Auto install file
$d = @WorkingDir & "\" & "safecom_go_hp_04005.exe"
;MsgBox(0, "file", $d)
Run($d)
; Wait for the SafeCom Go setup program to become active - it is titled "Setup - SafeCom Go HP software package" on English systems
WinWaitActive("Setup - SafeCom Go HP software package")
; Now that the window is active step through the screens
; Use AutoItSetOption to slow down the typing speed so we can see it
AutoItSetOption("SendKeyDelay", 400)
; Set focus on SafeCom Go installation in every action
; Initial screen click Next and wait 2 seconds to copy files
ControlClick("Setup - SafeCom Go HP software package", "&Next >", "TNewButton1")
;Send("!n")
Sleep(2000)
; Enter installation path and click Next - Default
; IMPORTANT: INSTALL SAFECOM G3 FIRST TO MAKE SURE THE PATH IS CORRECT
ControlClick("Setup - SafeCom Go HP software package", "&Next >", "TNewButton3")
Sleep(2000)
; Start Installation
ControlClick("Setup - SafeCom Go HP software package", "&Install", "TNewButton3")
; Wait 30 seconds to install files
Sleep(30000)
; Finish Installation
ControlClick("Setup - SafeCom Go HP software package", "&Finish", "TNewButton3")
; Wait 6 seconds to finish the process
Sleep(9000)
; Close SafeCom Administrator
ProcessClose("scAdministrator.exe")
; Finish!

Thanks!!!!

Edited by AntonioGNAL
Link to comment
Share on other sites

OK, another option is to use InstallShield or Wise to make a package. That way there is no clicking, no chance for the user to interfere during the install, and you can get the install just the way you want.

Now if you really want to go the route your going you need to look at WinWaitActive instead of using Sleep. The reason here is if the PC is slow, then your script will break. Look at using the AutoIt Window Info tool to get the title and text of the windows you are looking for.

Take a look at the script I edited for you. You will see how I added WinWaitActive in the place of Sleep. You will need to add the text that is in each window do WinWaitActive will know just the screen you are on.

;
; AutoIt Version: 3.0
; Language:    English
; Platform:    WS2008/ws2003
; Author:       Antonio Gayo / HP
;
; Script Function:
;   Runs SafeCom Go setup program and pushes correct buttons to run it unattended
;
; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
;$answer = MsgBox(4, "AutoIt - SafeCom Go Unattended Setup", "This script run the unattended SafeCom GO setup script.  Run?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
;If $answer = 7 Then
;    MsgBox(0, "Unattend install cancled", "OK.  Bye!")
;    Exit
;EndIf
; specify the directory location for the SafeCom Go install file. It must be in the same folder as the Auto install file

AutoItSetOption("SendKeyDelay", 400)
; Set focus on SafeCom Go installation in every action
; Initial screen click Next and wait 2 seconds to copy files

$d = @WorkingDir & "\" & "safecom_go_hp_04005.exe"
;MsgBox(0, "file", $d)
Run($d)
; Wait for the SafeCom Go setup program to become active - it is titled "Setup - SafeCom Go HP software package" on English systems
WinWaitActive("Setup - SafeCom Go HP software package")
; Now that the window is active step through the screens
; Use AutoItSetOption to slow down the typing speed so we can see it

ControlClick("Setup - SafeCom Go HP software package", "&Next >", "TNewButton1")
;Send("!n")
;~ Sleep(2000)
WinWaitActive("Setup - SafeCom Go HP software package", "some text from the next screen")
; Enter installation path and click Next - Default
; IMPORTANT: INSTALL SAFECOM G3 FIRST TO MAKE SURE THE PATH IS CORRECT
ControlClick("Setup - SafeCom Go HP software package", "&Next >", "TNewButton3")
;~ Sleep(2000)
WinWaitActive("Setup - SafeCom Go HP software package", "some text from the next screen")
; Start Installation
ControlClick("Setup - SafeCom Go HP software package", "&Install", "TNewButton3")
; Wait 30 seconds to install files
;~ Sleep(30000)
WinWaitActive("Setup - SafeCom Go HP software package", "some text from the next screen")
; Finish Installation
ControlClick("Setup - SafeCom Go HP software package", "&Finish", "TNewButton3")
; Wait 6 seconds to finish the process
;~ Sleep(9000)
WinWaitActive("Setup - SafeCom Go HP software package", "some text from the next screen")
; Close SafeCom Administrator
ProcessClose("scAdministrator.exe")
; Finish!

#cs
Questions:
1. Can the application window be moved off the screen using WinMove? That
would help keep the user from interfering with the install.
2. Do you uneed to lock the mouse and keyboard while the install happens?
#ce
Link to comment
Share on other sites

Wow, thanks MPH!

I opened another topic that could be also linked to this one:

I will definetly use the WinWaitActive if it's a possibility.

answering your questions.

Questions:

1. Can the application window be moved off the screen using WinMove? That

would help keep the user from interfering with the install.

2. Do you uneed to lock the mouse and keyboard while the install happens?

1. It would be really great if i could move the window off the screen and still press the buttons. Or even better if the script could be executed with the session locked (so it still works even if the session times out). Please, if it is possible let me know.

2. It's not a requirement, but it might certainly help. So if that's also possible, yes, i'd love to do that too.

I used this script because it was an easy one, in fact the way it is now it works.

However i'm having trouble with other two scripts i need to implement, because they have different kinds of buttons i'm not sure how to press:

ControlCommand:

ControlCommand("Setup - SafeCom G3", "C:\Program Files\SafeCom\SafeComG3", "TEdit1", "EditPaste" , "E:\SafeComG3")

Is this command correct? Since it is the first time i use it, i'm not sure how to do this. I need to change the route in a path text box from default to the one i choose.

ControlClick:

ControlClick("Setup - SafeCom G3", "I &accept the agreement", "TNewRadioButton1")

ControlClick("Setup - SafeCom G3", "", "TNewCheckListBox1", 10, 31)

ControlClick("Setup - SafeCom G3", "", "TNewCheckListBox1", 10, 9)

This are the ones i posted in the other topic, i need to press some round boxes in the wizard, but i'm not sure how to do it properly.

If you could gide me a little i would really appreciate it. I'm really starting with AutoIt because it was required but noone told me how it works, so i'm doing what i can with the information i find on the internet.

Thank you very very much.

Best regards.

Edit1:

I will add the entire second script so you can see it, i will change the Sleep comands in this one also. :graduated:

;
; AutoIt Version: 3.0
; Language: English
; Platform: WS2008/ws2003
; Author: Antonio Gayo / HP
;
; Script Function:
; Runs SafeCom setup program and pushes correct buttons to run it unattended
;
; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
;$answer = MsgBox(4, "AutoIt - SafeCom G3 Unattended Setup", "This script runs the unattended SafeCom G3 setup script. Run?")
; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
;If $answer = 7 Then
;   MsgBox(0, "Unattend install cancled", "OK.  Bye!")
;   Exit
;EndIf
; Specify the directory location for the SafeCom G3 install file. It must be in the same folder as the Auto install file
$d = @WorkingDir & "\" & "safecom_g3_410_07.exe"
;MsgBox(0, "file", $d)
Run($d)
; Wait for the SafeCom G3 setup program to become active - it is titled "Setup - SafeCom G3"
WinWaitActive("Setup - SafeCom G3")
; Now that the window is active step through the screens
; You may use AutoItSetOption to slow down the typing speed to be able to see it
AutoItSetOption("SendKeyDelay", 400)
; Initial screen click "Next" and wait 2 seconds
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton1")
Sleep(2000)
; Accept license agreement and click Next
ControlClick("Setup - SafeCom G3", "I &accept the agreement", "TNewRadioButton1")
Sleep(1000)
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton2")
Sleep(1000)
; Move cursor down to select advanced installation mode
ControlClick("Setup - SafeCom G3", "", "TNewCheckListBox1", 10, 31)
Sleep(1000)
; Click Next
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton2")
Sleep(1000)
; Select Server installation
ControlClick("Setup - SafeCom G3", "", "TNewCheckListBox1", 10, 9)
Sleep(1000)
; Click Next
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton2")
Sleep(1000)
; Change the destination program folder and click Next
ControlCommand("Setup - SafeCom G3", "C:\Program Files\SafeCom\SafeComG3", "TEdit1", "EditPaste" , "E:\SafeComG3")
Sleep(1000)
; Click Next
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton4")
Sleep(1000)
; Keep the data folder and click Next
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton4")
Sleep(1000)
; Here you might want to add another control command, e.g.
; ("D:\SafeCom\data")
; Here we select the SQL Server Installation mode - default SQL Server 2008 Express
ControlClick("Setup - SafeCom G3", "", "TNewCheckListBox1", 10, 9)
Sleep(1000)
; Click Next
ControlClick("Setup - SafeCom G3", "&Next >", "TNewButton4")
Sleep(1000)
; Click INSTALL to start installation process
ControlClick("Setup - SafeCom G3", "&Install >", "TNewButton4")
Sleep(1000)
; Now wait 20 minutes for the SQL Server to be installed and Finish the SafeCom installation
Sleep(1200000)
ControlClick("Setup - SafeCom G3", "&Finish", "TNewButton1")
; Now wait for program to close before continuing
WinWaitClose("Setup - SafeCom G3")
; Wait 6 seconds to finish the process
Sleep(6000)
; Close SafeCom Administrator
ProcessClose("scAdministrator.exe")
; Finished!
Edited by AntonioGNAL
Link to comment
Share on other sites

The easy thing to remember is this: The help file is your friend and searching the forum helps too!

To move the window off the screen during the install - like I said - use WinMove. Look up WinMove in the help file and take a look at the example script. In fact try the example script out in SciTE. The example script is just one line showing the command and how it would interact on a notepad window.

WinMove("[CLASS:Notepad]", "", 0, 0, 200, 200)

In this case with the window you want to interact with is all you would do is move the window like this:

WinMove("Setup - SafeCom G3", "", 0, 0, 200, 200)

The best way to test ControlCommand is make a small script to interact with the window and just set the checkbox. If it works then you add the snippit of code into your main script.

Edited by MPH
Link to comment
Share on other sites

I've been using the help in this website:

http://www.autoitscript.com/autoit3/docs/functions/ControlCommand.htm

And also AutoIt wiki, but i'm not really good understanding how the parameters work unfortunately. ;)

I'll try your idea of creating a smaller script just for the part i need. To check it and run it over and over again, that should help me identify the problems.

Example:

; Accep License Agreement
Global $Title = "Setup - SafeCom G3"
; Click I Accept the agreement
ControlClick($Title, "I &accept the agreement", "TNewRadioButton1")
; Finish!

I think i might be able to make it work this way. :graduated:

Could you point me in the right direction for this?

ControlClick($Title, "", "TNewCheckListBox1", 10, 31)

EDIT1: I can do it with this, but it's not the same:

; Select Advanced Installation option
Global $Title = "Setup - SafeCom G3"
; Click I Accept the agreement
ControlCommand($Title, "Installation options", "TNewCheckListBox1", "TabRight", "")
; Finish!

Am i using the numbers correctly? I took the ControlClick Coords in the AutoIt Info tool. But i'm not sure if those are the appropiate numbers.

Thanks.

Edited by AntonioGNAL
Link to comment
Share on other sites

You could probably also use ControlSend, or just Send to set the checkbox with an ALT-A sent to the window.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You could probably also use ControlSend, or just Send to set the checkbox with an ALT-A sent to the window.

Thanks BrewManNH,

I know i can't use the send command, because it is interrupted by screensavers, pop-ups, etc. loosing the focus. But maybe it can work somehow with ControlSend...

Here is the thing:

http://img.photobucket.com/albums/v358/Daryon/Imagenes/ServerInstallation_001.jpg

In some steps of the installation i might find the following, the focus is in the "Next" button, and using TAB i can only navigate through the lower buttons, but it never reaches the 3 items in the check list. Also, those items do not have a send option like an ALT+KEY, sometimes in the installation you can see buttons like "Next >" with a small line indicating the key to press, but in this case that's not possible either. ;)

Any ideas or suggestions?

Thanks!!!

EDIT1:

I think i'm close to it guys!!! i used this:

; Select Server Installation
Global $Title = "Setup - SafeCom G3"
; Click I Accept the agreement
ControlClick($Title, "", "TNewCheckListBox1", "primary")
; Finish!

And although the selection marked the wrong item, if i can now send a SPACE or something like that, then i could navigate the menu with TAB. I'll keep trying. :graduated:

EDIT2: Argh!!! It almost worked... :)

http://img.photobucket.com/albums/v358/Daryon/Imagenes/Tools_001.jpg

I managed to select the Tools Option, but i need the server option, and i can't move it sending a TAB command, because TAB works only in the lower buttons.

ControlClick($Title, "", "TNewCheckListBox1", "primary")
ControlSend($Title, "", "TNewCheckListBox1", "{SPACE}")
ControlSend($Title, "", "TNewCheckListBox1", "{TAB}")
Edited by AntonioGNAL
Link to comment
Share on other sites

Ok, i made it... but it doesn't make any sense...

It worked with this:

ControlClick($Title, "", "TNewCheckListBox1", "secondary")
ControlSend($Title, "", "TNewCheckListBox1", "{SPACE}")
Sleep(1000)
ControlClick($Title, "", "TNewCheckListBox1", "secondary")
ControlSend($Title, "", "TNewCheckListBox1", "{SPACE}")

Why would i have to send the command twice to make it work?

The first two lines make no effect, and when they are launched for the second time it works and marks the correct option... i don't understand it... ¿?¿?

EDIT1:

Ok, it works because of the SPACE inputs...

ControlClick($Title, "", "TNewCheckListBox1", "secondary")
ControlSend($Title, "", "TNewCheckListBox1", "{SPACE}")
ControlSend($Title, "", "TNewCheckListBox1", "{SPACE}")

This also works, so i guess this is the correct way to do it, at least the best i found so far.

Edited by AntonioGNAL
Link to comment
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
 Share

  • Recently Browsing   0 members

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