Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Associating File Types

Posted on 2009-07-12
14
Medium Priority
?
329 Views
Last Modified: 2012-05-07
Dear Experts,

I have found a code on this site to make a file have a DIFFERENT icon
than the icon of the .exe file.

This is the way to do it:

[1] Create a file in Notepad and write the following text

    X Icon FileIcon.ico  // this is the icon of your associated-file type

[2] Save the file as "Icon.rc"

[3] Make sure that the file "FileIcon.ico" are in the same folder as "Icon.rc" and then open the command prompt (Start -> Run -> type "cmd") and type (without the quotes) "brcc32 YOUR_PATH\Icon.rc". This will produce a file called "Icon.res".

[4] In Delpi, open your project and add the following line

{ .. code .. }

implementation

{$R *.dfm}
{$R Icon.res}  // add this line

{ .. code ..}

[5] The code:

procedure TMainForm.RegisterFileType;
var
Reg : TRegistry;
Begin
    Reg := TRegistry.Create;
   try
    with Reg do
   begin
    RootKey := HKEY_CLASSES_ROOT;
    OpenKey('\MyApp', True);
    WriteString('', 'MyApp File');
CloseKey;
  OpenKey('MyApp\DefaultIcon', True);
  WriteString('', Application.ExeName + ',0');
CloseKey;
OpenKey('MyApp\shell\open\command', True);
   WriteString('', Application.ExeName + '1');
CloseKey;
   RootKey := HKEY_CLASSES_ROOT;
   OpenKey('\.ext', True);
  WriteString('', 'MyApp');
  CloseKey;
  end;
finally
    Reg.CloseKey;
    Reg.Free;
end;
end;

When I fill in the RegisterFileType procedure, that i have put in the code-section i get:
Project ITKnowledgeBase.exe raised exception class ERegistryException with message 'Failed to set data for"'.

Here is my data:
My applicationname: IT Knowledgebase
Executable.name: ITKnowledgebase.exe
Icon name for the app: AppIcon.ico
Icon name for the file: FileIcon.ico
Filename: Icon.res
extension name:  .pkd


Greetings,

Peter Kiers
procedure TMainForm.RegisterFileType;
var
Reg : TRegistry;
Begin
    Reg := TRegistry.Create;
   try
    with Reg do
   begin
    RootKey := HKEY_CLASSES_ROOT;
    OpenKey('\ITKnowledgeBase', True);
    WriteString('', 'ITKnowledgeBase File');
CloseKey;
  OpenKey('ITKnowledgeBase\DefaultIcon', True);
  WriteString('', Application.ExeName + ',0');
CloseKey;
OpenKey('ITKnowledgeBase\shell\open\command', True);
   WriteString('', Application.ExeName + '1');
CloseKey;
   RootKey := HKEY_CLASSES_ROOT;
   OpenKey('\.PKD', True);
  WriteString('', 'ITKnowledgeBase');
  CloseKey;
  end;
finally
    Reg.CloseKey;
    Reg.Free;
end;
end;

Open in new window

0
Comment
Question by:peterkiers
[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
  • 7
  • 5
  • 2
14 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 24835754
proposal from my side:

you can do all the things using inno setup compiler, no need for doing that stuff with selfwriten code ...

just google for delohi & inno seto up, it is a excellent free tool
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24840816
If you still do not want to do such using Inno, (an outstanding installer, by the way), here is a link to a delphi.about.com article on how to do it easily.

http://delphi.about.com/od/adptips2006/qt/appextension.htm

John
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24841247
I prefer the procedure above.

Greetings, Peter Kiers
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:BdLm
ID: 24841665
is your issue solved, what is the latest status?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24841740
Nothing is solved yet.

I have asked this question before a long time ago.

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_22010656.html

But now i am working on a new application, but i don't get the RegisterFileType-procedure right!
The file that is associated with my application doesn't get the fileicon.ico.

Peter
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24842208
Are you trying to do this under Vista?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24842234
YES, sorry forgot to tell.
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24842297
You will need to run the application as an administrator OR ensure that the executable name has the word 'setup' or install' inside the executable name.

Try that. Right click your executable you created and runas an administrator and let us know what happens.

Also, did you download the code from delphi.about.com from the link I provided above? There are a couple registry settings and one create in delphi.about that you do not have in your code. I know their code works, so... might behoove you to look at it and I pasted it below.


procedure RegisterFileType(ExtName:String; AppName:String) ;
var
  reg:TRegistry;
begin
  reg := TRegistry.Create;
  try
   reg.RootKey:=HKEY_CLASSES_ROOT;
   reg.OpenKey('.' + ExtName, True) ;
   reg.WriteString('', ExtName + 'file') ;
   reg.CloseKey;
   reg.CreateKey(ExtName + 'file') ;
   reg.OpenKey(ExtName + 'file\DefaultIcon', True) ;
   reg.WriteString('', AppName + ',0') ;
   reg.CloseKey;
   reg.OpenKey(ExtName + 'file\shell\open\command', True) ;
   reg.WriteString('',AppName+' "%1"') ;
   reg.CloseKey;
  finally
   reg.Free;
  end;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24842494
These are my data:

Here is my data:
My applicationname: IT Knowledgebase
Executable.name: ITKnowledgebase.exe
Icon name for the app: AppIcon.ico
Icon name for the file: FileIcon.ico
Filename: Icon.res
extension name:  .pkd

How do i fill in the RegistryFileType procedure?


0
 
LVL 1

Author Comment

by:peterkiers
ID: 24842505
I'll be back tommorrow something came up.
Johnjces the 500 p's are yours anyway.

Peter
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 24842561
I have to ask at this point, what is the file extension you are wanting to use to open up some file in your application?

.klb or .know or .jct as examples. Something must be defined there as to what kind of an icon will we double click to open up this file with your application?

Or are you just trying to create a shortcut to open your executable. I am somewhat confused... which by the way is pretty normal!

John
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24846317
.pkd is the file extention.
0
 
LVL 18

Accepted Solution

by:
Johnjces earned 2000 total points
ID: 24846529
Using the procedure supplied, try:

RegisterFileType('pkd', 'ITKnowledgebase.exe') ;

Probably have to run the app asAdministrator for it to work right.

John
0
 
LVL 1

Author Comment

by:peterkiers
ID: 24848537
It works thanks. PK
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

722 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