Jump to content
Sign in to follow this  
doonyakka

Waiting for window to perform an action before closing

Recommended Posts

doonyakka

Hi, I've finished my first AutoIt script (it works!) and have a question about improving it. It's a very short, simple script that automates the installation and configuration of my personal firewall, using a third-party installer. The script runs the third-party installer and then enters the correct registration details in the various fields. The installer then configures the firewall according to the existent connection (eg., LAN, Wifi, dial-up, etc). At the moment, I am using the Sleep command to allow the installer enough time to complete the configuration, but this seems quite clumsy.

However, I was wondering if there is a more elegant and reliable way of doing this, ie., is there a command that would detect that the installer is finished?

Any advice much appreciated. If interested, see code below.

Cheers,

doonyakka

#RequireAdmin
Run("APP_NAME"); replace APP_NAME with the full app name and path
WinWaitActive("APP_NAME", "")
ControlSend("", "", "Edit1", "NAME"); replace NAME with your Registration Name
ControlSend("", "", "Edit3", "SERIAL_NUMBER"); replace SERIAL_NUMBER with your registered Serial number
ControlClick("", "", "[CLASS:Button; TEXT:Register; INSTANCE:2]")
Sleep(6000)
WinClose("APP_NAME", "")
Exit

Share this post


Link to post
Share on other sites
narayanjr

#RequireAdmin
Dim $last_active = 0
Dim $Inactive_Seconds = 5
Dim $timer = TimerInit()
Dim $count = 0
$not_idle = _CheckIdle($last_active, 1)

Run("APP_NAME"); replace APP_NAME with the full app name and path
WinWaitActive("APP_NAME", "")
ControlSend("", "", "Edit1", "NAME"); replace NAME with your Registration Name
ControlSend("", "", "Edit3", "SERIAL_NUMBER"); replace SERIAL_NUMBER with your registered Serial number
ControlClick("", "", "[CLASS:Button; TEXT:Register; INSTANCE:2]")

While (1)
    $not_idle = _CheckIdle($last_active)
    If $not_idle <> 0 Then $timer = TimerInit()
    sleep(2000)
    If Int(TimerDiff($timer) / 1000) >= $Inactive_Seconds Then
        if $count = 0 Then
            WinClose("APP_NAME", "")
            Exit
        EndIf
        $timer = TimerInit()
        $not_idle = _CheckIdle($last_active, 1)
    EndIf
WEnd

Func _CheckIdle(ByRef $last_active, $start = 0)
    $struct = DllStructCreate("uint;dword");
    DllStructSetData($struct, 1, DllStructGetSize($struct));
    If $start Then
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
        $last_active = DllStructGetData($struct, 2)
        Return $last_active
    Else
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
        If $last_active <> DllStructGetData($struct, 2) Then
            Local $save = $last_active
            $last_active = DllStructGetData($struct, 2)
            Return $last_active - $save
        EndIf
    EndIf
EndFunc   ;==>_CheckIdle

well thats another way it waits for the computer to be idle for 5 seconds before it closes the program

and the idle isnt my scripting i forget who i got it off of a while ago

Share this post


Link to post
Share on other sites
herewasplato

...is there a command that would detect that the installer is finished?...

Welcome to the forum... there is no one command that I know of that will do this, but consider these work arounds:

1)

ControlClick("", "", "[CLASS:Button; TEXT:Register; INSTANCE:2]")

WinWait("APP_NAME", "text")

WinClose("APP_NAME", "")

Where text = some text that only shows up when the install is done...

2)

If there is no unique text that you can key off of - you might want to look for a file that exists only after the install/config has completed - like maybe a log file. See the AutoIt function for FileExists ().

3)

If none of the above work, but there is a log file or ini file that is created and written to throughout the install procedure - you might have to compare the date/time stamp or file size on that file to see when it stops changing.

Maybe others have better work arounds... MSP


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

Share this post


Link to post
Share on other sites
doonyakka

Thanks for the helpful replies :)

herewasplato's first suggestion does exactly what I was looking for - ingenious!

1)

ControlClick("", "", "[CLASS:Button; TEXT:Register; INSTANCE:2]")

WinWait("APP_NAME", "text")

WinClose("APP_NAME", "")

Where text = some text that only shows up when the install is done...

Cheers,

doonyakka

Share this post


Link to post
Share on other sites
herewasplato

Glad that it worked for you.


[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  

×