Inno Setup fails to remove components during uninstall cause my program is still running and the executable cannot be deleted. How do I have it check to see if it is running
Use the AppMutex directive to prevent the uninstaller from proceeding, when an application is running.
[Setup]
AppMutex=MyProgMutex
The application has to create the mutex specified by the directive. See the linked AppMutex directive documentation for examples.
If you want to have the uninstaller kill the application, when it is still running, use this code instead:
function InitializeUninstall(): Boolean;
var
ErrorCode: Integer;
begin
if CheckForMutexes('MyProgMutex') and
(MsgBox('Application is running, do you want to close it?',
mbConfirmation, MB_OKCANCEL) = IDOK) then
begin
Exec('taskkill.exe', '/f /im MyProg.exe', '', SW_HIDE,
ewWaitUntilTerminated, ErrorCode);
end;
Result := True;
end;
As with the AppMutex directive above, the application has to create the mutex specified in the CheckForMutexes call.
Note that for installer, you do not have to code this. The installer has restart manager built-in.
See Kill process before (re)install using "taskkill /f /im" in Inno Setup.