应用程序 windows 闪烁而不是激活

Application windows flash instead of becoming active

我的 AutoIt 脚本根据传递的参数激活 Dynamics AX 应用程序。我打开并最小化了各种 AX 应用程序。

大多数情况下,正确的应用程序(基于 $partition 参数)会被激活并处于焦点状态,因此脚本会继续运行。但有时(可能是 3 个中的 1 个)应用程序只是在任务栏中闪烁并且没有激活,因此脚本无法继续。

一个 .Net 应用程序通过 Windows 2012 服务器上的参数调用我的 AutoIt 脚本:

#include <MsgBoxConstants.au3>
#include <GuiListView.au3>

Local $partition = $CmdLine[1]
Local $axc       = $CmdLine[2]
Local $brand     = $CmdLine[3]
Local $sTerm     = $CmdLine[4]

;command line example
;GoToCustomerServicePage.exe "msl" "MSLtd" "MSUK" "LS14 6PN"

SearchForCust($partition, $axc, $brand, $sTerm)

Func SearchForCust($partition, $axc, $brand, $sTerm)
    ;Set the Title match mode
    Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

    Local $custSer = StringUpper($partition) & "/Omnica MCR/Common/Customer Service"
    Local $exePath = "C:\Program Files (x86)\Microsoft Dynamics AX\Client\Bin\Ax32.exe \zoom-sql2\axcshare\" & $axc & ".axc"
    Local $axTitle = "[TITLE:" & $partition & "; CLASS:AxMainFrame]"

    ; Wait 10 seconds for the window to appear.
    WinWait($axTitle, "", 10)

    ; Test if the window exists and display the results.
    If WinExists($axTitle, "") Then
    Else
        Run($exePath)
        WinWait($axTitle, "", 20)
    EndIf

    Local $hWnd = WinGetHandle($axTitle)

    WinActivate($hWnd)

    If WinActive($hWnd) Then
    Else
        WinWaitActive($hWnd, 5)
    EndIf

    ; Simulate clicking on the address bar
    Send("{F11}")

    ;Enter this into the address bar
    Send($custSer)
    Send("{ENTER}")

    ;Set the Brand
    Send($brand)
    Send("{ENTER}")

    ;send search term
    If $sTerm <> "unavailable" Then
        Send($sTerm)
        Send("{ENTER}")
    EndIf

EndFunc

试试这个:

; Test if the window exists and display the results.
If WinExists($axTitle, "") Then
    ; add here: check if the window is active - activate if not
    If Not WinActive($axTitle) Then WinActivate($axTitle)
Else
    Run($exePath)
    WinWait($axTitle, "", 20)
EndIf