By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

how to associate files with application

P: n/a
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.

Oct 27 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

Ashok wrote:
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/window...fileassoc4.htm

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

Oct 28 '05 #2

P: n/a
Ashok wrote:
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.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Oct 28 '05 #3

P: n/a
Lasse Vågsæther Karlsen wrote:
Ashok wrote:
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.

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.
Oct 28 '05 #4

P: n/a
On Fri, 28 Oct 2005 09:48:27 -0400, "Colin J. Williams"
<cj*@sympatico.ca> declaimed the following in comp.lang.python:

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.
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Oct 28 '05 #5

P: n/a
Dennis Lee Bieber wrote:
On Fri, 28 Oct 2005 09:48:27 -0400, "Colin J. Williams"
<cj*@sympatico.ca> declaimed the following in comp.lang.python:
I'm no Windows expert but I think that, using Windows Explorer, one can,
with a right mouse click, select "Open With".

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

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Oct 29 '05 #6

P: n/a
Thanks Lasse, that was really helpful

Nov 3 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.