Solved

File associations

Posted on 1998-01-06
10
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 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