从 DOS 命令行关闭正在运行的应用程序
start 命令可以在批处理文件中启动像记事本这样的应用程序,如下所示:
start notepad
start "my love.mp3"
但是如何从命令行关闭正在运行的应用程序?我在搜索中找到了 taskkill
但我认为这不是正确的命令,因为它不起作用 - 它说没有这样的文件。
如何关闭使用 start
启动的应用程序?
The start command can launch an application like notepad in a batch file like this:
start notepad
start "my love.mp3"
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.
How do I close an application launched with start
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
输入
taskkill /?
查看语法和一些示例。您想要做的是使用您想要终止的程序的名称传递/IM
参数。例如:将杀死notepad.exe。
将杀死所有以“note”开头的进程。
Enter
taskkill /?
for the syntax and some examples. What you want to do is pass the/IM
argument using the name of the program you want to kill. For example:will kill notepad.exe.
will kill all processes beginning with "note".
Taskkill 是正确的。但您必须终止播放该文件的进程,而不是文件本身。从命令提示符中找出 mp3 文件的注册处理程序会有点棘手。
如果您知道,那么您可以杀死该进程。
下面是一个脚本,用于找出 mp3 文件的已注册应用程序并终止该任务:
如果将其保存为
killmp3.bat
或其他内容,则可以在需要时调用它。当然,请注意,如果程序已经在运行,正在执行其他操作,则无论如何它都会被关闭。请注意,这在很大程度上取决于注册表中的条目是否将可执行路径放在双引号内。如果没有它并且可执行文件名称中有空格,它将失败。
您可以将我的技术推广到能够传递文件扩展名(例如
.mp3
),您可以在注册表中查找类名mp3file
,然后从那里找到一个更通用的解决方案,它获取您启动的文件的名称并从中找出扩展名,这在理论上是可能的,但对于
notepad
来说,您必须这样做。通过搜索所有可执行文件的路径找出那是什么, 如果您创建了一个可以启动的极短的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.
Here's a script that figures out the registered application for mp3 files and kills the task:
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.
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 namemp3file
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.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.