[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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.
0
jackjoker
Asked:
jackjoker
1 Solution
 
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
 
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now