# Open With?

## Recommended Posts

Sorry if this has been asked before, I tried searching, but couldn't find it. I'm wondering how I can open a file with a specified application (like when you right click on a file and can choose "Open With"). For example, if I wanted to open song.mp3 with winamp instead of it's default application.

ShellExecute??

##### Share on other sites

ShellExecute??

That will just use the default program though.

Edited by ryantollefson

##### Share on other sites

I really don't know if this would work, since I'm using Win98 and it doesn't have that option.

ShellExecute("filename","","","Open with")

If it does work, I suppose all it'll do is show you the window where you are supposed to choose the program.

It should be a quite interesting function to make.

##### Share on other sites

I tried this:

ShellExecute("myfile.txt", "", @ScriptDir, "Open With")

And I get this error:

...Unable to execute the external program.:

ShellExecute("myfile.txt", "", @ScriptDir, "Open With")

No application is associated with the specified file for this operation.

##### Share on other sites

If you are wanting to open a file somewhere other than it's default app, then you should just be using Run() to execute the desired program directly and pass your file as a parameter.

##### Share on other sites

I tried this:

ShellExecute("myfile.txt", "", @ScriptDir, "Open With")

And I get this error:

...Unable to execute the external program.:

ShellExecute("myfile.txt", "", @ScriptDir, "Open With")

No application is associated with the specified file for this operation.

Did you even replace "myfile.txt" and "Open with" by something!? Edited by Dieuz

##### Share on other sites

weaponx, can you give me an example of how to do this? I tried:

Run("c:\Program Files\Windows NT\Accessories\wordpad.exe -C:\Users\Ryan\Documents\AutoIT\examples\myfile.txt")

but this just opens Wordpad, not the .txt file with it.

Dieuz, yes I replaced Open With with the program path, and "myfile.txt" is a file I am using to test this.

##### Share on other sites

Run('c:\Program Files\Windows NT\Accessories\wordpad.exe "New Text document.txt"')
I had New Text document.txt in the same folder as the script - you might want the entire path to your text file.

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

##### Share on other sites

You don't put a - before a parameter. Putting the parameter in quotes is better though.

Run('c:\Program Files\Windows NT\Accessories\wordpad.exe "C:\Users\Ryan\Documents\AutoIT\examples\myfile.txt"')

##### Share on other sites

You don't put a - before a parameter.

Thanks (to herewasplato too), that worked for the .txt file... But now how can I do it for something like this (this doesn't work - it will open Windows Media Player, but not the file)?

Run('C:\Program Files\Windows Media Player\wmplayer.exe "Triangle.wma"')

I tried this with the full path to Triangle.wma also, but that didn't work either.

Edited by ryantollefson

##### Share on other sites

Try adding the entire path to the WMA file.

[size="1"][font="Arial"].[u].[/u][/font][/size]

##### Share on other sites

Try adding the entire path to the WMA file.

Tried that, no luck

##### Share on other sites

Just so we are on the same page here (playing the same file):

http://www.triviaproducer.com/TB4_2_Playing_a_Game.wma

or, if you prefer the site, then link route:

http://www.triviaproducer.com/support.html

then "right mouse click/save file as" the "Playing a Game:" link

then run this code - changing the path as needed:

Run('C:\Program Files\Windows Media Player\wmplayer.exe "C:\Temp\TB4_2_Playing_a_Game.wma"')

It starts Windows Media Player (WMP), version 11.0.5721.5230, on a computer running the XP SP2 OS and plays the file as expected.

What happens for you?

What version of WMP are you using?

What OS?

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

##### Share on other sites

Maybe also there is need to use working dir..

Run('"C:\Program Files\Windows Media Player\wmplayer.exe" "Path\to\file\Triangle.wma"', '"Path\to\file"')oÝ÷ Ø   Ýj[(¶¼­¢ë²+¶­«­¢+ÙIÕ¸ ÌäìÅÕ½ÐìÌäìµÀì¥±ÑM¡½ÉÑ9µ ÌäíèÀäÈíAÉ½É´¥±ÌÀäÈí]¥¹½ÝÌ5¥A±åÈÀäÈíÝµÁ±åÈ¹áÌäì¤µÀìÌäìÅÕ½ÐìÌäìµÀì¥±ÑM¡½ÉÑ9µ ÌäíAÑ ÀäÈíÑ¼ÀäÈí¥±ÀäÈíQÉ¥¹±¹ÝµÌäì¤°ÌäìÅÕ½ÐíAÑ ÀäÈíÑ¼ÀäÈí¥±ÅÕ½ÐìÌäì¤

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

My Work...

Spoiler

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating )

* === My topics === *

==================================================

==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

##### Share on other sites

So I'm an idiot and can't type. :">

Thanks for all the help guys, and herewasplato, thanks for the (properly) spelled out example

Edited by ryantollefson

## Create an account

Register a new account