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┃
┗━━━━━━┛