gpt4 book ai didi

installation - 安装更新之前关闭正在运行的程序版本 (Inno Setup)

转载 作者:行者123 更新时间:2023-12-02 22:07:37 24 4
gpt4 key购买 nike

这应该很简单,我需要在安装程序启动时停止运行任何以前版本的程序。

大多数人建议创建一个 exe 来执行此操作,并在 Inno Setup 启动之前调用它。我使用 AutoIt 创建了一个 exe,它会终止程序的所有进程。问题是我不知道如何让 Inno Setup 在安装任何东西之前调用它。

如何在安装文件之前调用可执行文件?

或者,如果我可以检测程序是否正在运行并告诉用户关闭它,那也可以。

最佳答案

如果应用程序有互斥锁,您可以在 Inno Setup 安装程序中添加一个 AppMutex 值,它将显示一条消息,告诉用户停止该程序。您可以通过使用 SysInternals Process Explorer 并选择程序/进程并查看下部 Pane 中的句柄 (CTRL-H) 来找到互斥体(如果有的话)。

以下是知识库文章的链接,其中提到了几种方法:
http://www.vincenzo.net/isxkb/index.php?title=Detect_if_an_application_is_running

或者,您可以在 InitializeSetup 中尝试此(未经测试)代码:

[Setup]
;If the application has Mutex, uncomment the line below, comment the InitializeSetup function out, and use the AppMutex.
;AppMutex=MyApplicationMutex

[Code]
const
WM_CLOSE = 16;

function InitializeSetup : Boolean;
var winHwnd: Longint;
retVal : Boolean;
strProg: string;
begin
Result := True;
try
//Either use FindWindowByClassName. ClassName can be found with Spy++ included with Visual C++.
strProg := 'Notepad';
winHwnd := FindWindowByClassName(strProg);
//Or FindWindowByWindowName. If using by Name, the name must be exact and is case sensitive.
strProg := 'Untitled - Notepad';
winHwnd := FindWindowByWindowName(strProg);
Log('winHwnd: ' + IntToStr(winHwnd));
if winHwnd <> 0 then
Result := PostMessage(winHwnd,WM_CLOSE,0,0);
except
end;
end;

关于installation - 安装更新之前关闭正在运行的程序版本 (Inno Setup),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3507853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com