473,378 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to associate files with application

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
6 2340

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
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
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
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
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
Thanks Lasse, that was really helpful

Nov 3 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: knutsample | last post by:
Hello! I'm trying to associate a file extension to my wxPython script so that all I have to do is double click on the file and my python script will load up with the path of that file. For...
2
by: John Baker | last post by:
Hi: I have used this group a number of times simply because while the manuals for Access may show the technology, but most are really weak on how to apply it in special situations and the...
1
by: Tran Hong Quang | last post by:
Hi, Is it possible to write a code in C++ to associate a given file extension with our application? So that if user double click on the file on Windows Explorer, our application will be launched....
1
by: Ryan Liu | last post by:
Hi, As I remember theare are In and Out stream associate with a socket. TcpClient seems there in only one NetworkStream to do both read and write. Then will it be a conflicit if both side try...
4
by: BD | last post by:
Hi all. Running SQL2K SP4 on W2K3 Standard, SP4. I have just refreshed a database on one server with a backup from another. The database had existed previously on the target server, and I am...
1
by: zidansoft | last post by:
I created appropriate registry entries(shell\open\command) . my simple application lunching with that particular extension . problem 1 how i can handle that particular file from my...
2
by: wizardRahl | last post by:
Hello, I am curious to know if there is a way to associate old files with a new installation of windows. I reinstalled windows b/c the OS crashed and would never boot. Upon installing the fresh...
0
by: Proogeren | last post by:
Hello Does anyone know if it is possible to associate mp3 files with a vb 6.o application? Like windows media player. so that when you see a mp3 file in explorer it will have your applications...
0
by: liuhengyi | last post by:
Hi, I also have a question when using VS 2008 to edit the xml file. In my xml file, I used schemaLocation attribute to specify the xsd. If I put the xsd in our internal sharepoint site such as:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.