Sign in to follow this  
Followers 0
ryantollefson

Open With?

16 posts in this topic

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.

Share this post


Link to post
Share on other sites



ShellExecute??

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ShellExecute??

That will just use the default program though.

Edited by ryantollefson

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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 this post


Link to post
Share on other sites

Try adding the entire path to the WMA file.


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

Share this post


Link to post
Share on other sites

Try adding the entire path to the WMA file.

Tried that, no luck :)

Share this post


Link to post
Share on other sites

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

Download this WMA file from here:

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 this post


Link to post
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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

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

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0