Solved

File associations

Posted on 1998-01-06
10
341 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 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

23 Experts available now in Live!

Get 1:1 Help Now