Solved

File associations

Posted on 1998-01-06
10
345 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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
 

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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 132
Delphi inherited method 6 70
how can i search if string exist in array ? 3 59
enhance the following code 3 32
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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