Kill process before (re)install using “taskkill /f /im” in Inno Setup

匆匆过客 提交于 2019-11-27 20:19:52

I found a way using the BeforeInstall keyword and a simple Pascal function in the code section. I added a string parameter so it can be reused for multiple processes.

[Files]
Source: "My Service 1.exe"; DestDir: "{app}"; Flags: ignoreversion; BeforeInstall: TaskKill('My Service 1.exe')
Source: "My Service 2.exe"; DestDir: "{app}"; Flags: ignoreversion; BeforeInstall: TaskKill('My Service 2.exe')

[Code]
procedure TaskKill(FileName: String);
var
  ResultCode: Integer;
begin
    Exec(ExpandConstant('taskkill.exe'), '/f /im ' + '"' + FileName + '"', '', SW_HIDE,
     ewWaitUntilTerminated, ResultCode);
end;

Unless the installer is running on a Windows XP machine, or you have set CloseApplications directive to no (the default is yes), the installer should close the application automatically:

The functionality is available since Inno Setup 5.5 on Windows Vista and newer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!