2

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?

Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
  • Thanks, you're right. I got the following error: "The directory name is invalid." – Chuck Le Butt Oct 06 '13 at 20:20
  • 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 Oct 06 '13 at 20:41
  • 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 Oct 06 '13 at 20:46
  • 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 Oct 06 '13 at 20:53
  • 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 Oct 06 '13 at 21:00
  • I placed it in a MsgBox... This is such a weird thing. Everything else is working fine! Thanks for your assistance! – Chuck Le Butt Oct 06 '13 at 21:28
  • Try to set a breakpoint to line with `Exec` call and [`watch or log the value`](http://stackoverflow.com/a/14674126/960757) of the `UninstallString` variable. There should be visible also non-printable chars (as some extraordinary chars). Although it's weird how would non-printable chars appear in registry and be read by Windows API registry functions, it's the only thing that comes to my mind to explain the difference between string constant and a `string` variable with the same value printed by `MsgBox`. – TLama Oct 06 '13 at 21:37
  • I wonder if it's not `Exec` who failed but your `unins000.exe` failed with "The directory name is invalid.". It is strange that it does run when given the string directly. BTW Why would your `unins000.exe` be in the Windows directory instead of a program directory (unless you installed your program in `C:\Windows`)? (and there should also be a `unins000.dat`.) – Rik Oct 07 '13 at 12:14
  • Yeah, this is why I'm trying to clean things up a bit. Lol! It's a patch installer, so there's no main executable folder, but I think it would be better if I made one, instead of the installer automatically using `{win}` :-/ – Chuck Le Butt Oct 07 '13 at 13:42

1 Answers1

1

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 ;)

Rik
  • 1,982
  • 1
  • 17
  • 30
  • The `MsgBox` way for printing out string values is not the best way because you lose non-printable chars. And those might be serious problem for this case (but it seems they are not). – TLama Oct 08 '13 at 12:29
  • Yeah, but `"` is a printable character and I think the command is wrapped around `"` (which `Exec` can't handle). – Rik Oct 08 '13 at 12:29
  • No, I meant that the file name we are talking about might contain non-printable chars, like e.g. #8, #9 and whatever. And those you won't see through `MsgBox` and they might be problem for `Exec`. `MsgBox` is not the right way to see the real string value. Howgh! :-) – TLama Oct 08 '13 at 13:51
  • @Rik Well done for spotting this! I outputted the value to Log, as TLama suggested, and it was indeed "C:\Windows\unins000.exe"! – Chuck Le Butt Oct 12 '13 at 12:02