Uninstall fails because program is running. How do I make Inno Setup check for running process prior to attempting delete?
We used an other way than described above. Because this is an uninstallation we can kill the application and unistall it. The simpliest way, when u can't use AppMutex: (related to Really killing a process in Windows)
[UninstallRun]
Filename: "{cmd}"; Parameters: "/C ""taskkill /im <precessname>.exe /f /t"
Hope somebody will help this. I searched a long time for this.
Check these
Inno Setup: Detect instances running in any user session with AppMutex
Inno Setup: Is application running?
Inno Setup: Detect if an application is running
There are several ways. If your program defines a mutex use
[Setup]
AppMutex=MyMutexName
or for a specified mutex in the Code
section
function CheckForMutexes (Mutexes: String): Boolean;
You could also use
function FindWindowByClassName (const ClassName: String): Longint;
to get the window handle by class name and send it messages.
Or get it by the name
function FindWindowByWindowName (const WindowName: String): Longint;
Or you use one of several DLL files for this specific use case
- PSVince
- FindProcDLL
Or do it yourself after reading
How To Terminate an Application "Cleanly" in Win32
How To Enumerate Applications Using Win32 APIs (this one links to the german version as for some reason I can't find the english version of KB175030
or try the google translated version of the KB175030-DE
KB175030 DE -> EN
Try this solution! I had issues with other solutions closing the app, but Inno Setup still thought the installed files were locked.
Remember to define your constants:
#define MyAppName "AppName"
#define MyAppExeName "AppName.exe"
[Code]
function InitializeUninstall(): Boolean;
var ErrorCode: Integer;
begin
ShellExec('open','taskkill.exe','/f /im {#MyAppExeName}','',SW_HIDE,ewNoWait,ErrorCode);
ShellExec('open','tskill.exe',' {#MyAppName}','',SW_HIDE,ewNoWait,ErrorCode);
result := True;
end;
Major props to the original source of this solution.