16,749
社区成员
发帖
与我相关
我的任务
分享
RegAssociatedExec('.abc','abcfile','','','C:\Program.exe,0','C:\Program.exe %1');
uses Registry, shlobj;
function RegAssociatedExec(FileExt, Filetype, FileDescription, MIMEType, Icon,
ExecName: String): Boolean;
begin
Result := False;
if (FileExt = '') or (ExecName = '') then
Exit;
with TRegistry.Create do
begin
try
RootKey:=HKEY_CLASSES_ROOT;
if not OpenKey(FileExt, True) then
Exit;
WriteString('', FileType);
if MIMEType <> '' then
WriteString('Content Type', MIMEType);
CloseKey;
if not OpenKey(FileType, True) then
Exit;
WriteString('', FileDescription);
CloseKey;
if Icon<>'' then
begin
if not OpenKey(FileType+'\DefaultIcon', True) then
Exit;
WriteString('', Icon);
CloseKey;
end;
if not OpenKey(FileType+'\Shell\Open\Command', True) then
Exit;
WriteString('', ExecName);
CloseKey;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
finally
Free;
end;
end;
end;