运行 cscript 命令时无法使用 bat 文件
Can't use bat file when running cscript command
我正在制作一个基于 cmd 文本的游戏,运行 背景音乐,但每次我 运行 使用 cscript 命令时,它不会进入菜单屏幕,但如果我运行用启动命令,我退出文件后它也不会停止。这是命令:
@echo off
set "file=musicfilename.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
cscript //nologo sound.vbs
"musicfilename.mp3"是mp3文件名
基于@Stephan的解决方案你可以开始cscript
最小化
start /min cscript //nologo sound.vbs
我为你制作了这样一个有趣的脚本:
@echo off
Mode 64,35 & color 0A
Title Play Music
Rem :: You can change easily your custom URL on this variable URL_Music
Set "URL_Music=http://94.23.221.158:9197/stream"
Rem :: Here we start cscript minimized to play music with URL as argument
Call :Play "%URL_Music%"
:::
::: __ __ _______ ___ ___ _______
::: | | | || || | | | | |
::: | |_| || ___|| | | | | _ |
::: | || |___ | | | | | | | |
::: | || ___|| |___ | |___ | |_| |
::: | _ || |___ | || || |
::: |__| |__||_______||_______||_______||_______|
:::
::: _ _,---._
::: ,-',' `-.___
::: /-;' `._
::: /\/ ._ _,'o \
::: ( /\ _,--'\,','"`. )
::: |\ ,'o \' //\
::: | \ / ,--'""`-.
::: : \_ _/ ,-' `-._
::: \ `--' / )
::: `. \`._ ,' ________,','
::: .--` ,' ,--` __\___,;'
::: \`.,-- ,' ,`_)--' /`.,'
::: \( ; | | ) (`-/
::: `--'| |) |-/
::: | | | | |
::: | | |,.,-. | |_
::: | `./ / )---` )
::: _| / ,', ,-'
::: ,'|_( /-<._,' |--,
::: | `--'---. \/ \
::: | / \ /\ \
::: ,-^---._ | \ / \ \
::: ,-' \----' \/ \--`.
::: / \ \ \
:::
::**************************************************************
for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A
pause>nul & 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
::**************************************************************
这是我用纯 vbscript 制作的另一个解决方案:
Playing music in the background while another task is running
我正在制作一个基于 cmd 文本的游戏,运行 背景音乐,但每次我 运行 使用 cscript 命令时,它不会进入菜单屏幕,但如果我运行用启动命令,我退出文件后它也不会停止。这是命令:
@echo off
set "file=musicfilename.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
cscript //nologo sound.vbs
"musicfilename.mp3"是mp3文件名
基于@Stephan的解决方案你可以开始cscript
最小化
start /min cscript //nologo sound.vbs
我为你制作了这样一个有趣的脚本:
@echo off
Mode 64,35 & color 0A
Title Play Music
Rem :: You can change easily your custom URL on this variable URL_Music
Set "URL_Music=http://94.23.221.158:9197/stream"
Rem :: Here we start cscript minimized to play music with URL as argument
Call :Play "%URL_Music%"
:::
::: __ __ _______ ___ ___ _______
::: | | | || || | | | | |
::: | |_| || ___|| | | | | _ |
::: | || |___ | | | | | | | |
::: | || ___|| |___ | |___ | |_| |
::: | _ || |___ | || || |
::: |__| |__||_______||_______||_______||_______|
:::
::: _ _,---._
::: ,-',' `-.___
::: /-;' `._
::: /\/ ._ _,'o \
::: ( /\ _,--'\,','"`. )
::: |\ ,'o \' //\
::: | \ / ,--'""`-.
::: : \_ _/ ,-' `-._
::: \ `--' / )
::: `. \`._ ,' ________,','
::: .--` ,' ,--` __\___,;'
::: \`.,-- ,' ,`_)--' /`.,'
::: \( ; | | ) (`-/
::: `--'| |) |-/
::: | | | | |
::: | | |,.,-. | |_
::: | `./ / )---` )
::: _| / ,', ,-'
::: ,'|_( /-<._,' |--,
::: | `--'---. \/ \
::: | / \ /\ \
::: ,-^---._ | \ / \ \
::: ,-' \----' \/ \--`.
::: / \ \ \
:::
::**************************************************************
for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A
pause>nul & 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
::**************************************************************
这是我用纯 vbscript 制作的另一个解决方案:
Playing music in the background while another task is running