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

后端 未结 2 1326
南旧
南旧 2020-12-03 00:32

I install a service/daemon, which needs to be killed before uninstall and reinstall.

I already found out how to do it for uninstall:

[UninstallRun]
F         


        
相关标签:
2条回答
  • 2020-12-03 00:39

    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.

    0 讨论(0)
  • 2020-12-03 01:04

    I found a way using the BeforeInstall parameter and a simple Pascal Script 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;
    
    0 讨论(0)
提交回复
热议问题