Jump to content

File Association


cppman
 Share

Recommended Posts

Hi, Im farely new to AutoIt. Right now I am working on a text editor.

Im wondering if I was to associate the .txt extension with my program, and someone double clicks on a .txt file, how i could get my program to read that file.

Could someone show me a simple example of how I could do this.

thanks!

Link to comment
Share on other sites

Hi, Im farely new to AutoIt. Right now I am working on a text editor.

Im wondering if I was to associate the .txt extension with my program, and someone double clicks on a .txt file, how i could get my program to read that file.

Could someone show me a simple example of how I could do this.

thanks!

You are talking about changing "File Associations".

Read and enjoy!

Go Seahawks! :lmao:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You are talking about changing "File Associations".

Read and enjoy!

Go Seahawks! :lmao:

thanks, but that is not what i was looking for.

For example,

When u open a text file, usually it will automatically open in notepad(or whatever text editor you use), and the contents of that txt file are output to the Text Editor.

IM trying to do the same thing. ONe someone opens a .txt file, it will put the contents of that file inside my Edit control.

Link to comment
Share on other sites

If RegRead ("HKEY_CLASSES_ROOT\txtfile\shell\open\command", "") <> @ScriptFullPath Then RegWrite ("HKEY_CLASSES_ROOT\txtfile\shell\open\command", "", "REG_SZ", '"'&@ScriptFullPath&'" "%1"')

put that line at the very beginning of your script.

use $CmdLine[1] as the file's path.

For information on how that line works, read up on RegRead and RegWrite.

For information on reading the file, try FileOpen, FileRead, FileReadLine, and FileClose.

NOTE: This script modifies the registry. Use at your own risk.

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

If RegRead ("HKEY_CLASSES_ROOT\txtfile\shell\open\command", "") <> @ScriptFullPath Then RegWrite ("HKEY_CLASSES_ROOT\txtfile\shell\open\command", "", "REG_SZ", '"'&@ScriptFullPath&'" "%1"')

put that line at the very beginning of your script.

use $CmdLine[1] as the file's path.

For information on how that line works, read up on RegRead and RegWrite.

For information on reading the file, try FileOpen, FileRead, FileReadLine, and FileClose.

NOTE: This script modifies the registry. Use at your own risk.

Thankyou so much! That is what i have been wondering for some time now!... thanks alot!
Link to comment
Share on other sites

thanks, but that is not what i was looking for.

For example,

When u open a text file, usually it will automatically open in notepad(or whatever text editor you use), and the contents of that txt file are output to the Text Editor.

IM trying to do the same thing. ONe someone opens a .txt file, it will put the contents of that file inside my Edit control.

It's possible I misunderstood you, but I don't think so... :lmao:

The reason notepad opens when you double-click on a .txt file is because Notepad.exe has been Associated with the .txt extention. If you change the association for .txt files from Notepad.exe to MyScript.exe, then your script will open, with the file name passed as a command line argument. It is up to your script to take the received path and open the file, same as with Notepad.exe.

Comprede mon ami? ;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

here, just use this

$var = "c:\test.txt"
start($var)
func start($filex)
if $filex <> '' then
Return Run(@Comspec & " /c start " & $filex, '', @SW_HIDE
endif
endfunc

works with any file type, thought this might help

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

but that link u gave me, is just talking about, changing file ASSOCIATIONS, like going under FOLDER OPTIONS... I was talking about getting the FileName and FilePath to the File that was opened. That link said nothing about that.

thanks though.

That's accomplished automatically when you follown the procedure to make the association. You already got the regwrite() you need from theguy0000, but this is how it works (follow along in regedit, HKCR = HKEY_CLASSES_ROOT):

1. You double-click on a .txt file, which tells window to "open" the file

2. Windows reads HKCR\.txt and finds that the default type is "txtfile"

3. Windows reads HKCR\txtfile and finds that there is a shell key (meaning the shell can handle this)

4. Windows reads HKCR\txtfile\shell\open and finds there is a command key to run on open

5. Windows reads HKCR\txtfile\shell\open\command and finds the default command is "C:\Windows\System\Notepad.exe %1" (your path may vary)

The "%1" part is where Windows automatically puts the full path to the file you originaly double-clicked on.

If you double-clicked on "D:\MyStuff\TextFile.txt", then the effective command to Windows, based on the file association, is:

"C:\Windows\System\Notepad.exe" "D:\MyStuff\TextFile.txt"

If you change the association as described in that link I gave you (or more directly by the regwrite() theguy0000 gave you) to point to your script at "D:\MyStuff\AutoIT\MyScript.exe", then the registry says:

HKCR\txtfile\shell\open\command\"" = "D:\MyStuff\AutoIT\MyScript.exe %1"

Note that Windows will add the "%1" at the end if you use the file manager to make the change, or you write it explicitly with theguy0000's regwrite().

Now, when you double-click on a .txt file, Windows goes through steps 1 thru 5 above and gets the following command line:

"D:\MyStuff\AutoIT\MyScript.exe" "D:\MyStuff\TextFile.txt"

The path to the file is now a command line argument passed to your script. It is still up to your script to know what to do with that argument. Notepad.exe has to take that argument and open the file, so does your script. It was already pointed out by theguy0000 that "$CmdLine[1]" is how you see the command line argument inside your script. Your script then contains something like:

; Open file
$MyFileHandle = FileOpen($CmdLine[1], 0)

; Continue to read file into edit control

You may not of needed that long explanation, but I'm waiting for the Seahawks to take the lead back... :king:

Edit: Oops, had $CommandLine[1] vice $CmdLine[1]

Edit II: :lmao: Ummm... o:) Still waiting for the Seahawks to take the lead back... ;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I'm working on a text editor too. I can't get the "Open With..." thing right. What arre the command lines if any? How do I get that to work? Like, say I want to open a text file in explorer. I right click it andsay open with. Any advice?

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
Link to comment
Share on other sites

I'm working on a text editor too. I can't get the "Open With..." thing right. What arre the command lines if any? How do I get that to work? Like, say I want to open a text file in explorer. I right click it andsay open with. Any advice?

if you want an easy way to do it for one machine, i made a little gui for changing/deleting/viewing file associations. It's in scripts and scraps If nothing else, you can look through the code and see how i look up the extensions in the registry, and find the actions associated with those extensions.
Link to comment
Share on other sites

I got a great working example! BenEditor! The beta doesn't work to good but the stable one does. Try it!

See my signature.

http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script]
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...