扩展名关联可执行文件,可执行文件打开文件
某扩展名关联某可执行文件,使用下面代码可以实现关联,
function RegAssociatedExec(const AFileExt, AFileType, AFileDescription, AMIMEType, AIcon, AExecName: string): Boolean; stdcall;
begin
Result := False;
if (AFileExt = '') or (AExecName = '') then
Exit;
with TRegistry.Create do
begin
try
RootKey := HKEY_CLASSES_ROOT;
if not OpenKey(AFileExt, True) then
begin
Exit;
end;
WriteString('', AFileType);
if AMIMEType <> '' then
begin
WriteString('Content Type', AMIMEType);
end;
CloseKey;
if not OpenKey(AFileType, True) then
begin
Exit;
end;
WriteString('', AFileDescription);
CloseKey;
if AIcon <> '' then
begin
if not OpenKey(AFileType + '\DefaultIcon', True) then
begin
Exit;
end;
WriteString('', AIcon);
CloseKey;
end;
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
begin
Exit;
end;
WriteString('', AExecName);
CloseKey;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
finally
Free;
end;
end;
end;
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
begin
Exit;
end;
WriteString('', AExecName);