innosetup卸载时删除文件

需求背景:

innosetup原则上是安装哪些文件就卸载那些文件。

但实际上往往会在应用的使用过程中,会生成一些日志文件。在卸载的时候,不能删掉,会提示手动清理。

这样还是挺影响体验的。

解决方法:

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
 begin
     if CurUninstallStep = usDone then
     begin
        //删除 {app} 文件夹及其中所有文件
     DelTree(ExpandConstant('{app}'), True, True, True);
     end;
 end;

卸载不干净的情况:

[UninstallRun]
Filename: "{cmd}"; Parameters: "/c rd /s /q ""{app}"""; Flags: hidewizard runhidden


[UninstallDelete]
Name: {app}; Type: filesandordirs

卸载时循环删除文件

function Delete_Files(): Boolean;
    begin
      result := false;
      while result = false do
      begin
        //删除文件夹
        if DelTree(ExpandConstant('{app}\Python'), True, True, True) then
          begin
            result := true
          end;
      end;
      
      //删除文件
      //DeleteFile(ExpandConstant('C:\a.txt'));
      //DeleteFile(ExpandConstant('{app}\c.txt'));
    end;

function UninstallNeedRestart (): Boolean;
  var
    ResultStr: String;
    ResultCode: Integer;
    CmdStr: String;
    ret: Integer;
  begin
    result := false;
    Delete_Files()

  end;

Inno setup 删除指定文件

方法一

[UninstallDelete]
;删除文件,{app}:安装目录
Type: files; Name: "{app}\vcruntime140d.dll";
Type: files; Name: "{app}\ucrtbased.dll";
;删除文件夹
Type: filesandordirs; Name: "{app}";

方法二

[code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    begin
      //删除文件夹
      DelTree(ExpandConstant('{app}\platform'), True, True, True);
      //删除文件
      DeleteFile(ExpandConstant('C:\a.txt'));
      DeleteFile(ExpandConstant('{app}\c.txt'));
    end;
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值