Deleting and unregistering DLL files during instal

2019-05-30 18:42发布

问题:

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

In the [Run] section I have:

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

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;

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

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"

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

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

回答1:

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

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


So you need Pascal scripting.

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

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

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