使用"taskkill/f/im"杀死(重新)安装之前的进程.在Inno Setup中 [英] Kill process before (re)install using "taskkill /f /im" in Inno Setup

查看:255
本文介绍了使用"taskkill/f/im"杀死(重新)安装之前的进程.在Inno Setup中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了服务/守护程序,需要先将其杀死,然后再卸载并重新安装.

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

我已经找到了如何进行卸载:

[UninstallRun]
Filename: "taskkill"; Parameters: "/im ""My Service.exe"" /f"; Flags: runhidden

[Run]部分在安装后运行,因此我不能使用它.在安装前使用taskkill杀死进程的最佳方法是什么?

The [Run] section, however, runs after install, so I can't use it for that. What is the best way to kill the process using taskkill before install?

请注意,我特别想终止该过程. 使用IPC的更复杂的解决方案不提供对于我的好处,我只想在安装特定文件之前执行taskkill.

Please note that I specifically want to kill the process. A more complex solution using IPC offers no benefits in my case, I just want to execute taskkill before installing a particular file.

推荐答案

我在代码部分找到了使用BeforeInstall参数和简单的Pascal Script函数的方法.我添加了一个字符串参数,以便可以将其重复用于多个进程.

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;

这篇关于使用"taskkill/f/im"杀死(重新)安装之前的进程.在Inno Setup中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆