播放后停止音乐 [英] Stop Music Once Playing
问题描述
我试图让一首歌在Windows的背景下播放,经过一番看后,我发现了这一点:
I am trying to get a song to play in the background of Windows, after a little looking I found this:
@echo off
set file=RRLJ.mp3
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%file%"
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs
这对于开始播放歌曲非常有效,但是我无法从.bat
文件中停止它.我发现简而言之的唯一方法是打开任务管理器并从进程中关闭它.
This works well for starting the song but I have no way of stopping it from a .bat
file. The only way I found to cut it short is to open task manager and close it from the processes.
我尝试过:
taskkill /im wscript.exe
但是我一直在窗口中看到一些信息: 成功:将终止信号发送到具有PID 185448的进程"wscript.exe" 但音乐会继续播放,直到我用任务管理器手动结束
But I keep getting something in the window saying: Success: Sent termination sidnal to the process "wscript.exe" with PID 185448 but the music continues to play until I manually end it with task manager
推荐答案
我将使用/T
开关(杀死树):终止指定的进程以及由其启动的所有子进程.
I'd use /T
switch (Tree kill): terminates the specified process and any child processes which were started by it.
这里是一个脚本,用于找到ProcessID
以仅使用PID
终止完全需要的过程:
Here is a script to find ProcessID
to terminate exactly needed process only using PID
:
@ECHO OFF >NUL
for /F "usebackq tokens=*" %%G in (
`wmic process where "CommandLine like '%%sound.vbs%%' AND Caption like '%%script.exe%%'" get ProcessID/value ^|find /I "="`
) do (
rem echo %%G
for /F "tokens=2 delims==" %%H in ("%%~G") do echo taskkill /T /F /PID %%H
)
注意,仅回显taskkill
命令...在调试时删除echo
.
Note taskkill
command is echoed merely... Remove echo
when debugged.
这篇关于播放后停止音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!