how to associate files with application

A

Ashok

hi,
i want to know how to make a specific type of file open in an
application i developed in python when the user clicks on the file.(in
windows) for eg. a .txt file when clicked opens in notepad, a .doc file
when clicked opens in MS-word. In the same way i want to make a .xyz
file open in the application i developed when clicked.
thanks in advance for any advice.
 
J

jmdeschamps

Ashok said:
hi,
i want to know how to make a specific type of file open in an
application i developed in python when the user clicks on the file.(in
windows) for eg. a .txt file when clicked opens in notepad, a .doc file
when clicked opens in MS-word. In the same way i want to make a .xyz
file open in the application i developed when clicked.
thanks in advance for any advice.

Not an expert in this (OS-related) field but in Windows I think that
would be a Registry thing...

Maybe this article could help you start somewhere...
http://antivirus.about.com/od/windowsbasics/l/blfileassoc4.htm

Good Luck, and maybe you can reply-post your eventual success recipe!
 
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

Ashok said:
hi,
i want to know how to make a specific type of file open in an
application i developed in python when the user clicks on the file.(in
windows) for eg. a .txt file when clicked opens in notepad, a .doc file
when clicked opens in MS-word. In the same way i want to make a .xyz
file open in the application i developed when clicked.
thanks in advance for any advice.

You need to add several registry keys to do this, here's a short version
of what you need to do:

Example assumes you want to:

1. associate .ext with C:\Program Files\MyProgram\prog.exe
2. pass on any extra arguments to prog.exe (ie. test.ext 1 2 3 would
send 1 2 3 as well to prog.exe)
3. associate the icon of prog.exe to any file with a .ext extension

Ok, here's what you need to do:

1. Under HKEY_CLASSES_ROOT, add a key (folder) with the name .ext
2. Open that key, and set the (Default) value to MyProgramExtendedFile
(this name is something you choose yourself and should be a "identifier"
that identifies the file type. If your program supports several types of
files, make up unique identifiers for each.)
3. Under HKEY_CLASSES_ROOT, add another key, this time with the same
name you made up in 2. above, ie MyProgramExtendedFile
4. Open that key, and set the (Default) value to a textual description
of the type of file. This is what will show up in explorer in the file
type column. If you leave this empty, the description will be .EXT File
5. Inside MyProgramExtendedFile, add another key with the name shell
(lower-case is typical, can probably be Shell or whatever)
6. Inside shell, create another key with the name open
7. Inside open, create another key with the name command
8. Inside command, Set the (Default) value to:
"C:\Program Files\MyProgram\prog.exe" "%1" %*

Note that you need the quotes as specified above, exactly like written

9. Go back to MyProgramExtendedFile and create another key with the name
DefaultIcon
10. Inside DefaultIcon, set (Default) value to:
"C:\Program Files\MyProgram\prog.exe", 0

This will pick the first icon in prog.exe resource to show for the
files. Use 1 for second, etc.

There are also other commands you can add. If you want to be able to
right-click on the file and select a menu item to process the file in a
specific way, for instance by passing along specific parameters to
prog.exe, you can add more keys than "open" on the level open is
created. The (Default) value inside the key is then the text of the menu
item.

To find examples, just find a file extension in Windows that behaves the
way you want your own to behave and look through HKEY_CLASSES_ROOT\.ext
to find the details you want.
 
C

Colin J. Williams

Lasse said:
You need to add several registry keys to do this, here's a short version
of what you need to do:

Example assumes you want to:

1. associate .ext with C:\Program Files\MyProgram\prog.exe
2. pass on any extra arguments to prog.exe (ie. test.ext 1 2 3 would
send 1 2 3 as well to prog.exe)
3. associate the icon of prog.exe to any file with a .ext extension

Ok, here's what you need to do:

1. Under HKEY_CLASSES_ROOT, add a key (folder) with the name .ext
2. Open that key, and set the (Default) value to MyProgramExtendedFile
(this name is something you choose yourself and should be a "identifier"
that identifies the file type. If your program supports several types of
files, make up unique identifiers for each.)
3. Under HKEY_CLASSES_ROOT, add another key, this time with the same
name you made up in 2. above, ie MyProgramExtendedFile
4. Open that key, and set the (Default) value to a textual description
of the type of file. This is what will show up in explorer in the file
type column. If you leave this empty, the description will be .EXT File
5. Inside MyProgramExtendedFile, add another key with the name shell
(lower-case is typical, can probably be Shell or whatever)
6. Inside shell, create another key with the name open
7. Inside open, create another key with the name command
8. Inside command, Set the (Default) value to:
"C:\Program Files\MyProgram\prog.exe" "%1" %*

Note that you need the quotes as specified above, exactly like written

9. Go back to MyProgramExtendedFile and create another key with the name
DefaultIcon
10. Inside DefaultIcon, set (Default) value to:
"C:\Program Files\MyProgram\prog.exe", 0

This will pick the first icon in prog.exe resource to show for the
files. Use 1 for second, etc.

There are also other commands you can add. If you want to be able to
right-click on the file and select a menu item to process the file in a
specific way, for instance by passing along specific parameters to
prog.exe, you can add more keys than "open" on the level open is
created. The (Default) value inside the key is then the text of the menu
item.

To find examples, just find a file extension in Windows that behaves the
way you want your own to behave and look through HKEY_CLASSES_ROOT\.ext
to find the details you want.
I'm no Windows expert but I think that, using Windows Explorer, one can,
with a right mouse click, select "Open With".

You can then choose the appropriate executable. I believe that, if you
had set the "Always open with this program" box, then the registry is
automatically updated.

Colin W.
 
D

Dennis Lee Bieber

I'm no Windows expert but I think that, using Windows Explorer, one can,
with a right mouse click, select "Open With".

You can then choose the appropriate executable. I believe that, if you
had set the "Always open with this program" box, then the registry is
automatically updated.
You could also use the "file types" page (on XP it is under
"tools/folder options", W9x puts it under "view/folder options" I
believe). to define new file types, and then define all the actions
available for it. The default would be the Open action, but you might
add a print or edit action; these would show up using a right-click on
the file.
--
 
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

<snip>

There are several ways to do this using Windows Explorer. I was under
the assumption the OP wanted to know how he could automate it since that
is what you typically want to do with applications you write.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top