关闭从DOS命令行中运行的应用程序 [英] Close a running application from DOS command line

查看:215
本文介绍了关闭从DOS命令行中运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

start命令可以在这样的批处理文件启动记事本等应用程序:

The start command can launch an application like notepad in a batch file like this:

start notepad
start "my love.mp3"

但我怎么在命令行关闭正在运行的应用?我发现 TASKKILL 在我的搜索,但我不认为这是正确的命令,因为它不工作—它说没有这样的文件

But how do I close the running application from the command line? I found taskkill in my searches but I don't think that is the right command because it's not working—it says no such file.

我如何关闭与启动的应用程序启动

推荐答案

TASKKILL是正确的。但是,你必须杀死的过程中播放文件,而不是文件本身。已注册的处理MP3文件从命令提示符搞清楚将是一个有点棘手。

Taskkill is correct. But you must kill the process playing the file, not the file itself. Figuring out the registered handler for mp3 files from a command prompt will be a bit tricky.

如果你知道它,那么你可以杀死该进程。

If you know it then you can kill that process.

下面是计算出的注册申请mp3文件并杀死任务的脚本:

Here's a script that figures out the registered application for mp3 files and kills the task:

@echo off
if not .%1==. goto show

:createtemp
set tempfile="%temp%\temp-%random%-%time:~6,5%.bat"
if exist %tempfile% goto :createtemp

reg query HKEY_CLASSES_ROOT\mp3file\shell\play\command\ > %tempfile%

for /F "skip=4 delims=> tokens=2 usebackq" %%e in (`type %tempfile%`) do call %0 %%e

del %tempfile% > nul
set tempfile=
set handler=
set teststring=
set offset=
set cmd=
goto end

:show
set handler=%2
set handler=%handler:~1,-1%
set /A offset=-1

:loop
set cmd=set teststring=%%handler:~%offset%%%
echo %cmd% > %tempfile%
call %tempfile%
if %teststring:~0,1%==\ goto complete
set /A offset=offset-1
goto loop

:complete
set /A offset=offset+1
set cmd=set handler=%%handler:~%offset%%%
echo %cmd% > %tempfile%
call %tempfile%
taskkill /IM %handler% > nul

:end

如果您保存此为 killmp3.bat 什么的,你可以调用它,当你想要的。当然要注意,如果该程序已经运行,做别的东西,它会被关闭反正

If you save this as killmp3.bat or something, you can call it when you want. Of course be aware that if the program was already running, doing something else, that it will be closed anyway.

请注意,这在很大程度上取决于在注册表中的条目有双引号里面的可执行文件的路径。如果你没有这样的,有空间的可执行文件名,它就会失败。

Note that this depends heavily on the entry in the registry to have the executable path inside double quotes. If you don't have that and there are spaces in the executable name, it will fail.

您可以概括我的技术能在文件扩展名(通过如 .MP3 ,你可以查找在注册表中找到类名 mp3file ,然后从那里找到的处理器。

You could generalize my technique to be able to pass in the file extension (such as .mp3, which you could look up in the registry to find the class name mp3file and then find the handler from there.

一个更通用的解决方案,将你开始文件的名称,并计算出从它延伸理论上是可能的,但困难得多。在记事本的情况下,你必须弄清楚,是通过搜索所有可执行文件的路径等内容。

A more generic solution that takes the name of the file you started and figures out the extension from it is theoretically possible but a lot more difficult. In the case of notepad you have to figure out what that is by searching the path for all executable files, etc.

如果你创建了你可以开始在极短的MP3文件,这可能是简单。根据程序,它可能会停止播放当前文件,并切换到新的,这将结束几乎立即有效地停止播放。

This might be simpler if you created an extremely short mp3 file that you could start. Depending on the program, it might stop playing the current file and switch to the new one, which would end almost instantly and effectively stop playback.

这篇关于关闭从DOS命令行中运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆