Solved

Associating File Types

Posted on 2009-07-12
14
321 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

15 Experts available now in Live!

Get 1:1 Help Now