I'm not sure what is going on here. Part of your code is scripting the WMP object and then the switch to the
run method. Also the
mp3 variable is undefined and
time is a reserved word.
This is for your consideration. Before you panic at the sight of the code, WMP runs asynchronous to the script so most of the script is spent calculating how much time to wait for the song to play.
Set fso = CreateObject("Scripting.FileSystemObject")
Set wmp = CreateObject("WMPlayer.ocx")
Set objShell = CreateObject("Shell.Application")
Set WshShell = CreateObject("WScript.Shell")
' Prompt for song
'
Do
WScript.StdOut.Write("Enter Song Name: ")
strSong = WScript.StdIn.ReadLine
Loop Until fso.FileExists(strSong)
' Calculate song length (milliseconds)
'
Set f = fso.GetFile(strSong)
folder = f.ParentFolder
file = f.Name
Set shellFolder = objShell.NameSpace(folder)
Set shellFile = shellFolder.ParseName(file)
duration = Split(shellfolder.GetDetailsOf(shellfile, 27), ":")
sleeptime = ((duration(1)*60) + duration(2)) * 1000
' Play the song
'
wmp.openPlayer(strSong)
WScript.Sleep sleeptime
' Shutdown the player
'
WshShell.AppActivate("Windows Media Player")
WshShell.SendKeys "%{F4}"
The user is prompted for the song name. A fully qualified path is required; do not use quotes. Win7 does not seem to have a shortcut key to minimize a window. For XP you can add the following code after the wmp.openPlayer line:
WScript.Sleep 2000
WshShell.AppActivate("Windows Media Player")
WshShell.SendKeys "% n"
If nothing else, this may give you some ideas.