2
votes

I'm trying to put together a simple Inno Setup installer which looks for the previous version and removes it before proceeding. Everything is working fine until I get the following code:

  if Exec(UninstallString, '/SILENT', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  begin
    MsgBox('Previous version found and uninstalled successfully.', mbInformation, MB_OK);
  end
  else
  begin
    MsgBox('Please uninstall the previous version of this mod before continuing.', mbInformation, MB_OK);
    Result := FALSE;
  end;

It's a very simple bit of code, but it ALWAYS fails. I've checked the contents of UninstallString and they're correct (C:\Windows\unins000.exe) but the Exec fails with the error: "The directory name is invalid."

It appears that it can't read the contents of "UninstallString" correctly, because if I enter them manually (e.g. Exec('C:\Windows\unins000.exe, ...) it works fine.

How can I make Exec process the string "UninstallString" as intended?

1
Thanks, you're right. I got the following error: "The directory name is invalid." - Chuck Le Butt
Yes, I'm definitely looking up the previous AppId. Secondly, as stated in the question, I've checked the contents of the string and they're as expected :-/ - Chuck Le Butt
That's impossible. There's generally no difference between the string constant and a string type variable with the same value as the constant. The problem must be somewhere else. Don't you use AnsiString type e.g. for the UninstallString variable, don't you ? - TLama
I use: UninstallString: string; is that wrong? And, I promise you, the contents are there. I just checked again. It's boggling my mind. - Chuck Le Butt
No, that's correct. Then there is (from inside the Exec function point of view) absolutely no difference between that constant and the variable having the same value as the constant. I'm starting to think about some non-printable char in that registry value... How did you check the UninstallString value ? - TLama

1 Answers

1
votes

I don't know if you already did the MsgBox to determine the exact string in the registry for the UninstallString but in the registry the normal string is "C:\Windows\unins000.exe".

Note the extra " around the command.

When using Exec with the " around the command you get a ResultCode 267 which is an invalid directory error. So you need to strip them before the Exec.

When you entered the C:\Windows\unins000.exe manually in Exec you conveniently forgot them ;)