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
reg.OpenKey(prefix + 'file', True);
//and create a value where the icon is stored --> c:.exe,0
try
reg.Writestring('', exepfad + ',0');
finally
reg.CloseKey;
end;
reg.OpenKey(prefix + 'file', True);
//create value where exefile is stored --> c:.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('txt', '你的执行文件如:c:/edit.exe');
end;