Uninstall fails because program is running. How do I make Inno Setup check for running process prior to attempting delete?

后端 未结 4 720
死守一世寂寞
死守一世寂寞 2020-12-05 02:56

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

4条回答
  •  盖世英雄少女心
    2020-12-05 03:20

    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.

提交回复
热议问题