在安装更新之前关闭程序的运行版本(Inno Setup) [英] Close running version of program before installing update (Inno Setup)

查看:119
本文介绍了在安装更新之前关闭程序的运行版本(Inno Setup)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This should be simple, I need to stop any previous version of my program from running when the installer starts.

大多数人建议制作一个exe并在Inno Setup开始之前调用它.我使用AutoIt创建了exe,它会杀死程序的所有进程.问题是我不知道如何在安装任何东西之前让Inno Setup调用它.

Most people suggested making an exe which does this and calling it before Inno Setup starts. I created an exe using AutoIt which kills all processes of my program. The problem is I don't know how to get Inno Setup to call it before it installs anything.

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

How do I call an executable before installing files?

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

Alternatively, if I can just detect if a program is running and tell the user to close it, that would work too.

推荐答案

如果应用程序具有Mutex,则可以在Inno Setup安装程序中添加AppMutex值,它将显示一条消息,提示用户停止程序.您可以通过使用SysInternals Process Explorer并选择程序/进程并查看下部窗格中的Handles(CTRL-H)来找到Mutex(如果有).

If the application has a Mutex, you can add an AppMutex value in your Inno Setup installer and it will display a message telling the user to stop the program. You might be able to find the Mutex (if it's got one) by using SysInternals Process Explorer and selecting the program / process and looking at the Handles (CTRL-H) in the Lower Pane.

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

Here's a link to the a KB article that mentions several methods:
http://www.vincenzo.net/isxkb/index.php?title=Detect_if_an_application_is_running

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

Alternatively, you might try this (UNTESTED) code in the 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;

这篇关于在安装更新之前关闭程序的运行版本(Inno Setup)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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