China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-08 15:34
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Achieve background sound playback without any player, in one line View 1,880 Replies 6
Original Poster Posted 2010-01-22 21:54 ·  中国 天津 电信
高级用户
★★★
据说是李先生
Credits 609
Posts 400
Joined 2008-04-23 15:55
18-year member
UID 116706
Gender Male
Status Offline
mshta vbscript:document.write("<bgsound src='E:\audio\曹方我是认真的.mp3' loop='-1'>")
src can be a network resource, loop is the number of plays, -1 means loop. Typed on mobile, not sure if there's any mistake.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +7 2010-01-27 08:29
┏━━━━━━┓
┃据说是李先生┃
┠──────┨
┃*ntRSS┃
┗━━━━━━┛
Floor 2 Posted 2010-01-23 15:32 ·  中国 重庆 移动
初级用户
Credits 46
Posts 39
Joined 2008-11-02 22:24
17-year member
UID 129819
Gender Male
Status Offline
Floor 3 Posted 2010-01-23 22:09 ·  中国 广东 韶关 电信
高级用户
★★★
CMD感染者
Credits 691
Posts 383
Joined 2008-05-23 00:38
18-year member
UID 119451
Gender Male
Status Offline
Not bad
But after running a few more times, the task manager adds several mshta.exe processes
Floor 4 Posted 2010-01-26 19:39 ·  中国 北京 联通
新手上路
Credits 3
Posts 2
Joined 2007-08-14 20:09
18-year member
UID 95142
Gender Male
From 北京
Status Offline
Floor 5 Posted 2010-01-26 20:01 ·  中国 河南 郑州 新密市 联通
初级用户
★★
Credits 161
Posts 56
Joined 2007-10-01 00:42
18-year member
UID 98672
Gender Male
Status Offline
Not bad! The effect is good! It's streamlined and has a good effect!

Just don't know how to close it from which level! Can only end the process!
Was it originally running in the background? There won't be a close button! Hehe!
Floor 6 Posted 2010-01-26 21:35 ·  中国 安徽 池州 电信
贫困用户
Credits 1
Posts 3
Joined 2010-01-03 21:49
16-year member
UID 157899
Gender Male
Status Offline
There is a problem of multiple processes appearing. It's quite good. Support.


Cordless DrillsMakita Cordless DrillsBosch Cordless Drillscordless drill driver
Floor 7 Posted 2010-01-27 10:08 ·  中国 北京 中电华通通信有限公司
高级用户
★★★
据说是李先生
Credits 609
Posts 400
Joined 2008-04-23 15:55
18-year member
UID 116706
Gender Male
Status Offline
This code actually opens an HTML page (which we can't see), and there will be background sound in this page; while the mshta.exe exists when the web page is not closed, and the sound stops but the web page doesn't close automatically, so the process will remain; therefore, we can only close it manually, or because there is no event, we can only add a fixed waiting time in the code and then close it automatically. Because the wscript object in vbscript is not available in HTML, we can't use wscript.sleep for delay, so we use the setTimeout of the window object instead. Taking my song as an example, the length is 3 minutes and 06 seconds, that is 186 seconds. Assuming I want to play it twice and then end the mshta.exe process, then it needs to be closed after 372000 milliseconds, and we can wait a few seconds appropriately, so we take 375000.

mshta vbscript:execute("document.write ""<bgsound src='E:\audio\曹方我是认真的.mp3' loop='2'>"":window.setTimeout ""window.close()"",375000")

It's easier to write with javascript:

mshta javascript:document.write("<bgsound src='E:\audio\曹方我是认真的.mp3' loop='2'>");window.setTimeout("window.close()",375000)

If you don't know the length of the song, set the time to be longer. Generally, popular songs won't exceed 300000 ms, that is 5 minutes.

----------------------
Modified on 2010.09.03 to adapt to paths with spaces
Code effect:

Play "C:\Documents and Settings\issuser\Desktop\music\incoming\EMINEM ft.NATE DOGG - Shake That.mp3" twice in the background, but this program mshta.exe will automatically end exactly after 360000ms, that is 6 minutes.

mshta vbscript:execute("document.write ""<bgsound src='file:///"+Replace("C:\Documents and Settings\issuser\桌面\music\incoming\EMINEM ft.NATE DOGG - Shake That.mp3","\","/")+"' loop='2'>"":window.setTimeout ""window.close()"",360000")


[ Last edited by qinchun36 on 2010-9-3 at 18:39 ]
┏━━━━━━┓
┃据说是李先生┃
┠──────┨
┃*ntRSS┃
┗━━━━━━┛
Forum Jump: