The Registry

2 things here. Answer either one.

1) How do I write a program to configure the registry, so that whenever a file of a certain extension is clicked, Windows will fire up my application and my application will open the file?

2) Add a new item to the "right-click pop-up". When you right-click a file, a pop-up comes up right? I wanna add an item inside there, so that whenever someone clicks the item, my application will automactically open the selected file.

Thanks.
jackjokerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RadlerCommented:
Try

http://ftp/d20free/atshell.zip I'm using it

T++, Radler.
0
interCommented:
Hi,

Be carefull, you may override your associations if extension is already registered.

// Associating specific type with the application.
// Warning : This function overrides your previous association if you give a file name already
//           registered.
// Add registry unit to your uses clause

function MakeAssociation(Ext, AppName: string): boolean;
var
  R: TRegistry;
  MapName: string;
begin
  Result := true;
  try
    R := TRegistry.Create;
    try
      R.RootKey := HKEY_CLASSES_ROOT;
      // try to find a unique name for our assoc
      MapName := Ext + 'File';
      while R.KeyExists(MapName) do MapName := MapName + '1';
      // strip out the . form defname
      while (MapName[1] = '.') do Delete(MapName, 1, 1);
      // create assoc base
      Result := Result and R.OpenKey('\' + Ext, true);
      try
        R.WriteString('', MapName);
      finally
        R.CloseKey;
      end;
      // create mapping
      Result := Result and R.OpenKey('\' + MapName + '\shell\open\command', true);
      try
        R.WriteString('', AppName + '"%1"');
      finally
        R.CloseKey;
      end;
    finally
      R.Free;
    end;
  except
    Result := false;
  end;
end;

// call example

procedure TForm1.Button2Click(Sender: TObject);
begin
  if MakeAssociation('*.txt', 'c:\winnt\system32\notepad.exe') then ; //success
end;


regards,
igor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CalvinDayCommented:
Copy the following into a file called addpopup.reg. Then double click the file to register it. It will add Notepad to the context menu. When you right click over a selected item, notepad will load and open it. The same can be done for any program. The \*\ determines which file extensions notepad will popup for.

REGEDIT4

[HKEY_CLASSES_ROOT\*\shell\Notepad\command]
@="c:\\windows\\notepad.exe \"%1\""
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

jackjokerAuthor Commented:
inter, will that make my application open the selected file?

If I'm not wrong, that will only run my application, cos I don't see any code telling my application to *open* the file.

I'm using a Memo.
0
interCommented:
my friend, you should change the line

if MakeAssociation('*.txt', 'c:\winnt\system32\notepad.exe') then

above as follows:

for the first parameter, give the extension you want to associate with your app. for the second give the location and name of the exe file. I have given an example that HOW txt files can be associated with notepad above.

Ok?
0
interCommented:
Of course you need to get the file when your application started by using the ParamStr(1) function. This would return the name of the file that is sent to you by the system. Just get the filename and do anything you want.
0
jackjokerAuthor Commented:
So in the OnCreate event of the main form, I'll put:

0
jackjokerAuthor Commented:
So in the OnCreate event of the main form, I'll put:

Memo1.LoadFromFile(ParamStr(1));

Right?

0
interCommented:
yes that's it.
more specifically,
1 - when you are installing your program. you should run the piece of code above.
2 - on your formcreate read the file.

you may also place the makeassociation function to your form create so that if it was overriden or destroyed it is repaierd again. but you must at least call makeassoc proc once for it to work.
0
interCommented:
sorrry lad, remove the * from '*.txt', you should five '.txt'
0
interCommented:
i am sorry, i should go to sleep it is 5:30 a.m. and i have go to work 3 hours after, you may use the other suggestions if you need it urgently. i would be on net in about 6 hours.
0
interCommented:
i am awake now, do you want anything?
0
jackjokerAuthor Commented:
Haven't tried your code yet.
0
interCommented:
do you have an installation program or you just copy the exe.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.