function DeleteFileAssociation(Ext:string;Notify:boolean=true):boolean;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
key:='';
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
try
  reg:=tregistry.Create;
  reg.RootKey:=hkey_classes_root;
  if reg.KeyExists(ext) then
  begin
    if reg.OpenKey(ext,false) then
    begin
      key:=reg.ReadString('');
      reg.CloseKey;
      if (not reg.DeleteKey(ext)) or (not reg.DeleteKey(key)) then
        goto final;
    end
    else
      goto final;
  end;
  if notify then
 // SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
   notifyassociationchange; 
result:=true;
final:
finally
reg.Free;
end;
end;
function SetFileAssociation(Ext:string;
                            OpenApp:string;
                            FileTypeDescription:string='';
                            OpenMenuCaption:string='';
                            IconFile:string='';
                            IconIndex:integer=0;
                            Notify:boolean=true):boolean;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
if openmenucaption='' then openmenucaption:='&Open';
if IconFile='' then IconFile:=openapp;
key:=copy(ext,2,length(ext))+' File';
if filetypedescription='' then filetypedescription:=key;//////////////////////////////////////////
try
  reg:=tregistry.Create;
  reg.RootKey:=hkey_classes_root;
  if reg.OpenKey(ext,true) then
  begin
    reg.WriteString('',key);
    reg.CloseKey;
  end
  else
    goto final;
  if reg.OpenKey(key,true) then
  begin
    reg.WriteString('',filetypedescription);
    reg.CloseKey;
  end
  else
    goto final;
  if reg.OpenKey(key+'\DefaultIcon',true) then
  begin
    reg.WriteString('',openapp+','+inttostr(iconindex));
    reg.CloseKey;
  end
  else
    goto final;
  if reg.OpenKey(key+'\Shell\Open',true) then
  begin
    reg.WriteString('',openmenucaption);
    reg.CloseKey;
  end
  else
    goto final;
  if reg.OpenKey(key+'\Shell\Open\Command',true) then
  begin
    reg.WriteString('','"'+openapp+'" "%1"');
    reg.CloseKey;
  end
  else
    goto final;
  if notify then  
    notifyassociationchange;
  result:=true;
final:
finally
reg.Free;
end;
end;
procedure NotifyAssociationChange;
begin
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;

解决方案 »

  1.   

    不要这样嘛,一分中就结贴?http://www.csdn.net/Expert/forum.asp?typenum=8&searchKeys=+&roomid=0&author=xingjiaren&tabletype=now给stanely送分也不是第一回了。怎么你的帖子被删了那么多,信誉值还是100啊??
      

  2.   

    那个叫:emu(ston) 的,xingjiaren马上给我分就是送嘛?你找找,还有哪个贴子是送我分的??csdn里面故意送分的难道少嘛?说别人怎么样,你自己就干净?哦,有可能很干净,不然不会这么眼红的!