Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何在批处理文件中完成整个进程后终止它_Windows_Batch File_Autohotkey_Autoit - Fatal编程技术网

Windows 如何在批处理文件中完成整个进程后终止它

Windows 如何在批处理文件中完成整个进程后终止它,windows,batch-file,autohotkey,autoit,Windows,Batch File,Autohotkey,Autoit,我想在整个过程结束后终止它。我的问题是,我不知道这个过程需要多长时间。可能需要2分钟或1.5小时才能完成。完成后,它会弹出两个窗口,我必须单击“确定”才能打开。因为我想自动化这个过程,所以我想完全终止这个过程,以便它在.bat文件中执行下一步 这是我在下面的.bat文件中得到的。AutoIT和AHK解决方案也欣然接受。请注意***主应用程序窗口和弹出窗口具有相同的名称,即“自动” 在后台启动该过程,并等待具有指定标题的窗口Some window title: @echo关闭 启动“”/b am-

我想在整个过程结束后终止它。我的问题是,我不知道这个过程需要多长时间。可能需要2分钟或1.5小时才能完成。完成后,它会弹出两个窗口,我必须单击“确定”才能打开。因为我想自动化这个过程,所以我想完全终止这个过程,以便它在.bat文件中执行下一步

这是我在下面的.bat文件中得到的。AutoIT和AHK解决方案也欣然接受。请注意***主应用程序窗口和弹出窗口具有相同的名称,即“自动”


在后台启动该过程,并等待具有指定标题的窗口
Some window title

@echo关闭
启动“”/b am-a arobot
:等等
超时1>nul
对于/f“令牌=2”%%a,在('
任务列表/fi“窗口标题eq某些窗口标题”/fo列表^ |查找“PID:”
""做"(
taskkill/f/pid%%a
转到下一个
)
等一下
:下一个
sqlldr XXXXXX
暂停

这里有两个AutoIt解决方案

如果您不需要在终止进程之前单击两个OK按钮

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")
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 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")
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")
另一种选择是检查窗口句柄。当您使用Wingthandle并且有两个同名窗口时,它将获得最近活动窗口的句柄。在您的情况下,您可以使用此功能查看弹出窗口何时出现

$hWnd = WinGetHandle("Window title")

While 1
    Sleep(250)
    If $hWnd <> WinGetHandle("Window title") Then ExitLoop
WEnd
$hWnd=wingthandle(“窗口标题”)
而1
睡眠(250)
如果$hWnd Wingthandle(“窗口标题”),则退出
温德

您可以使用查找控件和窗口标题。

实际上不起作用。由于该任务处于活动状态且在弹出“ok”提示时处于阻塞状态,因此您的taskkill将永远无法到达。您必须将其作为单独的作业运行,并以某种方式监视这些弹出窗口。只要尝试一下,taskkill似乎在启动之前就扼杀了整个过程。它只是跳过am-a机器人,进入下一个任务。你没有告诉我程序总是显示一个窗口,并且它的标题没有改变,所以它当然被杀死了。我想要保持批处理语言限制,您需要一个类似(CLI版本
nircmdc
)的实用程序。