Jump to content

Opening files with a specified application


Recommended Posts

Running programs and opening files is one of the most fundamental aspects of scripting but I've had the greatest difficulty finding information. I don't think any of the AutoIt or Wiki tutorials show examples and searching the forum was a waste of much time (too many inapplicable results). Ditto for Example Scripts. Very frustrating.

"FileOpen" would seem to be the most obvious but that is text only. "Run" is the next most obvious but seems to apply to the primary files only eg exe. After much time I found "ShellExecute". That did not work - it opened the jpg file with MSPaint which I assume must be the baseline default for XP but not my configured "File Types" default, Irfanview.

I experimented with parameters for the file string variable "$file" attached to the exe, "C:\Program Files\IrfanView\i_view32.exe $file". That did not work so I changed $file to a specific file/path as text. That worked. Command Line parameters are not mentioned in the Help for the "Run" command which seems to be a strange omission.

Getting back to where I am now,

Run("C:\Program Files\IrfanView\i_view32.exe $file")

does not work because the $file is not converted to text. I've tried incorporating the String command String($file). How do I get this to work?

Edited by JohnSAutoIt
Link to comment
Share on other sites

If configured properly, ShellExecute() should do the same thing as "doubble click" on a file. Are you sure JPEG are not set to IfanView by default?

If you have to use the workaround you're trying, it would be

Run("C:\Program Files\IrfanView\i_view32.exe " & $file)
Edited by evilertoaster
Link to comment
Share on other sites

Thanks for the responses. I used the "Run" and it worked fine. I suppose I should have thought of joining the variable with the "&". It did not cross my mind.

Double-clicking a jpeg opens it in Irfanview as it is supposed to. There must be an issue somewhere with the "File Types" configuration.

Link to comment
Share on other sites

Double-clicking a jpeg opens it in Irfanview as it is supposed to. There must be an issue somewhere with the "File Types" configuration.

You can check that in a command prompt by typing:

assoc .jpg

and the output I get is:

.jpg=jpegfile

So now check "jpegfile" from output above:

ftype jpegfile

and the output I get is:

jpegfile=rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen %1

which is the Windows Picture And Fax Viewer.

ShellExecute($file) returns the Windows Picture And Fax Viewer for me. Irfanview may have changed the association and it is perhaps incorrect.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...