使用"taskkill/f/im"杀死(重新)安装之前的进程.在Inno Setup中 [英] Kill process before (re)install using "taskkill /f /im" in 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屋!