使用Inno Setup在安装过程中删除和注销DLL文件 [英] Deleting and unregistering DLL files during install using Inno Setup

查看:249
本文介绍了使用Inno Setup在安装过程中删除和注销DLL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的[Files]部分,我有以下内容:

In my [Files] section I have the following:

; Database password decryption (for PTS importing)
Source: "..\..\..\PTSTools\PTSTools\bin\x86\Release\PTSTools.dll"; DestDir: "{app}"; \
    DestName: "PTSTools_x86.dll"; Flags: ignoreversion
Source: "..\..\..\PTSTools\PTSTools\bin\x64\Release\PTSTools.dll"; DestDir: "{app}"; \
    DestName: "PTSTools_x64.dll"; Flags: ignoreversion; Check: IsWin64

[Run]部分中,我有:

Filename: "{dotnet40}\regasm.exe"; Parameters: "PTSTools_x86.dll /codebase"; \
    WorkingDir: "{app}"; Flags: runhidden
Filename: "{dotnet4064}\regasm.exe"; Parameters: "PTSTools_x64.dll /codebase"; \
    WorkingDir: "{app}"; Flags: runhidden; Check: IsWin64

最后,在[UninstallRun]部分中,我有:

Finally, in the [UninstallRun] section I have:

Filename: {dotnet40}\regasm.exe; Parameters: /u PTSTools_x86.dll; WorkingDir: {app}; \
    Flags: runhidden
Filename: {dotnet4064}\regasm.exe; Parameters: /u PTSTools_x64.dll; WorkingDir: {app}; \
    Flags: runhidden; Check: IsWin64;

现在,在我的程序的此版本中,我已将这两个DLL文件的功能合并为另一组DLL文件:

Now, in this version of my program I have consolidated the functionality of these two DLL files into another set of DLL files:

Source: "..\..\..\MSAToolsLibrary\MSAToolsLibrary\bin\x86\Release\MSAToolsLibrary.dll"; \
    DestDir: "{app}"; DestName: "MSAToolsLibrary_x86.dll"; Flags: ignoreversion
Source: "..\..\..\MSAToolsLibrary\MSAToolsLibrary\bin\x64\Release\MSAToolsLibrary.dll"; \
    DestDir: "{app}"; DestName: "MSAToolsLibrary_x64.dll"; Flags: ignoreversion; \
    Check: IsWin64

因此,不再需要PTSTool DLL文件.现在,我知道我可以删除它们(如果存在)

As a result, the PTSTool DLL files are no longer required. Now, I know I can simply delete them if they exist:

[InstallDelete]
Type: files; Name: "{app}\PTSTools_x64.dll"
Type: files; Name: "{app}\PTSTools_x86.dll"

但是据我所知,这不会像[UninstallRun]中那样触发DLL文件的注销.

But as far as I am aware this will not trigger the unregistering of the DLL files as is done in [UninstallRun].

我该怎么做?在安装过程中删除并注销DLL文件(如果存在)?

How can I do this? Delete and unregister the DLL files (if they exist) during the install?

推荐答案

我认为您无法使用标准部分轻松地实现此目的.

I do not think you can implement this easily using the standard sections.

[Run]条目仅在[InstallDelete]之后出现.在删除DLL之前,您可以用另一种方式先注销,然后再注销.

A [Run] entry happens only after [InstallDelete]. While you need it the other way around to first unregister, before you delete a DLL.

因此,您需要Pascal脚本.

So you need Pascal scripting.

BeforeInstall参数添加到并以编程方式注销DLL.

Either add BeforeInstall parameter to [InstallDelete] and unregister the DLL programmaticaly.

或将 AfterInstall参数添加到并以编程方式删除DLL.

Or add AfterInstall parameter to [Run] and delete the DLL programmatically.

后者对您来说工作量较小,因为您已经知道如何使用[Run]来(取消)注册.

The latter is less work for you, as you already know how to use [Run] to (un)register.

[Run]
Filename: {dotnet40}\regasm.exe; Parameters: /u PTSTools_x86.dll; WorkingDir: {app}; \
    Check: FileExists(ExpandConstant('{app}\PTSTools_x86.dll')); \
    AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools_x86.dll')); \
    Flags: runhidden
Filename: {dotnet4064}\regasm.exe; Parameters: /u PTSTools_x64.dll; WorkingDir: {app}; \
    Check: IsWin64 and FileExists(ExpandConstant('{app}\PTSTools_x64.dll')); \
    AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools_x64.dll')); \
    Flags: runhidden

[Code]

{ Cannot use built-in DeleteFile directly in AfterInstall as it's a function,
{ not a procedure. And this way we can add some error handling too. }
procedure DoDeleteFile(FileName: string);
begin
  if DeleteFile(FileName) then
  begin
    Log(Format('"%s" deleted', [FileName]));
  end
    else
  begin
    MsgBox(Format('Failed to delete "%s"', [FileName]), mbError, MB_OK);
  end;
end;

这篇关于使用Inno Setup在安装过程中删除和注销DLL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆