卸载后执行命令

发布于 2024-12-04 03:24:28 字数 110 浏览 0 评论 0原文

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

关于我如何实现上述目标有什么建议吗?

I need my uninstall to run a command after it's removed the files it has installed.
[UninstallRun] is no use as I understand it runs BEFORE files are removed.
I kind of need a "postuninstall" flag.

Any suggestions as to how I can accomplish the above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-12-11 03:24:28

See "Uninstall Event Functions" in the documentation. You can use for instance CurUninstallStepChanged when 'CurUninstallStep' is 'usPostUninstall'.

蔚蓝源自深海 2024-12-11 03:24:28

同样,还有一个 [Run] 部分,Inno 允许您定义一个 [UninstallRun] 部分指定卸载时应执行安装程序包的哪些文件。

例如:

[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;

In the same way there is a [Run] section, Inno allows to you to define an [UninstallRun] section to specify which files of your Installer package should be executed on unistall.

For example:

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

Alternatively, solution proposed by @Sertac Akyuz, which makes use of event functions can be used for tunning a bit more unistalling actions. Here is an example of the usage of CurUninstallStepChanged function among other related functions.

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文