Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/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
Batch file 批处理文件:停止一个进程_Batch File - Fatal编程技术网

Batch file 批处理文件:停止一个进程

Batch file 批处理文件:停止一个进程,batch-file,Batch File,我有一个调用程序的批处理文件,但我想在h小时后停止这个程序 例如,我的批将有此代码 @echo off ........ ....... ............ call myprogram.exe 有没有办法在h小时后停止myprogram.exe?尝试在批处理文件中使用: taskkill /IM myprogram.exe 至于在程序运行h小时后停止它,我不知道如何调用它。如果您有一个特定的时间想要停止它,您可以使用像Windows计划任务这样简单的方法 否则,您可以尝试使用服务管理

我有一个调用程序的批处理文件,但我想在h小时后停止这个程序 例如,我的批将有此代码

@echo off
........
.......
............
call myprogram.exe
有没有办法在h小时后停止myprogram.exe?

尝试在批处理文件中使用:

taskkill /IM myprogram.exe
至于在程序运行h小时后停止它,我不知道如何调用它。如果您有一个特定的时间想要停止它,您可以使用像Windows计划任务这样简单的方法

否则,您可以尝试使用服务管理应用程序,如将myprogram.exe设置为Windows服务,并将其安排在h小时后关闭。不幸的是,FireDaemon不是免费的,但它肯定能完成任务。

尝试在批处理文件中使用:

taskkill /IM myprogram.exe
REM delay for 36000 seconds (10 hours)
FOR /l %%a in (36000,-1,1) do (Echo closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
REM delete the program using it's PID
FOR /f "tokens=2" %a in ('tasklist ^| find "notepad.exe"') do tskill %a
至于在程序运行h小时后停止它,我不知道如何调用它。如果您有一个特定的时间想要停止它,您可以使用像Windows计划任务这样简单的方法

否则,您可以尝试使用服务管理应用程序,如将myprogram.exe设置为Windows服务,并将其安排在h小时后关闭。不幸的是,FireDaemon不是免费的,但它肯定能完成任务

REM delay for 36000 seconds (10 hours)
FOR /l %%a in (36000,-1,1) do (Echo closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
REM delete the program using it's PID
FOR /f "tokens=2" %a in ('tasklist ^| find "notepad.exe"') do tskill %a
使用ping意味着它可以在XP、Vista和7中工作(我假设Win8)


使用ping意味着它可以在XP、Vista和7中工作(我假设Win 8)

如果您使用的是Vista或更高版本,这将更容易

start myprogram.exe
timeout /t 3600
taskkill /im myprogram.exe /f

只需将
3600
替换为您的时间延迟(以秒为单位)。

如果您使用的是Vista或更高版本,这会容易得多

start myprogram.exe
timeout /t 3600
taskkill /im myprogram.exe /f

只需将
3600
替换为您的时间延迟(以秒为单位)。

这不起作用,例如,如果我调用myprogram.exe,它将不会在此之后执行其他命令,直到myprogram.exe停止使用
start myprogram.exe
-这将在程序启动后继续执行批处理文件。实际上,您必须指定
/W
/WAIT
,使其暂停,直到程序完成为止。例如,如果我调用myprogram.exe,它将在此之后不执行其他命令,直到myprogram.exe停止使用
start myprogram.exe
-这将在程序启动后继续执行批处理文件。实际上,您必须指定
/W
/WAIT
使其暂停,直到程序完成