Solved

(125 pts)  Associate a file extension - VB5

Posted on 1998-10-30
5
160 Views
Last Modified: 2010-04-30
I'd like to programmatically associate a file extension to my program from within my program.  Is there an API or something to do it?

I'd like my program to, on the Form_Load event, check if the association is there, then if it's not, make a file association to my program.  For example, how can I programmatically make it so when someone Double-Clicks on an odd file extension (like say a .PTY file) it will start my proram.

75+ Points if you can tell me how to programmatically associate a file extension.

50+ Points if you can tell me how to test if the association is there.  (this one's not as important as I can make an .INI entry saying that the association's already there, but would be nice to know how to check)

HATCHET
0
Comment
Question by:HATCHET
5 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1442595
The keyword is registry. But I don't have any time now.
Somebody else will explain.
0
 

Expert Comment

by:Fantym
ID: 1442596
I have the registry stuff to do it and the correct keys but the information is not with me at this moment so if this question is answered before i get to it thats fine.
0
 

Accepted Solution

by:
PixelMagic earned 50 total points
ID: 1442597
You need to create at least 2 entries in the registry. Both go into the hive HKEY_CLASSES_ROOT. The first is the entry for your file extension (i.e.: .abc). Create an entry for ".abc" and set the default value to a unique program ID for your app, such as "MyApplication".

Then create an entry for "MyApplication". You need to also create a sub-key off this one called "\shell\open\command" and set the default value to the path name of your app and the way it should be called.

Here's an example of the entries:

HKEY_CLASSES_ROOT/.abc       (Default Value) = "MyApplication"
HKEY_CLASSES_ROOT/MyApplication/shell/open/command = "c:\mydir\myapp.exe"

There are other options you can do as well. This is a pretty powerful thing. Let me know if you have any other questions.
0
 
LVL 3

Author Comment

by:HATCHET
ID: 1442598
Fantym,

If you could, please do post your answer as well.  PixelMagic posted an answer that sounds right, and I'll check it to make sure it is, but I'd like to hear what you have to say on it as well.  Any info I can get will help me and I'll award points for your effort.

HATCHET
0
 
LVL 3

Author Comment

by:HATCHET
ID: 1442599
PixelMagic,

You did get the right answer, but not all of it.  Through some checking and research on it, I found you need to modify the following Keys  (using a .pty file as an example):

HKEY_CLASSES_ROOT\.pty
HKEY_CLASSES_ROOT\pty_auto_file
HKEY_CLASSES_ROOT\pty_auto_file "EditFlags"
HKEY_CLASSES_ROOT\pty_auto_file\DefaultIcon
HKEY_CLASSES_ROOT\pty_auto_file\shell
HKEY_CLASSES_ROOT\pty_auto_file\shell\open
HKEY_CLASSES_ROOT\pty_auto_file\shell\open\command


I'm awarding you 50 pts as you didn't supply an example of how to implement it, and you didn't get the second half of the question - How to check the registry if it's already there.

HATCHET
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question