简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM