uses
registry, shlobj;
procedure TForm1.RegisterFileType(prefix: string; exepfad: string);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CLASSES_ROOT;
//create a new key --> .pci
reg.OpenKey('.' + prefix, True);
try
//create a new value for this key --> pcifile
reg.Writestring('', prefix + 'file');
finally
reg.CloseKey;
end;
//create a new key --> pcifile
reg.CreateKey(prefix + 'file');
//create a new key pcifile\DefaultIcon
reg.OpenKey(prefix + 'file\DefaultIcon', True);
//and create a value where the icon is stored --> c:\project1.exe,0
try
reg.Writestring('', exepfad + ',0');
finally
reg.CloseKey;
end;
reg.OpenKey(prefix + 'file\shell\open\command', True);
//create value where exefile is stored --> c:\project1.exe "%1"
try
reg.Writestring('', exepfad + ' "%1"');
finally
reg.CloseKey;
end;
finally
reg.Free;
end;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RegisterFileType('pci', 'c:\project1.exe');
end;
Bewerten Sie diesen Tipp:
|
|
|