Stop Music Once Playing

前端 未结 2 2022
长情又很酷
长情又很酷 2021-01-26 03:31

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         


        
相关标签:
2条回答
  • 2021-01-26 04:27

    I'd use /T switch (Tree kill): terminates the specified process and any child processes which were started by it.

    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  
        )
    

    Note taskkill command is echoed merely... Remove echo when debugged.

    0 讨论(0)
  • 2021-01-26 04:32

    This work for me, and is only one line.

    Taskkill /IM "wscript.exe" /F>nul 2>&1
    
    0 讨论(0)
提交回复
热议问题