无法在批处理文件中停止VBScript

时间:2019-10-21 12:15:09

标签: batch-file vbscript

我正试图阻止某个音乐文件在后台播放,因此我可以开始播放另一个音乐文件,但是我找不到解决方案。这是我正在使用的代码:

set "file=airraid.wav"
( 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 21
  echo loop
  echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /B cscript //nologo sound.vbs

1 个答案:

答案 0 :(得分:0)

您可以使用命令cscript终止Taskkil进程来停止音乐

这里是一个示例:

@echo off
Title Playing Music in the background and change it
Set "URL_Music1=http://94.23.221.158:9197/stream"
Set "URL_Music2=http://www.chocradios.ch/djbuzzradio_windows.mp3.asx"
Rem :: Here we start cscript minimized to play music with URL as argument
Call :Play "%URL_Music1%"
Tracert.exe www.codereview.stackexchange.com
Call :StopMusic
::Rem We play another music
Call :Play "%URL_Music2%"
Tracert.exe www.google.com
Call :StopMusic
Pause & Exit
::**************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo    Dim Sound
echo    Set Sound = CreateObject("WMPlayer.OCX"^)
echo    Sound.URL = URL
echo    Sound.settings.volume = 100
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
echo End Sub
)>"%Temp%\%~n0.vbs"
Start "Play Music" /Min cscript.exe //nologo "%Temp%\%~n0.vbs"
exit /b
::**************************************************************
:StopMusic
Taskkill /F /IM "cscript.exe">nul 2>&1
Exit /b 
::**************************************************************