0

I want to open .mp3 files with mpg123.exe silently when a .mp3 file is double clicked from within Windows Explorer. For this I wrote a VBScript as bellow and changed the default program for playing .mp3 files by assigning my VBScript to it via Open with → Choose default program. My script is working well from within command line (cmd.exe) but when a .mp3 file is double clicked I get an error message that double clicked .mp3 file is not an executable file in Windows. Here is my VBScript, please let me know where I am doing wrong.

if Wscript.arguments.count = 0 then
  WScript.quit
else
  strSoundFile = WScript.Arguments.Item(0)
end if

Set objShell = CreateObject("Wscript.Shell")

strCommand = "mpg123.exe -q " & chr(34) & strSoundFile & chr(34)

objShell.Run strCommand, 0, True 
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
David
  • 299
  • 2
  • 14

1 Answers1

1

Why don't you just associate mp3 files with mpg123.exe and set up the associated parameters (eg: -q "%1") instead?

Since I couldn't find a notable existing example, I've whipped up an example for you. (tested to work on Windows 7 with mpg123.exe). The response was too image heavy to post here. I hope it helps you.

Damien
  • 1,490
  • 1
  • 8
  • 17
  • Well how can I pass parameters like switch -q through "Open With -> Choose default program ..." ? That only accept the mpg123.exe without switch -q. Also I don't want using batch file (.bat) since it shows up the command shell. Perhaps, It is possible to execute .bat file within the vbscript to solve the problem (if so how to do that?) Where am I doing wrong in my vbscript? Please help. – David Jan 08 '14 at 18:28
  • 1
    @user108631 You need to modify the file association in the registry if you want to launch the program with parameters. See [here](http://stackoverflow.com/a/17274993/1630171) for an example. – Ansgar Wiechers Jan 08 '14 at 22:22
  • I've updated my answer to include a link to a quick example I have mocked up for you : http://www.jigsolving.com/general/associate-files-with-parameters-win-7 – Damien Jan 09 '14 at 07:32
  • Thank you Ansgar and specially Damien for his detailed answer. – David Jan 09 '14 at 12:10
  • I did what Damien instructed; a command shell window was showed up and then disappeared shortly. The reason I didn't go for associating .mp3 file to be handled by .bat file was that popping command shell window that it also appread by your registry command : cmd.exe /c start /min “MP3:%1″ “C:\MPG 123\MPG123.exe” -q “%1″ . Specifically I am looking for solution preventing the popping shell command. Please help if there is any modification to that. – David Jan 09 '14 at 12:20
  • You do know that the mpg123.exe will always show a window when executed right? It's actually just minimised in the solution I gave you. – Damien Jan 09 '14 at 16:11
  • You could take that cmd.exe section out and you will see what I mean... The app will still leave a blank cmd shell looking window open while it is playing a tune. If you don't want that, you'll have to get another app that is "Windows" based. This is a console based app. The -q suppresses the text but not the actual application window. Your actual question is answered. However, it seems as though your INTENDED QUESTION is actually "how can I run a dos based mp3 application without showing a command prompt like dos box?". Answer: you can't. You'd need to get another app. – Damien Jan 09 '14 at 16:23
  • Here's someone else asking a similar question (from the other side) http://stackoverflow.com/questions/2239151/how-to-run-console-application-in-background-no-ui – Damien Jan 09 '14 at 16:32