Jump to content

Open Any File


 Share

Recommended Posts

I am a newbie. But i am sure this must be possible...

Can i get autoit to open any file i like without saying what program needs to open it?

When you click on a file you dont have to know what program should open it. The OS already knows because the file type has been assigned to that application.

I know that the following works.

$LocationAndApplication2OpenWithEXE = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
$ItemLocationAndNameToOpen=@WorkingDir &"\FFT\school_FFT_DB_SCH.mdb"
Run('"' & $LocationAndApplication2OpenWithEXE & '" "' & $ItemLocationAndNameToOpen & '"')

Or the very simple example in the help file

Run("Notepad.exe", "", @SW_MAXIMIZE)

.. But is there a way not to say the program and just specify the file?

I want to open word, access and excel files. But if the autoit is run on a machine with a different version of office i'd have to code all the locations of the various versions of office.

Is there a way to solve this :whistle:

Thanks in advance :)

Link to comment
Share on other sites

.. But is there a way not to say the program and just specify the file?

I want to open word, access and excel files. But if the autoit is run on a machine with a different version of office i'd have to code all the locations of the various versions of office.

Is there a way to solve this :whistle:

Try this:

Run(@ComSpec & ' /c start ' & $filename, '', @SW_HIDE)

start knows most of the file associations.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

You could search for the excel/access/word exe's on the local computer. Then enter

<exe> <filename> at the command prompt

This method will only require you to know the name of the executables which should be standard.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

#include <Process.au3>
_RunDos("start d:\autoit\smurf.tif")


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Thanks for your help.

It works fine for text files. But i'm now trying to open an access database. And nothing happens. No error or anything.

I've tried both

$filename = @WorkingDir &"\FFT\database.mdb"
Run(@ComSpec & ' /c start ' & $filename, '', @SW_HIDE)

And...

_RunDos("start H:\Autoit\FFT\database.mdb")

Any ideas?

Thanks for the help so far :whistle:

Link to comment
Share on other sites

$filename = @ScriptDir &"\FFT\database.mdb"
$CodeName = RegRead("HKEY_CLASSES_ROOT\.mdb", "")
$thingtorun = RegRead("HKEY_CLASSES_ROOT\"&$CodeName&"\shell\Open\command", "")
$thingtorun = StringReplace($thingtorun, "%1", $filename)
Run($thingtorun)

#)

Link to comment
Share on other sites

It works fine for text files. But i'm now trying to open an access database. And nothing happens. No error or anything.

Any ideas?

Three things:

1.) is M$ Access installed on your system?

2.) what happens if you double click a *.mdb file?

3.) what happens if you run the start command manually?

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Three things:

1.) is M$ Access installed on your system?

2.) what happens if you double click a *.mdb file?

3.) what happens if you run the start command manually?

Cheers

Kurt

1) Yes of course. I'm lame at Autoit but i'm not that lame :whistle:

2) If i double click a *.mdb file it open in Access

3) If you mean do a Start> Run > Type the path to the file and click ok. Then that opens the file in Access too.

Cheers

Jonez

Link to comment
Share on other sites

$filename = @ScriptDir &"\FFT\database.mdb"
$CodeName = RegRead("HKEY_CLASSES_ROOT\.mdb", "")
$thingtorun = RegRead("HKEY_CLASSES_ROOT\"&$CodeName&"\shell\Open\command", "")
$thingtorun = StringReplace($thingtorun, "%1", $filename)
Run($thingtorun)

#)

Coool! That opens the file! Thanks for that.

Any ideas why my other code doesnt work?

I was trying to do it as simply as possible and that works fine for text files and even word *.doc files.

Cheers :whistle:

Link to comment
Share on other sites

$filename = @ScriptDir &"\FFT\database.mdb"
$CodeName = RegRead("HKEY_CLASSES_ROOT\.mdb", "")
$thingtorun = RegRead("HKEY_CLASSES_ROOT\"&$CodeName&"\shell\Open\command", "")
$thingtorun = StringReplace($thingtorun, "%1", $filename)
Run($thingtorun)

#)

As i said that works fine for *.mdb files.

If i wanted to open a word document would i just do.

$filename = @ScriptDir &"\FFT\document.doc"
$CodeName = RegRead("HKEY_CLASSES_ROOT\.doc", "")
$thingtorun = RegRead("HKEY_CLASSES_ROOT\"&$CodeName&"\shell\Open\command", "")
$thingtorun = StringReplace($thingtorun, "%1", $filename)
Run($thingtorun)

This opens Word but the file doesnt open at all.

Cheers for the help

Link to comment
Share on other sites

1) Yes of course. I'm lame at Autoit but i'm not that lame :whistle:

well, we do have some really "strange" people on this forum. I thought it's better to eliminate the obvious problems first :)

2) If i double click a *.mdb file it open in Access

What's the output of:

assoc | find "mdb"

and

ftype | find "access"

3) If you mean do a Start> Run > Type the path to the file and click ok. Then that opens the file in Access too.

Actually no. Start > Run > cmd.exe and then "start H:\Autoit\FFT\database.mdb".

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Try this:

Func _OpenFile($extention, $file)
   $CodeName = RegRead("HKEY_CLASSES_ROOT\"&$extention, "")
   $thingtorun = RegRead("HKEY_CLASSES_ROOT\"&$CodeName&"\shell\Open\command", "")
   $thingtorun = StringReplace($thingtorun, "%1", $file)
   If Not @extended Then $thingtorun = $thingtorun & " " & $file
   Run($thingtorun)
EndFunc

May fail on certain types of files, as I only taken into account one of the ways inwhich assosiations are stored.

_OpenFile(".doc", @ScriptDir &"\FFT\document.doc")

#)

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...