Solved

Associating File Types

Posted on 2009-07-12
14
322 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

862 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

22 Experts available now in Live!

Get 1:1 Help Now