Solved

Associating File Types

Posted on 2009-07-12
14
324 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Dbf export problem to a Visual Foxpro application 6 231
How to debug For loops? 3 60
RESTRequest Parameter 4 52
How to Get Images From Server using App Tethering 11 42
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 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