Solved

File associations

Posted on 1998-01-06
10
335 Views
Last Modified: 2010-04-04
Hi! How do I set file associations within code? I tried by setting registry values, but nothing happend.
0
Comment
Question by:fmichaud061597
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1355439
You mean to make the association permanent?
0
 

Author Comment

by:fmichaud061597
ID: 1355440
Yes, like many other programs do. For example, word97 documents use a specific icon in shell and when we double-click on them they open within word.
0
 

Accepted Solution

by:
Dippen earned 50 total points
ID: 1355441
This procedure creates a permanent file association for ".abc"-files, and it starts to work right away (no reboot required). To test it, make a copy of "Autoexec.bat" (or another textfile) and give the copy the extension ".abc". The example below will associate the ".abc"-extension with the 8th icon embedded in the standard "Defrag.exe" program supplied with W95.
   When you click the ".abc"-file, it will open up in NOTEPAD:


procedure TForm1.Button1Click(Sender: TObject);
var
  TReg : TRegistry;

begin
  //Create the registry-handler
  TReg := TRegistry.Create;
  //Set the rootkey
  TReg.Rootkey := HKEY_CLASSES_ROOT;
  //First create a subkey that matches the file-extension
  TReg.OpenKey('.abc',True);
  //Then give the key (Standard) a descriptive name
  TReg.WriteString('','Testapplication');

  //Then create a key that matches the ".abc" value (Testapplication)
  TReg.OpenKey('\Testapplication',True);
  //Then create a subkey containing the name of the icon for the extension ".abc"
  TReg.OpenKey('\Testapplication\DefaultIcon',True);
  //Then define what icon to use
  TReg.WriteString('','c:\windows\defrag.exe,7');
  //Then create a subkey that contains the definition for what should happen when
  //a file with that extension is opened
  TReg.OpenKey('\Testapplication\shell',True);
  TReg.OpenKey('open',True); //"open" is created as a subkey to "shell"
  TReg.OpenKey('command',True); //and "command" is created as a subkey to "open"
  //Finally, we associate the "open"-command with the NOTEPAD.EXE program.
  TReg.WriteString('','C:\Windows\NotePad.exe "%1"');
  //Finished!
  TReg.Free;
end;

Good luck!

//Daniel, Sweden
0
 

Author Comment

by:fmichaud061597
ID: 1355442
I already have done this and the icon associated with my file type still not show.
0
 

Expert Comment

by:Dippen
ID: 1355443
What version of Delphi are you using? And what OS?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:Dippen
ID: 1355444
One more thing: Does the file association not work after rebooting either? If you like to, you could mail me the code and let me look at it.
0
 

Author Comment

by:fmichaud061597
ID: 1355445
I'm using Delphi 3 with Windows 98.
0
 

Expert Comment

by:Dippen
ID: 1355446
OK, then I'm afraid I have nothing further to add to this discussion... ;-) (I'm using Delphi v2.0 with W95)
   It works for me, but then maybe there is something more that must be put in the W98-registry before it works properly, or some other problem. Good luck!
0
 

Expert Comment

by:zitt
ID: 2391901
Borrowed the code below from another freeware component:

// Update system to notify of association change
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, PChar(''), PChar(''));

Source:
Larry J. Rutledge <lrutledge@jps.net>
http://www.prestwood.com/forums/delphi/sdug/newsletter

To get the code associated with an article, go to the following:
http://www.geocities.com/SiliconValley/Lakes/4339
0
 

Expert Comment

by:zitt
ID: 2391915
Oh... and the unit required for the SH* constants:
uses
   ShlObj;
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now