Jump to content

WinWait() not working with AutoIt3.exe v3.3.6.1


Witto
 Share

Recommended Posts

Dear all,

I found a script to add a certificate to Windows with CertMgr.exe.

http://www.msfn.org/board/topic/29123-trusted-publishers-certificates/

I adapted it to my needs.

It works with AutoIt3.exe v3.2.2.0.

It does not work with AutoIt3.exe v3.3.6.1, the latest version.

The "Security Warning" window appears, but the WinWait() function does not do it's job when I use v3.3.6.1.

Does somebody know why?

; AutoIT Parameters 
#NoTrayIcon 
AutoItSetOption("MustDeclareVars", 1) 
AutoItSetOption("RunErrorsFatal", 0) 

; Operational Constants 
const $WinTitle = "Security Warning" 
const $WinText = "You are about to install a certificate" 
const $WinCtrl = 6 
const $FileName = '"' & @ScriptDir & '\MyCert.cer"' 
 
; Variables 
Dim $r 
Dim $e 
 
; Program Function 
$e = 0 
Run(@ScriptDir & "\CertMgr.exe -add -c " & $FileName & " -s ROOT") 

If @error = 0 Then 
        $r = WinWait($WinTitle, $WinText, 30) 
        If $r = 1 Then 
                WinActivate($WinTitle, $WinText) 
                ControlClick($WinTitle, $WinText, $WinCtrl, "left", 1) 
        Else 
                $e = 1 
        EndIf 
Else 
        $e = 1 
EndIf 
Exit($e)
Edited by Witto
Link to comment
Share on other sites

  • Moderators

Witto,

WinWait works perfectly, but you are looking for the wrong return value. :(

From the History in the Help file:

18th December, 2009 - v3.3.2.0

Added #764: Return Pid on ProcessWait() and handle on WinWait(), WinWaitActive, WinActivate(), WinActive(), WinMove() when successful.

So your $r = 1 condition will never be met. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Developers

WinWait() retuns the window handle when successfull, not a 1.

So something like this should work:

$r = WinWait($WinTitle, $WinText, 30) 
        If $r <> 0 Then 
                WinActivate($WinTitle, $WinText) 
                ControlClick($WinTitle, $WinText, $WinCtrl, "left", 1) 
        Else 
                $e = 1 
        EndIf
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Witto,

From the Help file for WinWait:

Return Value

Success: Returns handle to the requested window.

Failure: Returns 0 if timeout occurred.

In your script WinWait returns it when it has found the window (in which case $r is the handle) or if it timed out ($r = 0).

So just check for $r <> 0. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Dear Jos,

Dear Melba23,

Thanks for the reply. That makes the script working again. But I presume I can do smarter things with a return value like "0x000B0D78"?

; AutoIT Parameters 
#NoTrayIcon 
AutoItSetOption("MustDeclareVars", 1) 
AutoItSetOption("RunErrorsFatal", 0) 

; Operational Constants 
const $WinTitle = "Security Warning" 
const $WinText = "You are about to install a certificate" 
const $WinCtrl = 6 
const $FileName = '"' & @ScriptDir & '\MyCert.cer"' 
 
; Variables 
Dim $r 
Dim $e 
 
; Program Function 
$e = 0 
Run(@ScriptDir & "\CertMgr.exe -add -c " & $FileName & " -s ROOT") 

If @error = 0 Then 
        $r = WinWait($WinTitle, $WinText, 30) 
        If $r <> 0 Then 
;                MsgBox(1,"Return Value", $r, 30)
                WinActivate($WinTitle, $WinText) 
                ControlClick($WinTitle, $WinText, $WinCtrl, "left", 1) 
        Else 
                $e = 1 
        EndIf 
Else 
        $e = 1 
EndIf 
Exit($e)
Edited by Witto
Link to comment
Share on other sites

Dear Richard,

Thanks for your reply.

I have installed the latest "AutoIt Full Installation v3.3.6.1"

Thanks for your code. It seems to work. But I did not find it in the help.

Function Reference

WinWait

--------------------------------------------------------------------------------

Pauses execution of the script until the requested window exists.

WinWait ( "title" [, "text" [, timeout]] )

Parameters

title The title of the window to check. See Title special definition.

text [optional] The text of the window to check.

timeout [optional] Timeout in seconds

Return Value

Success: Returns handle to the requested window.

Failure: Returns 0 if timeout occurred.

Remarks

None.

Related

WinActive, WinExists, WinWaitActive, WinWaitClose, WinWaitNotActive, WinWaitDelay (Option), ProcessWait

Example

;Wait for the window "[CLASS:Notepad]" to exist

Run("notepad")

WinWait("[CLASS:Notepad]")

;Wait a maximum of 5 seconds for "[CLASS:Notepad]" to exist

WinWait("[CLASS:Notepad]", "", 5)

I have another question:

This works:

ControlClick($r, "", $WinCtrl, "left", 1)

This does not work:

ControlClick($r, "", $WinCtrl, "right", 1)
Edited by Witto
Link to comment
Share on other sites

A control will ignore* click-types it don't knows. *(will seems to ignore them, as it just don't knows what to do with them.)

For example. Try closing this messagebox with a right-mouse-click. You can't, and ControleClick can't either.

MsgBox(0, "MsgBox", "MsgBox")
Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

A control will ignore* click-types it don't knows. *(will seems to ignore them, as it just don't knows what to do with them.)

For example. Try closing this messagebox with a right-mouse-click. You can't, and ControleClick can't either.

MsgBox(0, "MsgBox", "MsgBox")

I see, it is the "ControlID" that defines which control button has to be clicked. "Button" is the mouse button.

In my example, this would make me click "No":

const $WinCtrl = 7
Edited by Witto
Link to comment
Share on other sites

it is the "ControlID" that defines which control button has to be clicked.

correct.

"Button" is the mouse button.

for the 'left', 'right' and 'middle', yes.

In my example, this would make me click "No":

const $WinCtrl = 7
If its a [ (yes) (no) ] gui message box. Probably. (But I don't run system related executables I don't know. So I have not seen the Gui your clicking on.)

You can however use the Au3Info tools to look a the buttons properties to see what will target it. (see: http://www.autoitscript.com/autoit3/docs/intro/controls.htm for additional information about control targeting.)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Thanks MvGulik,

If I start CertMgr.exe to install my certificate, it could be that it has been installed before.

In that case, I get a pop-up with a question if I want to delete the existing certificate. I want to answer "Yes" to that question. How could I see if the alternate window is opened first?

; AutoIT Parameters 
#NoTrayIcon 
AutoItSetOption("MustDeclareVars", 1) 
AutoItSetOption("RunErrorsFatal", 0) 

; Operational Constants 
const $WinTitle = "Security Warning" 
const $WinText = "You are about to install a certificate" 
const $WinCtrlYes = 6 
; const $WinCtrlNo = 7
const $FileName = '"' & @ScriptDir & '\MyCert.cer"' 
const $MouseBtnMain = "primary"
; const $MouseBtnMenu = "secondary"
; const $MouseBtnMiddle = "middle"

; Variables 
Dim $handle 
Dim $error 
 
; Program Function 
$error = 0 
Run(@ScriptDir & "\CertMgr.exe -add -c " & $FileName & " -s ROOT") 

; These are the text and the title of the other window that could appear first.
; How can I see which window is opened first?
; Dim $Title1 = "Root Certificate Store"
; Dim $Text1 = "Do you want to DELETE the following certificate from the Root Store?"

If @error = 0 Then 
    $handle = WinWait($WinTitle, $WinText, 30) 
    If $handle <> 0 Then 
        ; check if older version of AutoIt3 is used
        If $Handle = 1 then
            WinActivate($WinTitle, $WinText) 
            ControlClick($WinTitle, $WinText, $WinCtrlYes, "left", 1) 
        Else
            WinActivate($handle) 
            ControlClick($handle, "", $WinCtrlYes, $MouseBtnMain, 1)
        EndIf
    Else 
        $error = 1 
    EndIf 
Else 
    $error = 1 
EndIf 
Exit($error)
Edited by Witto
Link to comment
Share on other sites

I think I found a way using a loop

; AutoIT Parameters
#NoTrayIcon
AutoItSetOption("MustDeclareVars", 1)
; This option is not supported anymore since v3.2.12.0
; AutoItSetOption("RunErrorsFatal", 0)

; Operational Constants
Const $WinCtrlYes = 6
; Const $WinCtrlNo = 7
Const $FileName = '"' & @ScriptDir & '\MyCert.cer"'
Const $MouseBtnMain = "primary"
; Const $MouseBtnMenu = "secondary"
; Const $MouseBtnMiddle = "middle"

; This box appears when trying to add the certificate
Const $WinTitle0 = "Security Warning"
Const $WinText0 = "You are about to install a certificate"

; This box appears if the certificate has been installed before
Const $WinTitle1 = "Root Certificate Store"
Const $WinText1 = "Do you want to DELETE the following certificate from the Root Store?"

; Variables
Dim $handle
Dim $error
Dim $Success = 0
Dim $Counter = 0

; Program Function
Run(@ScriptDir & "\CertMgr.exe -add -c " & $FileName & " -s ROOT")

If @error = 0 Then
    Do
        ; Check if Certificate has been installed before
        $handle = WinWait($WinTitle1, $WinText1, 1)
        If $handle <> 0 Then
            If $Handle = 1 Then
                ; support for versions of AutoIt older then 3.3.2.0
                WinActivate($WinTitle1, $WinText1)
                ControlClick($WinTitle1, $WinText1, $WinCtrlYes, "left", 1)
            Else
                ; code for AutoIt v3.3.2.0 or more recent
                WinActivate($handle)
                ControlClick($handle, "", $WinCtrlYes, $MouseBtnMain, 1)
            EndIf
        EndIf
        ; Check if pop-up appears to install the certificate
        $handle = WinWait($WinTitle0, $WinText0, 1)
        If $handle <> 0 Then
            If $Handle = 1 then
                WinActivate($WinTitle0, $WinText0)
                ControlClick($WinTitle0, $WinText0, $WinCtrlYes, "left", 1)
            Else
                WinActivate($handle)
                ControlClick($handle, "", $WinCtrlYes, $MouseBtnMain, 1)
            EndIf
            $Success = 1
        EndIf
        $Counter = $Counter + 1
    Until $Success = 1 or $Counter = 30
    if $Counter = 30 Then
        $Error = 1
        exit $Error
    EndIf
Else
    $Error = 1
    Exit $Error
EndIf
Edited by Witto
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...