如何从批处理文件中删除整个进程

时间:2015-11-20 19:47:26

标签: windows batch-file autohotkey autoit

我希望在finsihes之后杀死整个过程。我遇到的问题是,我不知道这个过程需要多长时间。可能需要2分钟,或者可能需要1.5小时才能完成。完成后,它弹出两个窗口,我必须单击“确定”。由于我想自动化该过程,我想完全终止该过程,以便它执行.bat文件中的下一步。

这是我到目前为止在.bat文件中所获得的内容。 AutoIT和AHK解决方案也很乐意接受。请注意***主应用程序窗口和弹出窗口的名称与“AutoMe”相同。

@echo off
:: this is the long running process
am -a arobot
:: I was hoping this would kill the process but it just gets stuck with a
:: messagebox
taskkill /F /IM am.exe
:: Next step to perform
sqlldr XXXXXX
pause

2 个答案:

答案 0 :(得分:1)

这是两个AutoIt解决方案。

如果您在杀死该过程之前不需要单击两个okay按钮。

While 1
    Sleep(250)
    If WinExists("Title of the window with the OK button") Then ExitLoop
WEnd

;Close process. Make sure that am.exe is the process name.
ProcessClose("am.exe")

如果您需要在杀死该过程之前单击两个okay按钮。

While 1
    Sleep(250)
    If WinExists("Title of the window with the OK button") Then ExitLoop
WEnd

$hWnd = WinGetHandle("Title of the window with the OK button")
WinActivate($hWnd)
WinWaitActive($hWnd)
ControlClick("My Window", "", "[CLASS:Button; TEXT:OK; INSTANCE:1]") ;<<<check to make sure you have the right button control

WinWait("title of second window")
$hWnd = WinGetHandle("title of second window")
WinActivate($hWnd)
WinWaitActive($hWnd)
ControlClick("My Window", "", "[CLASS:Button; TEXT:OK; INSTANCE:1]") ;<<<check to make sure you have the right button control

;Close process. Make sure that am.exe is the process name.
ProcessClose("am.exe")

当弹出窗口与主窗口同名时,您可以在该窗口中查找ok按钮控件或任何其他控件,而不是窗口标题。

While 1
    Sleep(250)
    If ControlCommand("win title", "", "[CLASS:Button; TEXT:OK; INSTANCE:1]", "IsVisible", "") = 1 Then ExitLoop
WEnd

另一种选择是检查窗口句柄。当您使用WinGetHandle并且有两个具有相同名称的窗口时,它将获得最近活动窗口的句柄。在您的情况下,您可以使用此功能查看弹出窗口何时出现。

$hWnd = WinGetHandle("Window title")

While 1
    Sleep(250)
    If $hWnd <> WinGetHandle("Window title") Then ExitLoop
WEnd

您可以使用AutoIt Window Information Tool查找控件和窗口标题。

答案 1 :(得分:0)

在后台启动该过程并等待具有指定标题Some Window Title的窗口:

@echo off
start "" /b am -a arobot
:wait
    timeout 1 >nul
    for /f "tokens=2" %%a in ('
        tasklist /fi "windowtitle eq Some Window Title" /fo list ^| find "PID:"
    ') do (
        taskkill /f /pid %%a
        goto next
    )
    goto wait

:next
sqlldr XXXXXX
pause