0

Problem (EDITED) In an InnoSetup script I have to uninstall another installation of my program, which has previously been installed by InnoSetup, too. Although it regards the same program in this particular case, its way of installing has changed (it was a stand-alone installation, now it became part of another program), so the usual update procedure of InnoSetup cannot take care of this situation.

I can read its "UninstallString" from the Windows Registry with a {reg:...} expression as shown below.

Although the Registry entry exists, InnoSetup tells me "Cannot execute file, CreateProcess fails with Code 87".

According to the error message the path read from the Registry is correct; if I execute exactly this path in the command window, the uninstallation works fine.

[Run]
Filename="{reg:HKLM\SOFTWARE\WOW6432\Microsoft\Windows\CurrentVersion\Uninstall\MyProg_is1,UninstallString}"; Parameters: "/silent"; Flags: skipifdoesntexist

Also, if I put that path directly into the [Run] section as "Filename=", it works.

Any ideas what I've done wrong?

Christoph Jüngling
  • 1,080
  • 7
  • 26
  • 1
    This cannot work. You are reading registry on compile time (i.e. on the machine that creates the installer), instead of a run time (on the machine where you are (ui)installing). – See [Inno Setup: How to automatically uninstall previous installed version?](https://stackoverflow.com/q/2000296/850848). – Martin Prikryl May 26 '22 at 08:22
  • @MartinPrikryl Thanks, good point! Moved it to `PrepareToInstall`, and so found out that the "..." around the UninstallString (coming from InnoSetup's registry entry) were an additional problem - they caused the "code 87". – Christoph Jüngling May 26 '22 at 11:23

1 Answers1

0

This is my solution for the given situation. PrepareToInstall is a call-back function, which is automatically called by the Pascal scripting engine prior to the installation, if it exists.

[Code]

(**
* Uninstall previous stand-alone installation of a program, if present
**)
Function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  UninstallString: String;
  ResultCode: Integer;
  pgmname : String;

begin
  pgmname := 'PrevProgramName';
  Result := '';
  if RegQueryStringValue(
          HKLM32, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + pgmname + '_is1',
          'UninstallString', UninstallString) then

      // Strip quotation marks from the path
      StringChangeEx(UninstallString, '"', '', True);

      if UninstallString <> '' then
        if Exec(UninstallString, '/verysilent', '', 1, ewWaitUntilTerminated, ResultCode) then
          Result := ''
        else
          Result := 'Error executing uninstaller, Code ' + IntToStr(ResultCode);

end;
Christoph Jüngling
  • 1,080
  • 7
  • 26