Inconsistent Window detection possible script error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SpencerH
Posts: 20
Joined: 18 Jan 2018, 16:04

Inconsistent Window detection possible script error

18 Jan 2018, 16:31

Below you can see my script which I think I have messed up because I can detect the window and get the desired behavior most of the time but not all of the time. Also when QuickBooks detects another running window it will automatically switch to that window. I just wasn't sure of what I am doing wrong here.

If it matters I am working on 2008 Windows Server 64x processor and install. version 1.1.27.05 (06 would not download as it kept telling me there was a virus but not giving me an option to keep the file)
I'm getting the window info using the Window Spy tool

Code: Select all

IfWinExist, ahk_exe qbw32.exe,
{
    WinActivate
    WinMaximize
    MsgBox It found the Open Window!
}
else
{
    Run, "C:\Program Files (x86)\Intuit\QuickBooks Enterprise Solutions 16.0\QBW32EnterpriseContractor.exe"
    WinWait, ahk_exe qbw32.exe, , 10
        if ErrorLevel
            {
                MsgBox WinWait Timed out.
                return
            }
        else
            WinMaximize
}
SpencerH
Posts: 20
Joined: 18 Jan 2018, 16:04

Re: Inconsistent Window detection possible script error

19 Jan 2018, 11:25

I wasn't sure if this was the issue I am running into: https://autohotkey.com/docs/Tutorial.htm#s13

So I changed the code to remove the if condition nested in the else.

My script seemed to be a little more consistent but seems to skip ahead.

So now i have this:

Code: Select all

IfWinExist, ahk_exe qbw32.exe,
{
    WinActivate
    WinMaximize
    MsgBox It found the Open Window!
}
else
{
    RunWait, QBW32EnterpriseContractor.exe, C:\Program Files (x86)\Intuit\QuickBooks Enterprise Solutions 16.0, max
    ; WinWait, ahk_exe qbw32.exe, , 10
    WinActivate
    ; WinMaximize
}
MsgBox Something Worked!
And I am trying to figure out why I can see "Something Worked!" long before quickbooks has finished opening.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Inconsistent Window detection possible script error

20 Jan 2018, 09:28

SpencerH wrote:I can detect the window and get the desired behavior most of the time but not all of the time.
It would help if you elaborate on this.
SpencerH wrote:I am trying to figure out why I can see "Something Worked!" long before quickbooks has finished opening.
You start QBW32EnterpriseContractor.exe, which likely starts qbw32.exe and then exits continuing from RunWait.
I think your first script looks better though.
SpencerH
Posts: 20
Joined: 18 Jan 2018, 16:04

Re: Inconsistent Window detection possible script error

21 Jan 2018, 19:07

In general, I am trying to make this script more robust so that if something fails or "changes" it can continue. After posting on the discord and seeing I could use a loop for ImageSearch, it makes me think I could use a bunch of conditional ImageSearch expressions to keep things on track is this flawed?
SpencerH
Posts: 20
Joined: 18 Jan 2018, 16:04

Re: Inconsistent Window detection possible script error

22 Jan 2018, 15:11

I'm taking this part by part now trying to work it out. Originally I had this:

Code: Select all

SetTitleMatchMode, 2
IfWinExist, QuickBooks Enterprise Solutions: Contractor 16.0, , , 
    {
        WinActivate
        WinMaximize
        MsgBox It found the Open Window!
    }
IfWinExist, , An empty QuickBooks window already exists, ,
    {
        WinActivate
        send {enter}
        MsgBox I closed the Message for you
    }
IfWinExist, QuickBooks Login, , ,
    {
        WinActivate
        MouseClick, Left, 210, 228
        MsgBox I exited the Login Screen
}
    
else
{

    {
        RunWait, QBW32EnterpriseContractor.exe, C:\Program Files (x86)\Intuit\QuickBooks Enterprise Solutions 16.0, max
        WinWait, Intuit QuickBooks Enterprise Solutions: Contractor 16.0, , 10,
        sleep 100
        if ErrorLevel
        {
            IfWinExist, QuickBooks Login, , ,
            ; GoSub, %OpeningCompanyFile%
            MsgBox It was the other version
            MouseClick, Left, 210, 228
        }
        return
    }
}
But I found that Else always executed sometimes skipping over all of the IfWinExist so I tried this:

Code: Select all

SetTitleMatchMode, 2
if 
{
    IfWinExist, QuickBooks Enterprise Solutions: Contractor 16.0, , , 
    {
        WinActivate
        WinMaximize
        MsgBox It found the Open Window!
    }
    IfWinExist, , An empty QuickBooks window already exists, ,
    {
        WinActivate
        send {enter}
        MsgBox I closed the Message for you
    }
    IfWinExist, QuickBooks Login, , ,
    {
        WinActivate
        MouseClick, Left, 210, 228
        MsgBox I exited the Login Screen
    }
}    
else
{

    {
        RunWait, QBW32EnterpriseContractor.exe, C:\Program Files (x86)\Intuit\QuickBooks Enterprise Solutions 16.0, max
        WinWait, Intuit QuickBooks Enterprise Solutions: Contractor 16.0, , 10,
        sleep 100
        if ErrorLevel
        {
            IfWinExist, QuickBooks Login, , ,
            ; GoSub, %OpeningCompanyFile%
            MsgBox It was the other version
            MouseClick, Left, 210, 228
        }
        return
    }
}
This doesn't work and I know it is because I have no expression after the If, but I have no clue what to put there to make this work or possibly I am headed in the wrong direction entirely. So my question is either:

How do I make this work as is?
OR
Where should I be looking instead (what documentation should I read)?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, CrowexBR, Rohwedder and 199 guests