Inno Setup: Exec can't read string?

こ雲淡風輕ζ 提交于 2019-12-08 02:01:52

问题


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:


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



来源:https://stackoverflow.com/questions/19213376/inno-setup-exec-cant-read-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!