Amaranth
Amaranth

Reputation: 2511

Call exe in Inno Setup uninstall

I have an issue with the Inno Setup uninstaller. I have a exe file I want to executable to keep track of the installation and uninstallations. The exe is really simple and sends a message to a server.

[Files]
Source: "Tracker\LocalSandboxInstallTracker.exe"; DestDir: "{app}/Tracker";
Source: "Tracker\LocalSandboxInstallTracker.exe.config"; DestDir: "{app}/Tracker";
Source: "Tracker\Tracker.Client.dll"; DestDir: "{app}/Tracker";

[Run]
Filename: "{app}\Tracker\LocalSandboxInstallTracker.exe"; Parameters: " {#MyAppVersion} install"; Flags: runhidden; StatusMsg: "Sending tracking data..."

[Code]
procedure InitializeUninstallProgressForm();
var
  ResultCode: Integer;
begin
  Exec ('{app}\Tracker\LocalSandboxInstallTracker.exe',' {#MyAppVersion} uninstall','',SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;

The call at the installation works well, but not at the uninstall. I placed a breakpoint to my Exec command and it really goes through there, but the exe does not seem to be called.

Upvotes: 2

Views: 3928

Answers (2)

TLama
TLama

Reputation: 76733

You must expand the {app} constant before passing it to the Exec script function. Use the ExpandConstant whenever you need to get the value of the constant. Modify your script this way:

Exec(ExpandConstant('{app}\Tracker\LocalSandboxInstallTracker.exe'), 
  '{#MyAppVersion} uninstall', '', SW_SHOW, 
  ewWaitUntilTerminated, ResultCode);

Also, you should check the function result and the output result code to react when the Exec function fails. The error code you'll get in the ResultCode you can check against the System Error Codes reference or use SysErrorMessage(ResultCode) to get the error description from script.

Upvotes: 5

jachguate
jachguate

Reputation: 17203

You have to call the ExpandConstant function if you want to use constants like {app} in your Exec call:

[Code]
procedure InitializeUninstallProgressForm();
var
  ResultCode: Integer;
begin
  Exec (ExpandConstant('{app}\Tracker\LocalSandboxInstallTracker.exe')
    ,' {#MyAppVersion} uninstall','',SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;

Other way, you're failing to locate the exe.

Upvotes: 4

Related Questions