Close running version of program before installing update (Inno Setup)

前端 未结 10 1237
囚心锁ツ
囚心锁ツ 2020-12-23 12:24

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

Most people suggested making an exe wh

10条回答
  •  天命终不由人
    2020-12-23 12:59

    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.

    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

    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;
    

提交回复
热议问题