zoukankan      html  css  js  c++  java
  • innosetup安装之前关闭进程

        InnoSetup覆盖安装的时候可能会因为源程序正在运行而安装失败,以下脚本能够关闭原运行进程。

    [code]
    // 安装前检查关闭**进程
    function InitializeSetup():Boolean;
    //进程ID
    var appWnd: HWND;
    begin
      Result := true;
      //Log('Checking If Running...');
      //根据窗体名字获取进程ID
      appWnd := FindWindowByWindowName('IE Scavenger');
      if (appWnd <> 0) then
         //进程存在,关闭
         begin
            //Log('Is Runing...');
            //给进程发送关闭消息
            PostMessage(appWnd, 18, 0, 0);       // quit
         end else
         //进程不存在 
         begin 
            //Log('Not Runing...');
         end;
    end;

        InitializeSetup 函数在安装程序初始化时调用,返回 False 中断安装,返回 True 反之。

        FindWindowByWindowName 获取窗口名与指定字串匹配的顶层窗口的句柄。这个函数不搜索子窗口 ,且不执行区分大小写搜索。如果没有找到窗口则返回 0。

        运行流程就是根据窗口名获取正在运行的程序,如果已经运行则强制关闭。相应的卸载的时候如果需要先关闭程序,可以调用编写InitializeUninstall函数,关闭源程序。这种是无痛关闭,没有任何提示。你可以自己添加提示,引导用户进行操作。

  • 相关阅读:
    个人博客12
    《梦断代码》阅读笔记03
    个人博客11
    个人博客10
    【Codeforces 404C】Restore Graph
    【Codeforces 476C】Dreamoon and Sums
    【Codeforces 242C】King's Path
    【Codeforces 382C】Arithmetic Progression
    【Codeforces 1096D】Easy Problem
    【Codeforces 494A】Treasure
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/4135741.html
Copyright © 2011-2022 走看看