卸载后执行命令

时间:2011-09-13 13:40:22

标签: inno-setup

我需要卸载才能在删除已安装的文件后运行命令。 [UninstallRun]是没用的,因为据我所知它运行BEFORE文件被删除。 我需要一个“postuninstall”标志。

有关如何完成上述任务的任何建议吗?

2 个答案:

答案 0 :(得分:9)

请参阅文档中的“Uninstall Event Functions”。当'CurUninstallStep'为'usPostUninstall'时,您可以使用例如CurUninstallStepChanged

答案 1 :(得分:5)

以同样的方式存在[Run]部分,Inno允许您定义[UninstallRun]部分以指定应在unistall上执行哪些Installer包文件。

例如:

[UninstallRun]
Filename: {app}\Scripts\DeleteWindowsService.bat; Flags: runhidden;

或者,@ Sertac Akyuz提出的使用事件函数的解决方案可以用于调整更多不受欢迎的操作。以下是CurUninstallStepChanged函数在其他相关函数中的使用示例。

https://github.com/HeliumProject/InnoSetup/blob/master/Examples/UninstallCodeExample1.iss

; -- UninstallCodeExample1.iss --
;
; This script shows various things you can achieve using a [Code] section for Uninstall

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme

[Code]
function InitializeUninstall(): Boolean;
begin
  Result := MsgBox('InitializeUninstall:' #13#13 'Uninstall is initializing. Do you really want to start Uninstall?', mbConfirmation, MB_YESNO) = idYes;
  if Result = False then
    MsgBox('InitializeUninstall:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;

procedure DeinitializeUninstall();
begin
  MsgBox('DeinitializeUninstall:' #13#13 'Bye bye!', mbInformation, MB_OK);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  case CurUninstallStep of
    usUninstall:
      begin
        MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall is about to start.', mbInformation, MB_OK)
        // ...insert code to perform pre-uninstall tasks here...
      end;
    usPostUninstall:
      begin
        MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall just finished.', mbInformation, MB_OK);
        // ...insert code to perform post-uninstall tasks here...
      end;
  end;
end;