Jump to content

AutoITX with Visual Basic 2008 Express


Recommended Posts

I'm writing a program with Visual Basic 2008 Express edition and needed to use the AutoItX3 dll for one small section. In the event an authentication window appears when I access the external application, I'm using AutoItX to input the appropriate password and click OK. My code is:

Dim cAutoITX As New AutoItX3Lib.AutoItX3

cAutoITX.Opt("WinWaitDelay", 100)

cAutoITX.Opt("WinTitleMatchMode", 2)

If cAutoITX.WinExists("<Window Title>", "") Then

cAutoITX.ControlSetText("<Window Title>", "", 10810, "<Password>")

cAutoITX.ControlClick("<Window Title>", "", 1)

End If

If the window does appear, everthing works fines. However, if I'm accessing a version of the application that doesn't show this additional window, the code just hangs on the WinExists command. No errors are given, the compiler just shows that it is still executing this command. I'm working from a Windows XP 32 bit machine.

Link to comment
Share on other sites

I'm writing a program with Visual Basic 2008 Express edition and needed to use the AutoItX3 dll for one small section. In the event an authentication window appears when I access the external application, I'm using AutoItX to input the appropriate password and click OK. My code is:

Dim cAutoITX As New AutoItX3Lib.AutoItX3

cAutoITX.Opt("WinWaitDelay", 100)

cAutoITX.Opt("WinTitleMatchMode", 2)

If cAutoITX.WinExists("<Window Title>", "") Then

cAutoITX.ControlSetText("<Window Title>", "", 10810, "<Password>")

cAutoITX.ControlClick("<Window Title>", "", 1)

End If

If the window does appear, everthing works fines. However, if I'm accessing a version of the application that doesn't show this additional window, the code just hangs on the WinExists command. No errors are given, the compiler just shows that it is still executing this command. I'm working from a Windows XP 32 bit machine.

The problem is because it's waiting for the window I think. Try something like

Dim cAutoITX As New AutoItX3Lib.AutoItX3

               cAutoITX.Opt("WinWaitDelay", 100)
               cAutoITX.Opt("WinTitleMatchMode", 2)

               If cAutoITX.WinExists("<Window Title>", "") Then
                   cAutoITX.ControlSetText("<Window Title>", "", 10810, "<Password>")
                   cAutoITX.ControlClick("<Window Title>", "", 1)
              Else
                   ExitLoop
               End If
Link to comment
Share on other sites

The problem is because it's waiting for the window I think. Try something like

Dim cAutoITX As New AutoItX3Lib.AutoItX3

               cAutoITX.Opt("WinWaitDelay", 100)
               cAutoITX.Opt("WinTitleMatchMode", 2)

               If cAutoITX.WinExists("<Window Title>", "") Then
                   cAutoITX.ControlSetText("<Window Title>", "", 10810, "<Password>")
                   cAutoITX.ControlClick("<Window Title>", "", 1)
              Else
                   ExitLoop
               End If

Thanks for the quick reply. ExitLoop is an AutoIT command that isn't part of the AutoItX dll. Based on the AutoIT help file, WinExists isn't supposed to wait for the window, it just shows that it returns a 1 for success and 0 for failure. As a test, I've tried doing:

intValue = cAutoITX.WinExists("<Window Title>", "")

to retrieve the 0 or 1, but I still get the same result where it just hangs on this line with no error.

Link to comment
Share on other sites

Has anyone else encountered this or figured out how to make this work? If the window does exist, AutoItX code runs without a hitch, but it appears the WinExists function cannot return to the thread when the window does not exist. I ended up having to recreate the WinExists function in VB.Net.

Link to comment
Share on other sites

I wrote this simple function to check for a window by it's full name.

Private Declare Auto Function FindWindow Lib "user32" ( _

ByVal lpClassName As String, _

ByVal lpWindowName As String) As IntPtr

Public Function WinExists(ByVal strWindowName As String)

Dim phWnd As IntPtr

Dim winIntPtr As New IntPtr(0)

phWnd = FindWindow(Nothing, strWindowName)

If phWnd.Equals(winIntPtr) Then

Return False

Else

Return True

End If

End Function

I wrote several variations of a function to perform WinExists by partial name. Ironically, I can produce the same problem that AutoItX's WinExists demonstrates when I make API calls to either GetWindowText or using a SendMessage WM_GETTEXT. I would like to know if anyone else has run into this. Whichever of the three methods are called, the compiler gets hung when the window doesn't exist. If I pause during debugging, the line will become green and this message is displayed: "This is the next statement to execute when this thread returns from the current function."

Link to comment
Share on other sites

I haven't looked in to this yet, but at first glance I will suggest a work around: you might try wrapping this in an If statement which checks if the number of windows has increased. If it hasn't, then you can be pretty sure there was no pop-up, because there is such a small time frame for a different window to appear.

Edited by maxlarue
Link to comment
Share on other sites

Im thinking that you can set a sleep period in which you think the window should have enough time to pop up, without setting up too much of a delay that it annoys your user, and then if the window doesnt exist, then assume that it wont come up and continue. Also, you can see if you can find any other differences in the versions of the apps besides the window appearing or not appearing, and then use that feature to distinguish before hand whether or not the window will pop up.

E.G.: version 1 has a window that says ...... version 1. And you know that version 1 does NOT have the window, U can say, (i dont know the exact function, but)

$ WinText = WinGetText("APPLICATION")
 $stringFound = searchTextForGivenString($WinText, "Version 1"); <---boolean variable. (self-explanatory Pseudofunction)
if ($stringFound) then; continue with your winexist code
Else
     ;Dont!

Hope this works

--------Props to the 17 year old. ME ;)

Link to comment
Share on other sites

  • 2 years later...

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...