473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2360

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_RO OT, add a key (folder) with the name .ext
2. Open that key, and set the (Default) value to MyProgramExtend edFile
(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_RO OT, add another key, this time with the same
name you made up in 2. above, ie MyProgramExtend edFile
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 MyProgramExtend edFile, 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 MyProgramExtend edFile 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_RO OT\.ext
to find the details you want.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vk arlsen.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_RO OT, add a key (folder) with the name .ext
2. Open that key, and set the (Default) value to MyProgramExtend edFile
(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_RO OT, add another key, this time with the same
name you made up in 2. above, ie MyProgramExtend edFile
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 MyProgramExtend edFile, 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 MyProgramExtend edFile 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_RO OT\.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.pytho n:

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.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.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.pytho n:
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***@vk arlsen.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
3391
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 instance, I've associated all .py files to be opened up with emacs.exe. If I double click on a .py file, emacs.exe would open up with that file in...
2
1837
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 indexes are less that complete!. This is also the first real application iI have developed for Access, although I have done a number in Lotus Approach. ...
1
1252
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. Thanks Tran Hong Quang
1
1308
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 to send data? And when one end is sending data, if another end is not calling Recevive or BeginReceive, will the sender be blocked? Or recevier...
4
15638
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 just refreshing its contents. I used the following approach 1) From the target server, create a SQL script with users and roles 2) From the source...
1
1145
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 application?(how get file name as well as where i can handle ) problem2 when i tried with big application (liking with so many dll and other files) it is ...
2
1476
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 copy, I made a seperate folder called Windows2 to store the new system files and just to make sure that none of my data was lost. I now want to have...
0
823
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 icon? help appreciated
0
3169
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: xsi:schemaLocation="someNs http://sharepoint/Test.xsd" VS2008 xml editor shows that "this schema referenced from this location in your document...
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.