2

In application B I have this code in the [Run] section:

Filename: "{dotnet40}\regasm.exe"; \
    Parameters: "/u PTSTools_x86.dll"; \
    WorkingDir: "{app}"; \
    Flags: runhidden; \
    Check: FileExists(ExpandConstant('{app}\PTSTools_x86.dll')); \
    AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools_x86.dll'))

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

I used to use those DLL files in application B but no longer need to. So I performed the above to "unregistered and get rid of them". That is OK in itself. BUT ...

I have application A which DOES use them! So, in its [Run] section it does 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

Now, the two applications are independent of each other. A user may have one, the other or both.

  • If they only have application B then it can unregister and delete the obsolete DLL files.
  • If they also have application A installed, then, the obsolete DLL files only need to be deleted because application A would have registered them in its folder.

Can do I perform this selection uninstallation behaviour?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

2 Answers2

2

Call the regasm /u from CurStepChanged(ssInstall) using Exec function, after checking if Application A is not installed.


To check if Application A is installed, use the same code as here:
Can Inno Setup respond differently to a new install and an update?
Excludes part of Code section in ssPostInstall step if installation is update in Inno Setup

Just use AppId of the Application A.


procedure Unregister(Filename: string);
var
  Path, FilePath: string;
  ResultCode: Integer;
begin
  Path := ExpandConstant('{app}');
  FilePath := AddBackslash(Path) + Filename;
  if not FileExists(FilePath) then
  begin
    Log(Format('%s does not exist', [FilePath]));
  end
    else
  begin
    if IsAppAInstalled then
    begin
      Log(Format('Application A is installed, not unregistering %s', [FilePath]));
    end
      else
    begin
      if Exec(ExpandConstant('{dotnet40}\regasm.exe'), '/u ' + Filename,
              Path, SW_HIDE, ewWaitUntilTerminated,
              ResultCode) and
         // Not sure about this
         (ResultCode = 0) then
      begin
        Log(Format('Unregistered %s', [FilePath]));
      end
        else
      begin
        Log(Format('Failed to unregister %s', [FilePath]));
      end;
    end;

    if DeleteFile(FilePath) then
    begin
      Log(Format('Deleted %s', [FilePath]));
    end
      else
    begin
      Log(Format('Failed to delete %s', [FilePath]));
    end;
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    Unregister('PTSTools_x86.dll');
    if IsWin64 then Unregister('PTSTools_x64.dll');
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

This is based on the accepted answer with minor tweaks:

  • Tweak 1

In CurStepChanged I changed it to be conditional for unregistering the 64 bit DLL:

else if (CurStep = ssInstall) then
begin
    Unregister('PTSTools_x86.dll', ExpandConstant('{dotnet40}'));
    if (IsWin64) then
    begin
        Unregister('PTSTools_x64.dll', ExpandConstant('{dotnet4064}'));
    end;
end
  • Tweak 2

I modified Unregister to take a second parameter (the value of the expanded {dotnet40} constants). This is then used to build the path to regasm:

RegAsmPath := AddBackSlash(sDotNetRoot) + 'regasm.exe';

Then I simply used that value as the first parameter to Exec.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164