• innosetup 判断进程是否存在


    //;判断进程是否存在
    function IsAppRunning(const FileName : string): Boolean;
    var
        FSWbemLocator: Variant;
        FWMIService   : Variant;
        FWbemObjectSet: Variant;
    begin
        Result := false;
        FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
        FWMIService := FSWbemLocator.ConnectServer('', 'rootCIMV2', '', '');
        FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
        Result := (FWbemObjectSet.Count > 0);
        FWbemObjectSet := Unassigned;
        FWMIService := Unassigned;
        FSWbemLocator := Unassigned;
    end;
    
    //安装的时候判断进程是否存在
    function InitializeSetup(): Boolean;
    begin
      Result := IsAppRunning('{#MyAppExeName}');
      if Result then
      begin
          MsgBox('程序正在运行,请先关闭程序后再重试! ', mbError, MB_OK); 
        result:=false;
      end
      else
        begin
          result := true;
          if FileOrDirExists(ExpandConstant('{localappdata}FeikuaBrowserUserDataDefault')) then
            DelTree(ExpandConstant('{localappdata}FeikuaBrowserUserDataDefault'), True, True, True);
        end;
    end;
    
    
    //卸载的时候判断进程是否存在
    function InitializeUninstall(): Boolean;
    begin
     Result := IsAppRunning('{#MyAppExeName}');
      if Result then
      begin
          MsgBox('程序正在运行,请先关闭程序后再重试! ', mbError, MB_OK); 
        result:=false;
      end
    else
        begin
          result := true;
        end;
    end;  
  • 相关阅读:
    跑步前后吃什么?
    英雄杀八人场心得
    如何判断JavaScript数据具体类型
    js实现时间日期的格式化
    各个公司前端笔试题回顾
    原型模式Prototype,constructor,__proto__详解
    二级菜单不同方法的实现
    秋招笔试碰到的疑难题目1
    php和mysql学习问题笔记
    es6学习笔记12--Class
  • 原文地址:https://www.cnblogs.com/Galesaur-wcy/p/15513086.html
Copyright © 2020-2023  润新知