Jump to content

Trying to automate a window


Recommended Posts

Ok this window

post-60350-0-44062800-1400617221_thumb.p

Im trying to check the checkbox then click the reset button

RunWait ( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE )
;~ Send("{TAB}")
ControlSend("[Class:32770]", "Reset Internet Explorer Settings", "6644", "{TAB}")
;~ Send("{+}")

Ive tried send and controlsend but neither seem to respond, but Tab works perfectly

post-60350-0-79550000-1400617320_thumb.p

Control window for reference

So where am i going wrong?

Link to comment
Share on other sites

Don't use RunWait.

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

Or better yet use this.

Run('rundll32.exe inetcpl.cpl ResetIEtoDefaults') ;~ Send("{TAB}")
sleep(500)
ControlClick("Reset Internet Explorer Settings", "", "[CLASS:Button; INSTANCE:1]")

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

$iPID = Run ( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE )
$h = WinWait("[Class:#32770]", "Are you sure you want to reset all Internet Explorer settings?")
WinActivate($h)
ControlFocus($h, "", 6644)
ControlCommand($h, "", 6644, "Check", "")
ControlFocus($h, "", 1)
ControlClick($h, "", 1)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thx guys

Run( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE )
Sleep(1000)
Send("{TAB}")
Send("{+}")
Send("{TAB 2}")
Send("{ENTER}")
Sleep(1000)
WinWaitActive("[CLASS:#32770]")
Send("{ENTER}")

Or

Run( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE )
Sleep(1000)
ControlSend("Reset Internet Explorer Settings", "", "", "{TAB}")
ControlSend("Reset Internet Explorer Settings", "", "", "{+}")
ControlSend("Reset Internet Explorer Settings", "", "", "{TAB}")
ControlSend("Reset Internet Explorer Settings", "", "", "{TAB}")
ControlSend("Reset Internet Explorer Settings", "", "", "{ENTER}")
If WinWaitActive("[CLASS:#32770]") Then
    ControlSend("Reset Internet Explorer Settings", "", "", "{ENTER}")
EndIf

Seems to work either way

Many thanks

Link to comment
Share on other sites

Send is a last resort, ControlSend is MUCH more reliable. Also, all those Tabs are probably not needed at all if you can get the id of the control you need to manage, like my example shows.

BTW, try to avoid using "[CLASS:#32770]" because that can refer to numerous open windows that have nothing to do with the window you're dealing with. It's a very common window class number and can lead to automating the wrong one.

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

This would be one of the best ways...it ensures the window that you manipulate is actually created by your specific 'Run' instance of the rundll32.exe, and not just some window that might happen to have the same title...it could be expanded to verify the window title is as expected, prior to exiting the loop (such as when multiple windows might come about from running the exe).

#include <WinAPIex.au3>
$iPID = Run ( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE )
Local $a = ""
$iTimer = TimerInit()
While Not IsArray($a) And TimerDiff($iTimer)<5000
    $a = _WinAPI_EnumProcessWindows ($iPID,True)
WEnd

If IsArray($a) Then
    $h = $a[1][0]
    WinActivate($h)
    ControlFocus($h, "", 6644)
    ControlCommand($h, "", 6644, "Check", "")
    ControlFocus($h, "", 1)
    ;~ ControlClick($h, "", 1)
Else
    MsgBox(1,1,"coundn't find window")
EndIf

The click was commented out, since I don't want ot clear out anything on my local

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Ok thanks for that, ive commented through that example you gave me so i understand what is happening but there is on that im not sure on when you create the array

#include <WinAPIex.au3>
Global $iPID = Run ( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE ) ; run program to create PID
Local $a = "" ; initalize array as empty
Local $iTimer = TimerInit() ; start timer
While Not IsArray($a) And TimerDiff($iTimer)<5000 ; If no array exists and timer is less than 5 secs
    $a = _WinAPI_EnumProcessWindows ($iPID,True) ; remake array with current windows
WEnd

If IsArray($a) Then ; array data exists
    Local $h = $a[1][0] ;  <<<<<<<<<<<<<<<<<<<<<<<<< this one plz
    WinActivate($h) ; activate the window
    ControlFocus($h, "", 6644) ; set focus to checkbox
    ControlCommand($h, "", 6644, "Check", "") ; check the checkbox
    ControlFocus($h, "", 1) ; set focus to reset button
    ControlClick($h, "", 1) ; click the button

    $h = WinWait("[Class:#32770]", "Resetting Internet Explorer settings") ; find final window
    ControlFocus($h, "", 6608) ; set focus to button
    ControlClick($h, "", 1) ; click the button
Else
    MsgBox(1,1,"coundn't find window")
EndIf

Also ive added in the parts for the final window which pops up after it has finished

Ive added the delay so it waits for the window and it moves the focus to the button but doesnt click the button for some reason?

post-60350-0-00191600-1400656400.png

post-60350-0-94488200-1400656413_thumb.p

Link to comment
Share on other sites

This works for me ...

Run('rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE )
WinWaitActive('Reset Internet Explorer Settings')

Local $handle = WinGetHandle('Reset Internet Explorer Settings')
Msgbox(0, 'handle', $handle)

Local $button = ControlGetHandle($handle, '', '[Class:Button; Instance:1]')
Msgbox(0, 'button', $button)

Local $text = ControlGetText($handle, '', $button)
Msgbox(0, 'text', $text)

If StringInStr($text, 'Delete') Then
    ControlFocus($handle, '', $button)
    Sleep(250); <-- sometimes needed
    ControlClick($handle, '', $button)
EndIf

; <-- more code here

Exit

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

I played with it some more. Hope it works for you.

-edit: added some error checking.

_ResetIEtoDefaults()
MsgBox(0, 'Error Return', @error)

Func _ResetIEtoDefaults()
    Run('rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE)
    Sleep(1000)
    If WinExists('RUNDLL') Then; <-- IE version not supported
        If StringInStr(WinGetText('RUNDLL'), 'Error in inetcpl.cpl') Then
            Return SetError(-1)
        EndIf
    EndIf

    WinWaitActive('Reset Internet Explorer Settings')

    Local $handle = WinGetHandle('Reset Internet Explorer Settings'); <-- 1st window
    Local $button = ControlGetHandle($handle, '', '[Class:Button; Instance:1]')
    Local $text = ControlGetText($handle, '', $button)

    If StringInStr($text, 'Delete') Then
        ControlFocus($handle, '', $button)
        Sleep(250); <-- sometimes needed
        ControlClick($handle, '', $button)
    Else
        Return SetError(-2)
    EndIf

    $button = ControlGetHandle($handle, '', '[Class:Button; Instance:2]')
    $text = ControlGetText($handle, '', $button)
    If StringInStr($text, 'Reset') Then
        ControlFocus($handle, '', $button)
        Sleep(250)
        ControlClick($handle, '', $button)
    Else
        Return SetError(-3)
    EndIf

    Sleep(5000); <-- give some time for new window to appear and to process

    $handle = WinGetHandle('Reset Internet Explorer Settings'); <-- 2nd window
    $button = ControlGetHandle($handle, '', '[Class:Button; Instance:1]')
    $text = ControlGetText($handle, '', $button)

    If StringInStr($text, 'Close') Then
        While WinExists('Reset Internet Explorer Settings')
            Sleep(1000)
            ControlFocus($handle, '', $button)
            Sleep(250)
            ControlClick($handle, '', $button)
        WEnd
    Else
        Return SetError(-4)
    EndIf
EndFunc
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Seeing how this is MS, can you do this with command line?

Agreed ^

Just for the sake of the exercise..._WinAPI_EnumProcessWindows only retruns an array if there are windows to return...so I'm looping until the window is present (the variable becomes an array):

#include <WinAPIex.au3>
Global $iPID = Run ( 'rundll32.exe inetcpl.cpl ResetIEtoDefaults', '', @SW_HIDE ) ; run program to create PID
Local $a = "" ; initalize array as empty
Local $iTimer = TimerInit() ; start timer
While Not IsArray($a) And TimerDiff($iTimer)<5000 ; If no array exists and timer is less than 5 secs
    $a = _WinAPI_EnumProcessWindows ($iPID,True) ; remake array with current windows
WEnd

If IsArray($a) Then ; array data exists
    Local $h = $a[1][0] ;  <<<<<<<<<<<<<<<<<<<<<<<<< this one plz...this is grabbing the window's handle from the array, just because $h is shorter than $a[1][0]
    WinActivate($h) ; activate the window
    ControlFocus($h, "", 6644) ; set focus to checkbox
    ControlCommand($h, "", 6644, "Check", "") ; check the checkbox
    ControlFocus($h, "", 1) ; set focus to reset button
    ControlClick($h, "", 1) ; click the button
    WinWaitClose($h)
Else
    MsgBox(1,1,"coundn't find window")
EndIf

$a = "" ; initalize array as empty
; wait for the next window of the process
Local $iTimer = TimerInit() ; start timer
While Not IsArray($a) TimerDiff($iTimer)<5000 ; If no array exists and timer is less than 5 secs
    $a = _WinAPI_EnumProcessWindows ($iPID,True) ; remake array with current windows
WEnd

If  IsArray($a) Then ; array data exists
    Local $h = $a[1][0] ;  <<<<<<<<<<<<<<<<<<<<<<<<< this one plz...this is grabbing the NEW window's handle from the array
    $h = WinWait($h, "Resetting Internet Explorer settings") ; find final window
    ControlFocus($h, "", 6608) ; set focus to button...is this the correct button id?  Double check it, you are clicking a different one
    ControlClick($h, "", 1) ; click the button
Else
    MsgBox(1,1,"coundn't find second window")
EndIf
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • 1 month later...

Started working on a different window and im still getting problems

Based on the earlier code ive tried

#include <WinAPIex.au3>

Global $iPID = Run ( 'C:\Program Files (x86)\HD Tune\unins000.exe', '', @SW_SHOW ) ; run program to create PID
Local $a = "" ; initalize array as empty
Local $iTimer = TimerInit() ; start timer
While Not IsArray($a) And TimerDiff($iTimer)<5000 ; If no array exists and timer is less than 5 secs
    $a = _WinAPI_EnumProcessWindows ($iPID,True) ; remake array with current windows
WEnd

If IsArray($a) Then ; array data exists
    Local $h = $a[1][0] ;  this is grabbing the window's handle from the array, just because $h is shorter than $a[1][0]
    WinActivate($h) ; activate the window
    ControlFocus($h, "", 6) ; set focus to yes button

    WinWaitClose($h)
Else
    MsgBox(1,1,"coundn't find window")
EndIf

Which fails with the couldnt find window error

EDIT just discovered Run doesnt start the uninstaller for some reason dunno why, ill keep looking

And also

ShellExecute('C:\Program Files (x86)\HD Tune\unins000.exe', '', @SW_SHOW )
sleep(300)
Local $iPID = WinActive('HD Tune Uninstall')
ConsoleWrite($iPID & @CRLF)
;~ WinActivate($iPID)
Local $check = ControlFocus($iPID, "", 6)
ConsoleWrite($check & @CRLF)
Exit

WHich gives me
0x002907F6
0
from the consolewrites

Is there just some windows you cant grab?

post-60350-0-14490800-1403557208_thumb.p

Edited by Chimaera
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...