这应该很简单,当安装程序启动时,我需要停止任何先前版本的程序运行.
大多数人建议做一个exe这样做,并在Inno Setup启动之前调用它.我使用AutoIt创建了一个exe,它会杀死我的程序的所有进程.问题是我不知道如何让Inno安装程序在安装任何东西之前调用它.
解决方法
如果应用程序有一个Mutex,您可以在Inno Setup安装程序中添加一个AppMutex值,并显示一条消息,告诉用户停止该程序.您可以通过使用SysInternals Process Explorer并选择程序/进程并查看下方窗格中的句柄(CTRL-H)来找到Mutex(如果有的话).
以下是提供几种方法的KB文章的链接:
http://www.vincenzo.net/isxkb/index.php?title=Detect_if_an_application_is_running
或者,您可以在InitializeSetup中尝试此(UNTESTED)代码:
[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); except end; end;